Skip to contentSkip to conversation

fsi: Fix error handling in fsi_slave_init

PATCH In review Ma Ke 2 participants 2 messages Nov 7, 2025

Subsystems (2)
lore
Share & tools
lore

Ma Ke

author
#0 lore raw

PATCH 1/1 fsi: Fix error handling in fsi_slave_init

fsi_slave_init() calls device_initialize() for slave->dev unconditionally. However, in the error paths, put_device() is not called, leading to an imbalance in the device reference count.

Although kfree(slave) eventually frees the memory, it does not properly release the device initialized by device_initialize(). For proper pairing of device_initialize()/put_device(), add put_device() calls in both error paths.

Found by code review.

Fixes d1dcd6782576 ("fsi: Add cfam char devices")
---
 drivers/fsi/fsi-core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/fsi/fsi-core.c +4 -1
index c6c115993ebc..0d45e4442ca9 100644
@@ -1075,7 +1075,7 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
 	rc = __fsi_get_new_minor(slave, fsi_dev_cfam, &slave->dev.devt,
 				 &slave->cdev_idx);
 	if (rc)
-		goto err_free;
+		goto err_put_device;
 
 	trace_fsi_slave_init(slave);
 
@@ -1112,6 +1112,9 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
 
 err_free_ida:
 	fsi_free_minor(slave->dev.devt);
+err_put_device:
+	put_device(&slave->dev);
+	return rc;
 err_free:
 	of_node_put(slave->dev.of_node);
 	kfree(slave);
Signature · 1 line
2.17.1