Commit f9cbfb66 authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by Mark Brown

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: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://patch.msgid.link/20240703-asoc-cleanup-h-v1-2-71219dfd0aef@linaro.orgSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 408e4938
...@@ -230,8 +230,6 @@ static int audio_iio_aux_probe(struct platform_device *pdev) ...@@ -230,8 +230,6 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
struct audio_iio_aux_chan *iio_aux_chan; struct audio_iio_aux_chan *iio_aux_chan;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct audio_iio_aux *iio_aux; struct audio_iio_aux *iio_aux;
const char **names;
u32 *invert_ranges;
int count; int count;
int ret; int ret;
int i; int i;
...@@ -248,22 +246,22 @@ static int audio_iio_aux_probe(struct platform_device *pdev) ...@@ -248,22 +246,22 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
iio_aux->num_chans = count; iio_aux->num_chans = count;
names = kcalloc(iio_aux->num_chans, sizeof(*names), GFP_KERNEL); const char **names __free(kfree) = kcalloc(iio_aux->num_chans,
sizeof(*names),
GFP_KERNEL);
if (!names) if (!names)
return -ENOMEM; return -ENOMEM;
invert_ranges = kcalloc(iio_aux->num_chans, sizeof(*invert_ranges), GFP_KERNEL); u32 *invert_ranges __free(kfree) = kcalloc(iio_aux->num_chans,
if (!invert_ranges) { sizeof(*invert_ranges),
ret = -ENOMEM; GFP_KERNEL);
goto out_free_names; if (!invert_ranges)
} return -ENOMEM;
ret = device_property_read_string_array(dev, "io-channel-names", ret = device_property_read_string_array(dev, "io-channel-names",
names, iio_aux->num_chans); names, iio_aux->num_chans);
if (ret < 0) { if (ret < 0)
dev_err_probe(dev, ret, "failed to read io-channel-names\n"); return dev_err_probe(dev, ret, "failed to read io-channel-names\n");
goto out_free_invert_ranges;
}
/* /*
* snd-control-invert-range is optional and can contain fewer items * 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) ...@@ -274,10 +272,8 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
count = min_t(unsigned int, count, iio_aux->num_chans); count = min_t(unsigned int, count, iio_aux->num_chans);
ret = device_property_read_u32_array(dev, "snd-control-invert-range", ret = device_property_read_u32_array(dev, "snd-control-invert-range",
invert_ranges, count); invert_ranges, count);
if (ret < 0) { if (ret < 0)
dev_err_probe(dev, ret, "failed to read snd-control-invert-range\n"); return dev_err_probe(dev, ret, "failed to read snd-control-invert-range\n");
goto out_free_invert_ranges;
}
} }
for (i = 0; i < iio_aux->num_chans; i++) { for (i = 0; i < iio_aux->num_chans; i++) {
...@@ -286,23 +282,16 @@ static int audio_iio_aux_probe(struct platform_device *pdev) ...@@ -286,23 +282,16 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
iio_aux_chan->is_invert_range = invert_ranges[i]; iio_aux_chan->is_invert_range = invert_ranges[i];
iio_aux_chan->iio_chan = devm_iio_channel_get(dev, iio_aux_chan->name); iio_aux_chan->iio_chan = devm_iio_channel_get(dev, iio_aux_chan->name);
if (IS_ERR(iio_aux_chan->iio_chan)) { if (IS_ERR(iio_aux_chan->iio_chan))
ret = PTR_ERR(iio_aux_chan->iio_chan); return dev_err_probe(dev, PTR_ERR(iio_aux_chan->iio_chan),
dev_err_probe(dev, ret, "get IIO channel '%s' failed\n", "get IIO channel '%s' failed\n",
iio_aux_chan->name); iio_aux_chan->name);
goto out_free_invert_ranges;
}
} }
platform_set_drvdata(pdev, iio_aux); platform_set_drvdata(pdev, iio_aux);
ret = devm_snd_soc_register_component(dev, &audio_iio_aux_component_driver, return devm_snd_soc_register_component(dev, &audio_iio_aux_component_driver,
NULL, 0); NULL, 0);
out_free_invert_ranges:
kfree(invert_ranges);
out_free_names:
kfree(names);
return ret;
} }
static const struct of_device_id audio_iio_aux_ids[] = { static const struct of_device_id audio_iio_aux_ids[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment