All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>
Subject: Re: [PATCH v1 1/1] iio: core: Simplify IIO core managed APIs
Date: Fri, 20 Feb 2026 10:18:44 +0000	[thread overview]
Message-ID: <20260220101844.17f3bc63@jic23-huawei> (raw)
In-Reply-To: <20260216081412.1118599-1-andriy.shevchenko@linux.intel.com>

On Mon, 16 Feb 2026 09:14:12 +0100
Andy Shevchenko <andriy.shevchenko@linux.intel.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: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Nice.  There was a mass sweep up of these cases a few years
back but I guess these instances slipped through the scripting
that was used to find those.

> ---
>  drivers/iio/buffer/kfifo_buf.c     | 29 +++++++++++++----------------
>  drivers/iio/industrialio-trigger.c | 24 ++++++++++--------------
>  2 files changed, 23 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/iio/buffer/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c
> index 38034c8bcc04..a126cc05fb38 100644
> --- a/drivers/iio/buffer/kfifo_buf.c
> +++ b/drivers/iio/buffer/kfifo_buf.c
> @@ -234,23 +234,20 @@ static void devm_iio_kfifo_release(struct device *dev, void *res)
>   * @dev:		Device to allocate kfifo buffer for
>   *
>   * RETURNS:
> - * Pointer to allocated iio_buffer on success, NULL on failure.
> + * Pointer to allocated iio_buffer on success, error pointer on failure.

This had me briefly confused as I failed to notice it was static
(no idea why I gave such a simple internal function kernel-doc!)

However that brings the obvious follow up question.  Given your
simplification does having a helper make sense given only a single caller?

Let's just squash it and have the two calls inline + some resulting docs
updates to get rid of the references to this function.

Thanks,

Jonathan


>   */
>  static struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev)
>  {
> -	struct iio_buffer **ptr, *r;
> -
> -	ptr = devres_alloc(devm_iio_kfifo_release, sizeof(*ptr), GFP_KERNEL);
> -	if (!ptr)
> -		return NULL;
> +	struct iio_buffer *r;
> +	int ret;
>  
>  	r = iio_kfifo_allocate();
> -	if (r) {
> -		*ptr = r;
> -		devres_add(dev, ptr);
> -	} else {
> -		devres_free(ptr);
> -	}
> +	if (!r)
> +		return ERR_PTR(-ENOMEM);
> +
> +	ret = devm_add_action_or_reset(dev, devm_iio_kfifo_release, r);
> +	if (ret)
> +		return ERR_PTR(ret);
>  
>  	return r;
>  }
> @@ -275,8 +272,8 @@ int devm_iio_kfifo_buffer_setup_ext(struct device *dev,
>  	struct iio_buffer *buffer;
>  
>  	buffer = devm_iio_kfifo_allocate(dev);
> -	if (!buffer)
> -		return -ENOMEM;
> +	if (IS_ERR(buffer))
> +		return PTR_ERR(buffer);
>  
>  	indio_dev->modes |= INDIO_BUFFER_SOFTWARE;
>  	indio_dev->setup_ops = setup_ops;


  parent reply	other threads:[~2026-02-20 10:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-16  8:14 [PATCH v1 1/1] iio: core: Simplify IIO core managed APIs Andy Shevchenko
2026-02-16 14:31 ` Nuno Sá
2026-02-17  7:45   ` Andy Shevchenko
2026-02-17 13:29     ` Nuno Sá
2026-02-17 13:32       ` Andy Shevchenko
2026-02-20 10:09         ` Nuno Sá
2026-02-20 10:18 ` Jonathan Cameron [this message]
2026-02-20 10:27   ` Andy Shevchenko
2026-02-20 12:14     ` Jonathan Cameron
2026-02-20 13:29       ` Andy Shevchenko

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=20260220101844.17f3bc63@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.