]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: core: Simplify IIO core managed APIs
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 20 Feb 2026 13:25:19 +0000 (14:25 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 23 Feb 2026 21:00:47 +0000 (21:00 +0000)
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>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/buffer/kfifo_buf.c
drivers/iio/industrialio-trigger.c

index a6ff9085b8a28bb56c2acb97205a71f10761bc71..b67ea646822653d76b04bb576a59c2bd52a91fd7 100644 (file)
@@ -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 *buffer)
 {
-       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(buffer);
 }
 
 /**
@@ -262,10 +236,12 @@ static struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev)
  * @setup_ops: The setup_ops required to configure the HW part of the buffer (optional)
  * @buffer_attrs: Extra sysfs buffer attributes for this IIO buffer
  *
- * This function allocates a kfifo buffer via devm_iio_kfifo_allocate() and
+ * This function allocates a kfifo buffer via iio_kfifo_allocate() and
  * 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;
 
index 9776a185864ef9a6ca47b50c5e435cdd6b78ed10..17781c12bc858e998ba5412a96db23428cd17ef7 100644 (file)
@@ -635,9 +635,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);
 }
 
 /**
@@ -659,24 +659,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;
 }