scsi: raid_class: fix possible memory leak in raid_component_add()
PATCH 1/1 scsi: raid_class: fix possible memory leak in raid_component_add()
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" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Signed-off-by Yang Yingliang <[email protected]>
--- drivers/scsi/raid_class.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/raid_class.c +1 -2
@@ -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);
Signature · 1 line
2.25.1