mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-02 07:36:44 +07:00
0e4ff5c806
Simplify error handling and remove repetitive (and rarely executed) code for unregistration by providing a devm_snd_soc_register() card. Signed-off-by: Mark Brown <broonie@linaro.org> Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
87 lines
2.1 KiB
C
87 lines
2.1 KiB
C
/*
|
|
* soc-devres.c -- ALSA SoC Audio Layer devres functions
|
|
*
|
|
* Copyright (C) 2013 Linaro Ltd
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
* option) any later version.
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/moduleparam.h>
|
|
#include <sound/soc.h>
|
|
|
|
static void devm_component_release(struct device *dev, void *res)
|
|
{
|
|
snd_soc_unregister_component(*(struct device **)res);
|
|
}
|
|
|
|
/**
|
|
* devm_snd_soc_register_component - resource managed component registration
|
|
* @dev: Device used to manage component
|
|
* @cmpnt_drv: Component driver
|
|
* @dai_drv: DAI driver
|
|
* @num_dai: Number of DAIs to register
|
|
*
|
|
* Register a component with automatic unregistration when the device is
|
|
* unregistered.
|
|
*/
|
|
int devm_snd_soc_register_component(struct device *dev,
|
|
const struct snd_soc_component_driver *cmpnt_drv,
|
|
struct snd_soc_dai_driver *dai_drv, int num_dai)
|
|
{
|
|
struct device **ptr;
|
|
int ret;
|
|
|
|
ptr = devres_alloc(devm_component_release, sizeof(*ptr), GFP_KERNEL);
|
|
if (!ptr)
|
|
return -ENOMEM;
|
|
|
|
ret = snd_soc_register_component(dev, cmpnt_drv, dai_drv, num_dai);
|
|
if (ret == 0) {
|
|
*ptr = dev;
|
|
devres_add(dev, ptr);
|
|
} else {
|
|
devres_free(ptr);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);
|
|
|
|
static void devm_card_release(struct device *dev, void *res)
|
|
{
|
|
snd_soc_unregister_card(*(struct snd_soc_card **)res);
|
|
}
|
|
|
|
/**
|
|
* devm_snd_soc_register_card - resource managed card registration
|
|
* @dev: Device used to manage card
|
|
* @card: Card to register
|
|
*
|
|
* Register a card with automatic unregistration when the device is
|
|
* unregistered.
|
|
*/
|
|
int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card)
|
|
{
|
|
struct device **ptr;
|
|
int ret;
|
|
|
|
ptr = devres_alloc(devm_card_release, sizeof(*ptr), GFP_KERNEL);
|
|
if (!ptr)
|
|
return -ENOMEM;
|
|
|
|
ret = snd_soc_register_card(card);
|
|
if (ret == 0) {
|
|
*ptr = dev;
|
|
devres_add(dev, ptr);
|
|
} else {
|
|
devres_free(ptr);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(devm_snd_soc_register_card);
|