[PATCH] fsi/core: Fix device reference leak in fsi_slave_init() error path

From: Guangshuo Li

Date: Sun Apr 12 2026 - 03:21:54 EST


After device_initialize(), the embedded struct device in struct
fsi_slave is expected to be released through the device core with
put_device().

In fsi_slave_init(), the cdev_device_add() failure path frees the slave
object directly instead of dropping the device reference, which bypasses
the normal device lifetime handling for the embedded struct device.

Since this path has already allocated the minor and taken a reference to
the OF node, switch it to put_device() so the cleanup is handled through
fsi_slave_release().

Fixes: 371975b0b0752 ("fsi/core: Fix error paths on CFAM init")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
drivers/fsi/fsi-core.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
index c6c115993ebc..444878ab9fb1 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -1084,7 +1084,8 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
rc = cdev_device_add(&slave->cdev, &slave->dev);
if (rc) {
dev_err(&slave->dev, "Error %d creating slave device\n", rc);
- goto err_free_ida;
+ put_device(&slave->dev);
+ return rc;
}

/* Now that we have the cdev registered with the core, any fatal
@@ -1110,8 +1111,6 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)

return 0;

-err_free_ida:
- fsi_free_minor(slave->dev.devt);
err_free:
of_node_put(slave->dev.of_node);
kfree(slave);
--
2.43.0