fsi: Fix refcount leak in slave init error path
Subsystems (2)
PATCH 1/1 fsi: Fix refcount leak in slave init error path
After device_initialize(), the lifetime of slave is expected to be managed through the device core reference counting. In the cdev_device_add() failure path, slave and its associated resources are freed directly, rather than releasing the device reference with put_device(). This may leave the reference count of the embedded struct device unbalanced, resulting in a refcount leak and potentially leading to a use-after-free.
A possible fix would be to use put_device() in the failure path and let fsi_slave_release() handle the final cleanup.
Fixes d1dcd6782576 ("fsi: Add cfam char devices")
Signed-off-by Guangshuo Li <[email protected]>
--- drivers/fsi/fsi-core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/fsi/fsi-core.c +4 -3
@@ -1084,7 +1084,7 @@ 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; + goto err_put_dev; }/* Now that we have the cdev registered with the core, any fatal
@@ -1110,8 +1110,9 @@ 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_put_dev: +put_device (&slave->dev); +return rc; err_free:of_node_put (slave->dev.of_node);kfree (slave);
Signature · 1 line
2.43.0