Skip to content

Commit 408e493

Browse files
krzkbroonie
authored andcommitted
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent ccb367c commit 408e493

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

sound/soc/codecs/audio-iio-aux.c

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
// Author: Herve Codina <[email protected]>
88

9+
#include <linux/cleanup.h>
910
#include <linux/iio/consumer.h>
1011
#include <linux/minmax.h>
1112
#include <linux/mod_devicetable.h>
@@ -131,51 +132,36 @@ static int audio_iio_aux_add_dapms(struct snd_soc_component *component,
131132
struct audio_iio_aux_chan *chan)
132133
{
133134
struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
134-
char *output_name;
135-
char *input_name;
136-
char *pga_name;
137135
int ret;
138136

139-
input_name = kasprintf(GFP_KERNEL, "%s IN", chan->name);
137+
/* Allocated names are not needed afterwards (duplicated in ASoC internals) */
138+
char *input_name __free(kfree) = kasprintf(GFP_KERNEL, "%s IN", chan->name);
140139
if (!input_name)
141140
return -ENOMEM;
142141

143-
output_name = kasprintf(GFP_KERNEL, "%s OUT", chan->name);
144-
if (!output_name) {
145-
ret = -ENOMEM;
146-
goto out_free_input_name;
147-
}
142+
char *output_name __free(kfree) = kasprintf(GFP_KERNEL, "%s OUT", chan->name);
143+
if (!output_name)
144+
return -ENOMEM;
148145

149-
pga_name = kasprintf(GFP_KERNEL, "%s PGA", chan->name);
150-
if (!pga_name) {
151-
ret = -ENOMEM;
152-
goto out_free_output_name;
153-
}
146+
char *pga_name __free(kfree) = kasprintf(GFP_KERNEL, "%s PGA", chan->name);
147+
if (!pga_name)
148+
return -ENOMEM;
154149

155150
widgets[0] = SND_SOC_DAPM_INPUT(input_name);
156151
widgets[1] = SND_SOC_DAPM_OUTPUT(output_name);
157152
widgets[2] = SND_SOC_DAPM_PGA(pga_name, SND_SOC_NOPM, 0, 0, NULL, 0);
158153
ret = snd_soc_dapm_new_controls(dapm, widgets, 3);
159154
if (ret)
160-
goto out_free_pga_name;
155+
return ret;
161156

162157
routes[0].sink = pga_name;
163158
routes[0].control = NULL;
164159
routes[0].source = input_name;
165160
routes[1].sink = output_name;
166161
routes[1].control = NULL;
167162
routes[1].source = pga_name;
168-
ret = snd_soc_dapm_add_routes(dapm, routes, 2);
169163

170-
/* Allocated names are no more needed (duplicated in ASoC internals) */
171-
172-
out_free_pga_name:
173-
kfree(pga_name);
174-
out_free_output_name:
175-
kfree(output_name);
176-
out_free_input_name:
177-
kfree(input_name);
178-
return ret;
164+
return snd_soc_dapm_add_routes(dapm, routes, 2);
179165
}
180166

181167
static int audio_iio_aux_component_probe(struct snd_soc_component *component)

0 commit comments

Comments
 (0)