66//
77// Author: Herve Codina <herve.codina@bootlin.com>
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 );
169-
170- /* Allocated names are no more needed (duplicated in ASoC internals) */
171163
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
181167static int audio_iio_aux_component_probe (struct snd_soc_component * component )
@@ -244,8 +230,6 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
244230 struct audio_iio_aux_chan * iio_aux_chan ;
245231 struct device * dev = & pdev -> dev ;
246232 struct audio_iio_aux * iio_aux ;
247- const char * * names ;
248- u32 * invert_ranges ;
249233 int count ;
250234 int ret ;
251235 int i ;
@@ -262,22 +246,22 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
262246
263247 iio_aux -> num_chans = count ;
264248
265- names = kcalloc (iio_aux -> num_chans , sizeof (* names ), GFP_KERNEL );
249+ const char * * names __free (kfree ) = kcalloc (iio_aux -> num_chans ,
250+ sizeof (* names ),
251+ GFP_KERNEL );
266252 if (!names )
267253 return - ENOMEM ;
268254
269- invert_ranges = kcalloc (iio_aux -> num_chans , sizeof ( * invert_ranges ), GFP_KERNEL );
270- if (! invert_ranges ) {
271- ret = - ENOMEM ;
272- goto out_free_names ;
273- }
255+ u32 * invert_ranges __free ( kfree ) = kcalloc (iio_aux -> num_chans ,
256+ sizeof ( * invert_ranges ),
257+ GFP_KERNEL ) ;
258+ if (! invert_ranges )
259+ return - ENOMEM ;
274260
275261 ret = device_property_read_string_array (dev , "io-channel-names" ,
276262 names , iio_aux -> num_chans );
277- if (ret < 0 ) {
278- dev_err_probe (dev , ret , "failed to read io-channel-names\n" );
279- goto out_free_invert_ranges ;
280- }
263+ if (ret < 0 )
264+ return dev_err_probe (dev , ret , "failed to read io-channel-names\n" );
281265
282266 /*
283267 * snd-control-invert-range is optional and can contain fewer items
@@ -288,10 +272,8 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
288272 count = min_t (unsigned int , count , iio_aux -> num_chans );
289273 ret = device_property_read_u32_array (dev , "snd-control-invert-range" ,
290274 invert_ranges , count );
291- if (ret < 0 ) {
292- dev_err_probe (dev , ret , "failed to read snd-control-invert-range\n" );
293- goto out_free_invert_ranges ;
294- }
275+ if (ret < 0 )
276+ return dev_err_probe (dev , ret , "failed to read snd-control-invert-range\n" );
295277 }
296278
297279 for (i = 0 ; i < iio_aux -> num_chans ; i ++ ) {
@@ -300,23 +282,16 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
300282 iio_aux_chan -> is_invert_range = invert_ranges [i ];
301283
302284 iio_aux_chan -> iio_chan = devm_iio_channel_get (dev , iio_aux_chan -> name );
303- if (IS_ERR (iio_aux_chan -> iio_chan )) {
304- ret = PTR_ERR (iio_aux_chan -> iio_chan );
305- dev_err_probe (dev , ret , "get IIO channel '%s' failed\n" ,
306- iio_aux_chan -> name );
307- goto out_free_invert_ranges ;
308- }
285+ if (IS_ERR (iio_aux_chan -> iio_chan ))
286+ return dev_err_probe (dev , PTR_ERR (iio_aux_chan -> iio_chan ),
287+ "get IIO channel '%s' failed\n" ,
288+ iio_aux_chan -> name );
309289 }
310290
311291 platform_set_drvdata (pdev , iio_aux );
312292
313- ret = devm_snd_soc_register_component (dev , & audio_iio_aux_component_driver ,
314- NULL , 0 );
315- out_free_invert_ranges :
316- kfree (invert_ranges );
317- out_free_names :
318- kfree (names );
319- return ret ;
293+ return devm_snd_soc_register_component (dev , & audio_iio_aux_component_driver ,
294+ NULL , 0 );
320295}
321296
322297static const struct of_device_id audio_iio_aux_ids [] = {
0 commit comments