Skip to content

Commit f9cbfb6

Browse files
krzkbroonie
authored andcommitted
ASoC: codecs: audio-iio-aux: Simplify audio_iio_aux_probe() with cleanup.h
Allocate the memory with scoped/cleanup.h in audio_iio_aux_probe() 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 408e493 commit f9cbfb6

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

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

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
230230
struct audio_iio_aux_chan *iio_aux_chan;
231231
struct device *dev = &pdev->dev;
232232
struct audio_iio_aux *iio_aux;
233-
const char **names;
234-
u32 *invert_ranges;
235233
int count;
236234
int ret;
237235
int i;
@@ -248,22 +246,22 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
248246

249247
iio_aux->num_chans = count;
250248

251-
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);
252252
if (!names)
253253
return -ENOMEM;
254254

255-
invert_ranges = kcalloc(iio_aux->num_chans, sizeof(*invert_ranges), GFP_KERNEL);
256-
if (!invert_ranges) {
257-
ret = -ENOMEM;
258-
goto out_free_names;
259-
}
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;
260260

261261
ret = device_property_read_string_array(dev, "io-channel-names",
262262
names, iio_aux->num_chans);
263-
if (ret < 0) {
264-
dev_err_probe(dev, ret, "failed to read io-channel-names\n");
265-
goto out_free_invert_ranges;
266-
}
263+
if (ret < 0)
264+
return dev_err_probe(dev, ret, "failed to read io-channel-names\n");
267265

268266
/*
269267
* snd-control-invert-range is optional and can contain fewer items
@@ -274,10 +272,8 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
274272
count = min_t(unsigned int, count, iio_aux->num_chans);
275273
ret = device_property_read_u32_array(dev, "snd-control-invert-range",
276274
invert_ranges, count);
277-
if (ret < 0) {
278-
dev_err_probe(dev, ret, "failed to read snd-control-invert-range\n");
279-
goto out_free_invert_ranges;
280-
}
275+
if (ret < 0)
276+
return dev_err_probe(dev, ret, "failed to read snd-control-invert-range\n");
281277
}
282278

283279
for (i = 0; i < iio_aux->num_chans; i++) {
@@ -286,23 +282,16 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
286282
iio_aux_chan->is_invert_range = invert_ranges[i];
287283

288284
iio_aux_chan->iio_chan = devm_iio_channel_get(dev, iio_aux_chan->name);
289-
if (IS_ERR(iio_aux_chan->iio_chan)) {
290-
ret = PTR_ERR(iio_aux_chan->iio_chan);
291-
dev_err_probe(dev, ret, "get IIO channel '%s' failed\n",
292-
iio_aux_chan->name);
293-
goto out_free_invert_ranges;
294-
}
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);
295289
}
296290

297291
platform_set_drvdata(pdev, iio_aux);
298292

299-
ret = devm_snd_soc_register_component(dev, &audio_iio_aux_component_driver,
300-
NULL, 0);
301-
out_free_invert_ranges:
302-
kfree(invert_ranges);
303-
out_free_names:
304-
kfree(names);
305-
return ret;
293+
return devm_snd_soc_register_component(dev, &audio_iio_aux_component_driver,
294+
NULL, 0);
306295
}
307296

308297
static const struct of_device_id audio_iio_aux_ids[] = {

0 commit comments

Comments
 (0)