]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: core: Clean up device correctly on viio_trigger_alloc() failure
authorSalah Triki <salah.triki@gmail.com>
Sat, 21 Feb 2026 07:32:42 +0000 (08:32 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 23 Feb 2026 20:44:31 +0000 (20:44 +0000)
Move device_initialize() after all error paths in viio_trigger_alloc().
Previously, put_device() should have been called on all error paths after
device_initialize(), but that was not done.

Rather than adding put_device(), move device_initialize() to avoid
needing to unwind it on error.

In addition move trig->dev initialization to just before device_initialize()
to related code together.

Signed-off-by: Salah Triki <salah.triki@gmail.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/industrialio-trigger.c

index 7f34fe7bad07d2fdbdce6ea8f78d695c45ba5be7..9776a185864ef9a6ca47b50c5e435cdd6b78ed10 100644 (file)
@@ -561,10 +561,6 @@ struct iio_trigger *viio_trigger_alloc(struct device *parent,
        if (!trig)
                return NULL;
 
-       trig->dev.parent = parent;
-       trig->dev.type = &iio_trig_type;
-       trig->dev.bus = &iio_bus_type;
-       device_initialize(&trig->dev);
        INIT_WORK(&trig->reenable_work, iio_reenable_work_fn);
 
        mutex_init(&trig->pool_lock);
@@ -592,6 +588,11 @@ struct iio_trigger *viio_trigger_alloc(struct device *parent,
                                  IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE);
        }
 
+       trig->dev.parent = parent;
+       trig->dev.type = &iio_trig_type;
+       trig->dev.bus = &iio_bus_type;
+       device_initialize(&trig->dev);
+
        return trig;
 
 free_descs: