]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: adc: adi-axi-adc: simplify devm_adi_axi_adc_conv_register()
authorYicong Yang <yangyicong@hisilicon.com>
Thu, 8 Apr 2021 11:38:10 +0000 (19:38 +0800)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 17 May 2021 12:49:06 +0000 (13:49 +0100)
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: Yicong Yang <yangyicong@hisilicon.com>
Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/1617881896-3164-2-git-send-email-yangyicong@hisilicon.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/adi-axi-adc.c

index d5f6ffc5b5bc3eb69687a5c67da497b0cff85bf1..a73e3c2d212fabf4a919eb92d4a03323220c85e2 100644 (file)
@@ -202,29 +202,25 @@ static void adi_axi_adc_conv_unregister(struct adi_axi_adc_conv *conv)
        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,
                                                        size_t sizeof_priv)
 {
-       struct adi_axi_adc_conv **ptr, *conv;
-
-       ptr = devres_alloc(devm_adi_axi_adc_conv_release, sizeof(*ptr),
-                          GFP_KERNEL);
-       if (!ptr)
-               return ERR_PTR(-ENOMEM);
+       struct adi_axi_adc_conv *conv;
+       int ret;
 
        conv = adi_axi_adc_conv_register(dev, sizeof_priv);
-       if (IS_ERR(conv)) {
-               devres_free(ptr);
-               return ERR_CAST(conv);
-       }
+       if (IS_ERR(conv))
+               return conv;
 
-       *ptr = conv;
-       devres_add(dev, ptr);
+       ret = devm_add_action_or_reset(dev, devm_adi_axi_adc_conv_release,
+                                      conv);
+       if (ret)
+               return ERR_PTR(ret);
 
        return conv;
 }