diff mbox series

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

Message ID 20221018145651.1975792-1-yangyingliang@huawei.com
State New
Headers show
Series [1/2] fsi: master-hub: fix possible memory leak in hub_master_probe() | expand

Commit Message

Yang Yingliang Oct. 18, 2022, 2:56 p.m. UTC
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

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


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)
 	return 0;
+	put_device(&hub->master.dev);
 	fsi_slave_release_range(fsi_dev->slave, FSI_HUB_LINK_OFFSET,
 			FSI_HUB_LINK_SIZE * links);