fsi: Fix error handling in fsi_slave_init
Subsystems (2)
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.
--- drivers/fsi/fsi-core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/fsi/fsi-core.c +4 -1
@@ -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
Quoted 3 lines
fsi_slave_init()callsdevice_initialize()forslave->devunconditionally. However, in the error paths,put_device()is not called, leading to an imbalance in the device reference count.
…
Would an other word wrapping be a bit nicer for such a change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc4#n658
Regards,
Markus