diff mbox series

[6/7] iio: trigger: simplify __devm_iio_trigger_register

Message ID 1617881896-3164-7-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/industrialio-trigger.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

Comments

Jonathan Cameron April 24, 2021, 2:05 p.m. UTC | #1
On Thu, 8 Apr 2021 19:38:15 +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,

Jonathan

> ---
>  drivers/iio/industrialio-trigger.c | 18 +++++-------------
>  1 file changed, 5 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
> index ea3c985..0db0952 100644
> --- a/drivers/iio/industrialio-trigger.c
> +++ b/drivers/iio/industrialio-trigger.c
> @@ -624,9 +624,9 @@ struct iio_trigger *devm_iio_trigger_alloc(struct device *dev,
>  }
>  EXPORT_SYMBOL_GPL(devm_iio_trigger_alloc);
>  
> -static void devm_iio_trigger_unreg(struct device *dev, void *res)
> +static void devm_iio_trigger_unreg(void *trigger_info)
>  {
> -	iio_trigger_unregister(*(struct iio_trigger **)res);
> +	iio_trigger_unregister(trigger_info);
>  }
>  
>  /**
> @@ -647,21 +647,13 @@ int __devm_iio_trigger_register(struct device *dev,
>  				struct iio_trigger *trig_info,
>  				struct module *this_mod)
>  {
> -	struct iio_trigger **ptr;
>  	int ret;
>  
> -	ptr = devres_alloc(devm_iio_trigger_unreg, sizeof(*ptr), GFP_KERNEL);
> -	if (!ptr)
> -		return -ENOMEM;
> -
> -	*ptr = trig_info;
>  	ret = __iio_trigger_register(trig_info, this_mod);
> -	if (!ret)
> -		devres_add(dev, ptr);
> -	else
> -		devres_free(ptr);
> +	if (ret)
> +		return ret;
>  
> -	return ret;
> +	return devm_add_action_or_reset(dev, devm_iio_trigger_unreg, trig_info);
>  }
>  EXPORT_SYMBOL_GPL(__devm_iio_trigger_register);
>
diff mbox series

Patch

diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index ea3c985..0db0952 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -624,9 +624,9 @@  struct iio_trigger *devm_iio_trigger_alloc(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(devm_iio_trigger_alloc);
 
-static void devm_iio_trigger_unreg(struct device *dev, void *res)
+static void devm_iio_trigger_unreg(void *trigger_info)
 {
-	iio_trigger_unregister(*(struct iio_trigger **)res);
+	iio_trigger_unregister(trigger_info);
 }
 
 /**
@@ -647,21 +647,13 @@  int __devm_iio_trigger_register(struct device *dev,
 				struct iio_trigger *trig_info,
 				struct module *this_mod)
 {
-	struct iio_trigger **ptr;
 	int ret;
 
-	ptr = devres_alloc(devm_iio_trigger_unreg, sizeof(*ptr), GFP_KERNEL);
-	if (!ptr)
-		return -ENOMEM;
-
-	*ptr = trig_info;
 	ret = __iio_trigger_register(trig_info, this_mod);
-	if (!ret)
-		devres_add(dev, ptr);
-	else
-		devres_free(ptr);
+	if (ret)
+		return ret;
 
-	return ret;
+	return devm_add_action_or_reset(dev, devm_iio_trigger_unreg, trig_info);
 }
 EXPORT_SYMBOL_GPL(__devm_iio_trigger_register);