Re: [PATCH v1 1/1] iio: core: Simplify IIO core managed APIs

From: Nuno Sá

Date: Mon Feb 16 2026 - 09:36:08 EST


On Mon, 2026-02-16 at 09:14 +0100, Andy Shevchenko 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@xxxxxxxxxxxxxxx>
> ---

LGTM. Just one minor "complain". Anyways:

Reviewed-by: Nuno Sá <nuno.sa@xxxxxxxxxx>

>  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
> @@ -224,9 +224,9 @@ void iio_kfifo_free(struct iio_buffer *r)
>  }
>  EXPORT_SYMBOL(iio_kfifo_free);
>  
> -static void devm_iio_kfifo_release(struct device *dev, void *res)
> +static void devm_iio_kfifo_release(void *r)
>  {
> - iio_kfifo_free(*(struct iio_buffer **)res);
> + iio_kfifo_free(r);
>  }
>  
>  /**
> @@ -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.
>   */
>  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);

Subtle change that could have been mentioned in the commit message.


- Nuno Sá