[PATCH] iio: trigger: fix memory leak in viio_trigger_alloc()

From: Ashwin Gundarapu

Date: Fri May 22 2026 - 05:39:01 EST


From: Ashwin Gundarapu <linuxuser509@xxxxxxxxxxx>
Date: Fri, 22 May 2026 14:34:46 +0530
Subject: [PATCH] iio: trigger: fix memory leak in viio_trigger_alloc()

Replace direct kfree() with put_device() in the error path after
device_initialize() has been called.

The direct kfree() bypasses the reference counting mechanism,
causing memory leak and potential use-after-free.

Signed-off-by: Ashwin Gundarapu <linuxuser509@xxxxxxxxxxx>
---
drivers/iio/industrialio-trigger.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index 17781c12bc85..9c72e7ae996c 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -598,7 +598,7 @@ struct iio_trigger *viio_trigger_alloc(struct device *parent,
free_descs:
irq_free_descs(trig->subirq_base, CONFIG_IIO_CONSUMERS_PER_TRIGGER);
free_trig:
- kfree(trig);
+ put_device(&trig->dev);
return NULL;
}

--
2.43.0