mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 20:22:09 +00:00
ASoC: codecs: audio-iio-aux: Simplify audio_iio_aux_add_dapms() with cleanup.h
Allocate the memory with scoped/cleanup.h in audio_iio_aux_add_dapms() to reduce error handling (less error paths) and make the code a bit simpler. Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Link: https://patch.msgid.link/20240703-asoc-cleanup-h-v1-1-71219dfd0aef@linaro.org Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
ccb367c5ab
commit
408e493817
@ -6,6 +6,7 @@
|
||||
//
|
||||
// Author: Herve Codina <herve.codina@bootlin.com>
|
||||
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/iio/consumer.h>
|
||||
#include <linux/minmax.h>
|
||||
#include <linux/mod_devicetable.h>
|
||||
@ -131,33 +132,27 @@ static int audio_iio_aux_add_dapms(struct snd_soc_component *component,
|
||||
struct audio_iio_aux_chan *chan)
|
||||
{
|
||||
struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
|
||||
char *output_name;
|
||||
char *input_name;
|
||||
char *pga_name;
|
||||
int ret;
|
||||
|
||||
input_name = kasprintf(GFP_KERNEL, "%s IN", chan->name);
|
||||
/* Allocated names are not needed afterwards (duplicated in ASoC internals) */
|
||||
char *input_name __free(kfree) = kasprintf(GFP_KERNEL, "%s IN", chan->name);
|
||||
if (!input_name)
|
||||
return -ENOMEM;
|
||||
|
||||
output_name = kasprintf(GFP_KERNEL, "%s OUT", chan->name);
|
||||
if (!output_name) {
|
||||
ret = -ENOMEM;
|
||||
goto out_free_input_name;
|
||||
}
|
||||
char *output_name __free(kfree) = kasprintf(GFP_KERNEL, "%s OUT", chan->name);
|
||||
if (!output_name)
|
||||
return -ENOMEM;
|
||||
|
||||
pga_name = kasprintf(GFP_KERNEL, "%s PGA", chan->name);
|
||||
if (!pga_name) {
|
||||
ret = -ENOMEM;
|
||||
goto out_free_output_name;
|
||||
}
|
||||
char *pga_name __free(kfree) = kasprintf(GFP_KERNEL, "%s PGA", chan->name);
|
||||
if (!pga_name)
|
||||
return -ENOMEM;
|
||||
|
||||
widgets[0] = SND_SOC_DAPM_INPUT(input_name);
|
||||
widgets[1] = SND_SOC_DAPM_OUTPUT(output_name);
|
||||
widgets[2] = SND_SOC_DAPM_PGA(pga_name, SND_SOC_NOPM, 0, 0, NULL, 0);
|
||||
ret = snd_soc_dapm_new_controls(dapm, widgets, 3);
|
||||
if (ret)
|
||||
goto out_free_pga_name;
|
||||
return ret;
|
||||
|
||||
routes[0].sink = pga_name;
|
||||
routes[0].control = NULL;
|
||||
@ -165,17 +160,8 @@ static int audio_iio_aux_add_dapms(struct snd_soc_component *component,
|
||||
routes[1].sink = output_name;
|
||||
routes[1].control = NULL;
|
||||
routes[1].source = pga_name;
|
||||
ret = snd_soc_dapm_add_routes(dapm, routes, 2);
|
||||
|
||||
/* Allocated names are no more needed (duplicated in ASoC internals) */
|
||||
|
||||
out_free_pga_name:
|
||||
kfree(pga_name);
|
||||
out_free_output_name:
|
||||
kfree(output_name);
|
||||
out_free_input_name:
|
||||
kfree(input_name);
|
||||
return ret;
|
||||
return snd_soc_dapm_add_routes(dapm, routes, 2);
|
||||
}
|
||||
|
||||
static int audio_iio_aux_component_probe(struct snd_soc_component *component)
|
||||
|
Loading…
Reference in New Issue
Block a user