public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] iio: core: Simplify IIO core managed APIs
@ 2026-02-16  8:14 Andy Shevchenko
  2026-02-16 14:31 ` Nuno Sá
  2026-02-20 10:18 ` Jonathan Cameron
  0 siblings, 2 replies; 10+ messages in thread
From: Andy Shevchenko @ 2026-02-16  8:14 UTC (permalink / raw)
  To: Andy Shevchenko, linux-iio, linux-kernel
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, 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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 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);
 
 	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] 10+ messages in thread

end of thread, other threads:[~2026-02-20 13:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-02-20 10:27   ` Andy Shevchenko
2026-02-20 12:14     ` Jonathan Cameron
2026-02-20 13:29       ` Andy Shevchenko

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