public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Yicong Yang <yangyicong@hisilicon.com>
Cc: <linux-iio@vger.kernel.org>, <lars@metafoo.de>,
	<Michael.Hennerich@analog.com>, <pmeerw@pmeerw.net>,
	<prime.zeng@huawei.com>, <tiantao6@hisilicon.com>
Subject: Re: [PATCH 7/7] iio: inkern: simplify some devm functions
Date: Sat, 24 Apr 2021 15:12:56 +0100	[thread overview]
Message-ID: <20210424151256.020b24a6@jic23-huawei> (raw)
In-Reply-To: <1617881896-3164-8-git-send-email-yangyicong@hisilicon.com>

On Thu, 8 Apr 2021 19:38:16 +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 to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Jonathan

> ---
>  drivers/iio/inkern.c | 61 ++++++++++++++++++++--------------------------------
>  1 file changed, 23 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
> index db77a2d..5de35cc 100644
> --- a/drivers/iio/inkern.c
> +++ b/drivers/iio/inkern.c
> @@ -359,30 +359,24 @@ void iio_channel_release(struct iio_channel *channel)
>  }
>  EXPORT_SYMBOL_GPL(iio_channel_release);
>  
> -static void devm_iio_channel_free(struct device *dev, void *res)
> +static void devm_iio_channel_free(void *iio_channel)
>  {
> -	struct iio_channel *channel = *(struct iio_channel **)res;
> -
> -	iio_channel_release(channel);
> +	iio_channel_release(iio_channel);
>  }
>  
>  struct iio_channel *devm_iio_channel_get(struct device *dev,
>  					 const char *channel_name)
>  {
> -	struct iio_channel **ptr, *channel;
> -
> -	ptr = devres_alloc(devm_iio_channel_free, sizeof(*ptr), GFP_KERNEL);
> -	if (!ptr)
> -		return ERR_PTR(-ENOMEM);
> +	struct iio_channel *channel;
> +	int ret;
>  
>  	channel = iio_channel_get(dev, channel_name);
> -	if (IS_ERR(channel)) {
> -		devres_free(ptr);
> +	if (IS_ERR(channel))
>  		return channel;
> -	}
>  
> -	*ptr = channel;
> -	devres_add(dev, ptr);
> +	ret = devm_add_action_or_reset(dev, devm_iio_channel_free, channel);
> +	if (ret)
> +		return ERR_PTR(ret);
>  
>  	return channel;
>  }
> @@ -392,20 +386,16 @@ struct iio_channel *devm_of_iio_channel_get_by_name(struct device *dev,
>  						    struct device_node *np,
>  						    const char *channel_name)
>  {
> -	struct iio_channel **ptr, *channel;
> -
> -	ptr = devres_alloc(devm_iio_channel_free, sizeof(*ptr), GFP_KERNEL);
> -	if (!ptr)
> -		return ERR_PTR(-ENOMEM);
> +	struct iio_channel *channel;
> +	int ret;
>  
>  	channel = of_iio_channel_get_by_name(np, channel_name);
> -	if (IS_ERR(channel)) {
> -		devres_free(ptr);
> +	if (IS_ERR(channel))
>  		return channel;
> -	}
>  
> -	*ptr = channel;
> -	devres_add(dev, ptr);
> +	ret = devm_add_action_or_reset(dev, devm_iio_channel_free, channel);
> +	if (ret)
> +		return ERR_PTR(ret);
>  
>  	return channel;
>  }
> @@ -496,29 +486,24 @@ void iio_channel_release_all(struct iio_channel *channels)
>  }
>  EXPORT_SYMBOL_GPL(iio_channel_release_all);
>  
> -static void devm_iio_channel_free_all(struct device *dev, void *res)
> +static void devm_iio_channel_free_all(void *iio_channels)
>  {
> -	struct iio_channel *channels = *(struct iio_channel **)res;
> -
> -	iio_channel_release_all(channels);
> +	iio_channel_release_all(iio_channels);
>  }
>  
>  struct iio_channel *devm_iio_channel_get_all(struct device *dev)
>  {
> -	struct iio_channel **ptr, *channels;
> -
> -	ptr = devres_alloc(devm_iio_channel_free_all, sizeof(*ptr), GFP_KERNEL);
> -	if (!ptr)
> -		return ERR_PTR(-ENOMEM);
> +	struct iio_channel *channels;
> +	int ret;
>  
>  	channels = iio_channel_get_all(dev);
> -	if (IS_ERR(channels)) {
> -		devres_free(ptr);
> +	if (IS_ERR(channels))
>  		return channels;
> -	}
>  
> -	*ptr = channels;
> -	devres_add(dev, ptr);
> +	ret = devm_add_action_or_reset(dev, devm_iio_channel_free_all,
> +				       channels);
> +	if (ret)
> +		return ERR_PTR(ret);
>  
>  	return channels;
>  }


  reply	other threads:[~2021-04-24 14:12 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-08 11:38 [PATCH 0/7] Simplify codes with devm_add_action_or_reset Yicong Yang
2021-04-08 11:38 ` [PATCH 1/7] iio: adc: adi-axi-adc: simplify devm_adi_axi_adc_conv_register Yicong Yang
2021-04-08 13:00   ` Alexandru Ardelean
2021-04-08 13:04   ` Alexandru Ardelean
2021-04-09  7:39     ` Yicong Yang
2021-04-11 14:12   ` Jonathan Cameron
2021-04-12  9:10     ` Yicong Yang
2021-04-24 12:31       ` Jonathan Cameron
2021-04-08 11:38 ` [PATCH 2/7] iio: buffer-dmaengine: simplify __devm_iio_dmaengine_buffer_free Yicong Yang
2021-04-24 12:33   ` Jonathan Cameron
2021-04-08 11:38 ` [PATCH 3/7] iio: hw_consumer: simplify devm_iio_hw_consumer_alloc Yicong Yang
2021-04-24 13:56   ` Jonathan Cameron
2021-04-08 11:38 ` [PATCH 4/7] iio: triggered-buffer: simplify devm_iio_triggered_buffer_setup_ext Yicong Yang
2021-04-11 14:16   ` Jonathan Cameron
2021-04-12  9:05     ` Yicong Yang
2021-04-24 13:59       ` Jonathan Cameron
2021-04-08 11:38 ` [PATCH 5/7] iio: core: simplify some devm functions Yicong Yang
2021-04-08 13:09   ` Alexandru Ardelean
2021-04-09  7:21     ` Yicong Yang
2021-04-09  9:19       ` Andy Shevchenko
2021-04-09  9:41         ` Yicong Yang
2021-04-09  9:55           ` Andy Shevchenko
2021-04-09 13:05             ` Yicong Yang
2021-04-24 14:04               ` Jonathan Cameron
2021-04-08 11:38 ` [PATCH 6/7] iio: trigger: simplify __devm_iio_trigger_register Yicong Yang
2021-04-24 14:05   ` Jonathan Cameron
2021-04-08 11:38 ` [PATCH 7/7] iio: inkern: simplify some devm functions Yicong Yang
2021-04-24 14:12   ` Jonathan Cameron [this message]
2021-04-08 13:14 ` [PATCH 0/7] Simplify codes with devm_add_action_or_reset Alexandru Ardelean
2021-04-09  6:58 ` Lars-Peter Clausen
2021-04-09  7:27 ` Sa, Nuno
2021-04-09  9:17 ` Andy Shevchenko
2021-04-11 14:21 ` Jonathan Cameron
2021-04-24 14:15   ` Jonathan Cameron
2021-04-25  9:13     ` Yicong Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210424151256.020b24a6@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=prime.zeng@huawei.com \
    --cc=tiantao6@hisilicon.com \
    --cc=yangyicong@hisilicon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox