Commit 4e023c4d authored by Yicong Yang's avatar Yicong Yang Committed by Jonathan Cameron

iio: adc: adi-axi-adc: simplify devm_adi_axi_adc_conv_register()

Use devm_add_action_or_reset() instead of devres_alloc() and
devres_add(), which works the same. This will simplify the
code. There is no functional changes.
Signed-off-by: default avatarYicong Yang <yangyicong@hisilicon.com>
Reviewed-by: default avatarAlexandru Ardelean <ardeleanalex@gmail.com>
Reviewed-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Reviewed-by: default avatarNuno Sa <nuno.sa@analog.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/1617881896-3164-2-git-send-email-yangyicong@hisilicon.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent afa2b78f
...@@ -202,29 +202,25 @@ static void adi_axi_adc_conv_unregister(struct adi_axi_adc_conv *conv) ...@@ -202,29 +202,25 @@ static void adi_axi_adc_conv_unregister(struct adi_axi_adc_conv *conv)
kfree(cl); kfree(cl);
} }
static void devm_adi_axi_adc_conv_release(struct device *dev, void *res) static void devm_adi_axi_adc_conv_release(void *conv)
{ {
adi_axi_adc_conv_unregister(*(struct adi_axi_adc_conv **)res); adi_axi_adc_conv_unregister(conv);
} }
struct adi_axi_adc_conv *devm_adi_axi_adc_conv_register(struct device *dev, struct adi_axi_adc_conv *devm_adi_axi_adc_conv_register(struct device *dev,
size_t sizeof_priv) size_t sizeof_priv)
{ {
struct adi_axi_adc_conv **ptr, *conv; struct adi_axi_adc_conv *conv;
int ret;
ptr = devres_alloc(devm_adi_axi_adc_conv_release, sizeof(*ptr),
GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);
conv = adi_axi_adc_conv_register(dev, sizeof_priv); conv = adi_axi_adc_conv_register(dev, sizeof_priv);
if (IS_ERR(conv)) { if (IS_ERR(conv))
devres_free(ptr); return conv;
return ERR_CAST(conv);
}
*ptr = conv; ret = devm_add_action_or_reset(dev, devm_adi_axi_adc_conv_release,
devres_add(dev, ptr); conv);
if (ret)
return ERR_PTR(ret);
return conv; return conv;
} }
......
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