[PATCH 1/2] fsi: master-hub: fix possible memory leak in hub_master_probe()

Yang Yingliang yangyingliang at huawei.com
Wed Oct 19 01:56:50 AEDT 2022


If fsi_master_register() fails, the name allocated in dev_set_name() and
the 'hub' need be freed, calling put_device(), so that the refcount of
device is decreased to 0, the name and the 'hub' can be freed in callback
function.

Fixes: 7f9e8f767030 ("drivers/fsi: Add hub master support")
Signed-off-by: Yang Yingliang <yangyingliang at huawei.com>
---
 drivers/fsi/fsi-master-hub.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/fsi/fsi-master-hub.c b/drivers/fsi/fsi-master-hub.c
index 01f0a796111e..b6f5833f2ee1 100644
--- a/drivers/fsi/fsi-master-hub.c
+++ b/drivers/fsi/fsi-master-hub.c
@@ -241,7 +241,7 @@ static int hub_master_probe(struct device *dev)
 
 	rc = fsi_master_register(&hub->master);
 	if (rc)
-		goto err_release;
+		goto err_register;
 
 	/* At this point, fsi_master_register performs the device_initialize(),
 	 * and holds the sole reference on master.dev. This means the device
@@ -253,6 +253,8 @@ static int hub_master_probe(struct device *dev)
 	get_device(&hub->master.dev);
 	return 0;
 
+err_register:
+	put_device(&hub->master.dev);
 err_release:
 	fsi_slave_release_range(fsi_dev->slave, FSI_HUB_LINK_OFFSET,
 			FSI_HUB_LINK_SIZE * links);
-- 
2.25.1



More information about the linux-fsi mailing list