public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/1] iio: core: Simplify IIO core managed APIs
@ 2026-02-20 13:25 Andy Shevchenko
  2026-02-22 16:54 ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2026-02-20 13:25 UTC (permalink / raw)
  To: Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel
  Cc: Jonathan Cameron, David Lechner, Andy Shevchenko

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.

While at it, inline devm_iio_kfifo_allocate() into its only user.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---

v2: squashed some code (Jonathan), amended commit message & added tag (Nuno)

 drivers/iio/buffer/kfifo_buf.c     | 39 ++++++++----------------------
 drivers/iio/industrialio-trigger.c | 24 ++++++++----------
 2 files changed, 20 insertions(+), 43 deletions(-)

diff --git a/drivers/iio/buffer/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c
index 38034c8bcc04..92ffe9131190 100644
--- a/drivers/iio/buffer/kfifo_buf.c
+++ b/drivers/iio/buffer/kfifo_buf.c
@@ -224,35 +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);
-}
-
-/**
- * devm_iio_kfifo_allocate - Resource-managed iio_kfifo_allocate()
- * @dev:		Device to allocate kfifo buffer for
- *
- * RETURNS:
- * Pointer to allocated iio_buffer on success, NULL 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;
-
-	r = iio_kfifo_allocate();
-	if (r) {
-		*ptr = r;
-		devres_add(dev, ptr);
-	} else {
-		devres_free(ptr);
-	}
-
-	return r;
+	iio_kfifo_free(r);
 }
 
 /**
@@ -266,6 +240,8 @@ static struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev)
  * attaches it to the IIO device via iio_device_attach_buffer().
  * This is meant to be a bit of a short-hand/helper function as there are a few
  * drivers that seem to do this.
+ *
+ * Return: 0 on success, negative error code on failure.
  */
 int devm_iio_kfifo_buffer_setup_ext(struct device *dev,
 				    struct iio_dev *indio_dev,
@@ -273,11 +249,16 @@ int devm_iio_kfifo_buffer_setup_ext(struct device *dev,
 				    const struct iio_dev_attr **buffer_attrs)
 {
 	struct iio_buffer *buffer;
+	int ret;
 
-	buffer = devm_iio_kfifo_allocate(dev);
+	buffer = iio_kfifo_allocate();
 	if (!buffer)
 		return -ENOMEM;
 
+	ret = devm_add_action_or_reset(dev, devm_iio_kfifo_release, buffer);
+	if (ret)
+		return ret;
+
 	indio_dev->modes |= INDIO_BUFFER_SOFTWARE;
 	indio_dev->setup_ops = setup_ops;
 
diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index 54416a384232..00c8b7e5c8b9 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -634,9 +634,9 @@ void iio_trigger_free(struct iio_trigger *trig)
 }
 EXPORT_SYMBOL(iio_trigger_free);
 
-static void devm_iio_trigger_release(struct device *dev, void *res)
+static void devm_iio_trigger_release(void *trig)
 {
-	iio_trigger_free(*(struct iio_trigger **)res);
+	iio_trigger_free(trig);
 }
 
 /**
@@ -658,24 +658,20 @@ struct iio_trigger *__devm_iio_trigger_alloc(struct device *parent,
 					     struct module *this_mod,
 					     const char *fmt, ...)
 {
-	struct iio_trigger **ptr, *trig;
+	struct iio_trigger *trig;
 	va_list vargs;
-
-	ptr = devres_alloc(devm_iio_trigger_release, sizeof(*ptr),
-			   GFP_KERNEL);
-	if (!ptr)
-		return NULL;
+	int ret;
 
 	/* use raw alloc_dr for kmalloc caller tracing */
 	va_start(vargs, fmt);
 	trig = viio_trigger_alloc(parent, this_mod, fmt, vargs);
 	va_end(vargs);
-	if (trig) {
-		*ptr = trig;
-		devres_add(parent, ptr);
-	} else {
-		devres_free(ptr);
-	}
+	if (!trig)
+		return NULL;
+
+	ret = devm_add_action_or_reset(parent, devm_iio_trigger_release, trig);
+	if (ret)
+		return NULL;
 
 	return trig;
 }
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] iio: core: Simplify IIO core managed APIs
  2026-02-20 13:25 [PATCH v2 1/1] iio: core: Simplify IIO core managed APIs Andy Shevchenko
@ 2026-02-22 16:54 ` Jonathan Cameron
  2026-02-22 19:07   ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2026-02-22 16:54 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Nuno Sá, linux-iio, linux-kernel, David Lechner,
	Andy Shevchenko

On Fri, 20 Feb 2026 14:25:19 +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.
> 
> While at it, inline devm_iio_kfifo_allocate() into its only user.
> 
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Nice.  Applied

Thanks,

Jonathan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] iio: core: Simplify IIO core managed APIs
  2026-02-22 16:54 ` Jonathan Cameron
@ 2026-02-22 19:07   ` Andy Shevchenko
  2026-02-23 21:00     ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2026-02-22 19:07 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Nuno Sá, linux-iio, linux-kernel, David Lechner,
	Andy Shevchenko

On Sun, Feb 22, 2026 at 04:54:11PM +0000, Jonathan Cameron wrote:
> On Fri, 20 Feb 2026 14:25:19 +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.
> > 
> > While at it, inline devm_iio_kfifo_allocate() into its only user.
> > 
> > Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Nice.  Applied

Thanks!

One minor thing though. The iio_kfifo_alloc()/free() uses variable name 'r'
while devm_iio_kfifo_alloc() uses 'buffer'. I was thinking again and now
I probably would go with 'buffer' in devm_iio_kfifo_release() as well
to have a symmetry with the devm_*_alloc(). If you think it worth changing,
may you fold it? (AFAIU the applied patch is still in the pending/testing
queue that is okay for rebase, squash, et cetera.)

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] iio: core: Simplify IIO core managed APIs
  2026-02-22 19:07   ` Andy Shevchenko
@ 2026-02-23 21:00     ` Jonathan Cameron
  2026-02-24  9:17       ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2026-02-23 21:00 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Nuno Sá, linux-iio, linux-kernel, David Lechner,
	Andy Shevchenko

On Sun, 22 Feb 2026 21:07:10 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Sun, Feb 22, 2026 at 04:54:11PM +0000, Jonathan Cameron wrote:
> > On Fri, 20 Feb 2026 14:25:19 +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.
> > > 
> > > While at it, inline devm_iio_kfifo_allocate() into its only user.
> > > 
> > > Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>  
> > Nice.  Applied  
> 
> Thanks!
> 
> One minor thing though. The iio_kfifo_alloc()/free() uses variable name 'r'
> while devm_iio_kfifo_alloc() uses 'buffer'. I was thinking again and now
> I probably would go with 'buffer' in devm_iio_kfifo_release() as well
> to have a symmetry with the devm_*_alloc(). If you think it worth changing,
> may you fold it? (AFAIU the applied patch is still in the pending/testing
> queue that is okay for rebase, squash, et cetera.)
> 
Ok.  Whilst looking at this I noticed there was a stray docs
reference to devm_iio_kfifo_alloc() Which doesn't exist any more so
I updated that to refer to iio_kfifo_alloc() which is what is called.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] iio: core: Simplify IIO core managed APIs
  2026-02-23 21:00     ` Jonathan Cameron
@ 2026-02-24  9:17       ` Andy Shevchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-02-24  9:17 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Nuno Sá, linux-iio, linux-kernel, David Lechner,
	Andy Shevchenko

On Mon, Feb 23, 2026 at 09:00:35PM +0000, Jonathan Cameron wrote:
> On Sun, 22 Feb 2026 21:07:10 +0200
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > On Sun, Feb 22, 2026 at 04:54:11PM +0000, Jonathan Cameron wrote:
> > > On Fri, 20 Feb 2026 14:25:19 +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.
> > > > 
> > > > While at it, inline devm_iio_kfifo_allocate() into its only user.
> > > > 
> > > > Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> > > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>  
> > > Nice.  Applied  
> > 
> > Thanks!
> > 
> > One minor thing though. The iio_kfifo_alloc()/free() uses variable name 'r'
> > while devm_iio_kfifo_alloc() uses 'buffer'. I was thinking again and now
> > I probably would go with 'buffer' in devm_iio_kfifo_release() as well
> > to have a symmetry with the devm_*_alloc(). If you think it worth changing,
> > may you fold it? (AFAIU the applied patch is still in the pending/testing
> > queue that is okay for rebase, squash, et cetera.)
> > 
> Ok.  Whilst looking at this I noticed there was a stray docs
> reference to devm_iio_kfifo_alloc() Which doesn't exist any more so
> I updated that to refer to iio_kfifo_alloc() which is what is called.

Thank you!

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-02-24  9:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-20 13:25 [PATCH v2 1/1] iio: core: Simplify IIO core managed APIs Andy Shevchenko
2026-02-22 16:54 ` Jonathan Cameron
2026-02-22 19:07   ` Andy Shevchenko
2026-02-23 21:00     ` Jonathan Cameron
2026-02-24  9:17       ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox