diff mbox series

scsi: raid_class: fix possible memory leak in raid_component_add()

Message ID 20221102093112.2678-1-yangyingliang@huawei.com (mailing list archive)
State Deferred
Headers show
Series scsi: raid_class: fix possible memory leak in raid_component_add() | expand

Commit Message

Yang Yingliang Nov. 2, 2022, 9:31 a.m. UTC
Afer commit 1fa5ae857bb1 ("driver core: get rid of struct device's
bus_id string array"), the name of device is allocated dynamically,
it need be freed if device_add(&rc->dev) returns error, as comment of
device_add() says, it should call put_device() to drop the reference
on error.

Fix it by calling put_device(&rc->dev) so that the name can be freed
in kobject_cleanup(). In raid_component_release(), it will put refcount
of component_dev and free 'rc', so the release code of them in error
path can be removed.

Fixes: 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/scsi/raid_class.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/scsi/raid_class.c b/drivers/scsi/raid_class.c
index 898a0bdf8df6..86ed1f66d749 100644
--- a/drivers/scsi/raid_class.c
+++ b/drivers/scsi/raid_class.c
@@ -250,8 +250,7 @@  int raid_component_add(struct raid_template *r,struct device *raid_dev,
 err_out:
 	list_del(&rc->node);
 	rd->component_count--;
-	put_device(component_dev);
-	kfree(rc);
+	put_device(&rc->dev);
 	return err;
 }
 EXPORT_SYMBOL(raid_component_add);