Re: [PATCH 6/7] iio: trigger: simplify __devm_iio_trigger_register

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 8 Apr 2021 19:38:15 +0800
Yicong Yang <yangyicong@xxxxxxxxxxxxx> 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@xxxxxxxxxxxxx>
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);
>  




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux