diff mbox series

[3/7] iio: hw_consumer: simplify devm_iio_hw_consumer_alloc

Message ID 1617881896-3164-4-git-send-email-yangyicong@hisilicon.com (mailing list archive)
State New
Headers show
Series Simplify codes with devm_add_action_or_reset | expand

Commit Message

Yicong Yang April 8, 2021, 11:38 a.m. UTC
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>
---
 drivers/iio/buffer/industrialio-hw-consumer.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

Comments

Jonathan Cameron April 24, 2021, 1:56 p.m. UTC | #1
On Thu, 8 Apr 2021 19:38:12 +0800
Yicong Yang <yangyicong@hisilicon.com> wrote:

> 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>
Applied,

Thanks,
> ---
>  drivers/iio/buffer/industrialio-hw-consumer.c | 25 +++++++++++--------------
>  1 file changed, 11 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/iio/buffer/industrialio-hw-consumer.c b/drivers/iio/buffer/industrialio-hw-consumer.c
> index f2d2778..87d9aab 100644
> --- a/drivers/iio/buffer/industrialio-hw-consumer.c
> +++ b/drivers/iio/buffer/industrialio-hw-consumer.c
> @@ -137,9 +137,9 @@ void iio_hw_consumer_free(struct iio_hw_consumer *hwc)
>  }
>  EXPORT_SYMBOL_GPL(iio_hw_consumer_free);
>  
> -static void devm_iio_hw_consumer_release(struct device *dev, void *res)
> +static void devm_iio_hw_consumer_release(void *iio_hwc)
>  {
> -	iio_hw_consumer_free(*(struct iio_hw_consumer **)res);
> +	iio_hw_consumer_free(iio_hwc);
>  }
>  
>  /**
> @@ -153,20 +153,17 @@ static void devm_iio_hw_consumer_release(struct device *dev, void *res)
>   */
>  struct iio_hw_consumer *devm_iio_hw_consumer_alloc(struct device *dev)
>  {
> -	struct iio_hw_consumer **ptr, *iio_hwc;
> -
> -	ptr = devres_alloc(devm_iio_hw_consumer_release, sizeof(*ptr),
> -			   GFP_KERNEL);
> -	if (!ptr)
> -		return NULL;
> +	struct iio_hw_consumer *iio_hwc;
> +	int ret;
>  
>  	iio_hwc = iio_hw_consumer_alloc(dev);
> -	if (IS_ERR(iio_hwc)) {
> -		devres_free(ptr);
> -	} else {
> -		*ptr = iio_hwc;
> -		devres_add(dev, ptr);
> -	}
> +	if (IS_ERR(iio_hwc))
> +		return iio_hwc;
> +
> +	ret = devm_add_action_or_reset(dev, devm_iio_hw_consumer_release,
> +				       iio_hwc);
> +	if (ret)
> +		return ERR_PTR(ret);
>  
>  	return iio_hwc;
>  }
diff mbox series

Patch

diff --git a/drivers/iio/buffer/industrialio-hw-consumer.c b/drivers/iio/buffer/industrialio-hw-consumer.c
index f2d2778..87d9aab 100644
--- a/drivers/iio/buffer/industrialio-hw-consumer.c
+++ b/drivers/iio/buffer/industrialio-hw-consumer.c
@@ -137,9 +137,9 @@  void iio_hw_consumer_free(struct iio_hw_consumer *hwc)
 }
 EXPORT_SYMBOL_GPL(iio_hw_consumer_free);
 
-static void devm_iio_hw_consumer_release(struct device *dev, void *res)
+static void devm_iio_hw_consumer_release(void *iio_hwc)
 {
-	iio_hw_consumer_free(*(struct iio_hw_consumer **)res);
+	iio_hw_consumer_free(iio_hwc);
 }
 
 /**
@@ -153,20 +153,17 @@  static void devm_iio_hw_consumer_release(struct device *dev, void *res)
  */
 struct iio_hw_consumer *devm_iio_hw_consumer_alloc(struct device *dev)
 {
-	struct iio_hw_consumer **ptr, *iio_hwc;
-
-	ptr = devres_alloc(devm_iio_hw_consumer_release, sizeof(*ptr),
-			   GFP_KERNEL);
-	if (!ptr)
-		return NULL;
+	struct iio_hw_consumer *iio_hwc;
+	int ret;
 
 	iio_hwc = iio_hw_consumer_alloc(dev);
-	if (IS_ERR(iio_hwc)) {
-		devres_free(ptr);
-	} else {
-		*ptr = iio_hwc;
-		devres_add(dev, ptr);
-	}
+	if (IS_ERR(iio_hwc))
+		return iio_hwc;
+
+	ret = devm_add_action_or_reset(dev, devm_iio_hw_consumer_release,
+				       iio_hwc);
+	if (ret)
+		return ERR_PTR(ret);
 
 	return iio_hwc;
 }