SCSI: fix possible memory leak while device_add() fails
PATCH 1/1 SCSI: fix possible memory leak while device_add() fails
If device_add() returns error, the name allocated by dev_set_name() need be freed. As comment of device_add() says, it should use put_device() to decrease the reference count in the error path. So fix this by calling put_device, then the name can be freed in kobject_cleanp().
--- drivers/scsi/raid_class.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/raid_class.c +3 -1
@@ -242,8 +242,10 @@ int raid_component_add(struct raid_template *r,struct device *raid_dev,list_add_tail (&rc->node, &rd->component_list); rc->dev.class = &raid_class.class; err =device_add (&rc->dev); -if (err) +if (err) { +put_device (&rc->dev); goto err_out; + }return 0 ;
Signature · 1 line
2.17.1
Quoted 16 lines · Zhu Wang
If
device_add()returns error, the name allocated bydev_set_name()need be freed. As comment ofdevice_add()says, it should useput_device()to decrease the reference count in the error path. So fix this by callingput_device, then the name can be freed inkobject_cleanp().Fixes ee959b00c335 ("SCSI: convert struct class_device to struct device")Signed-off-by Zhu Wang <[email protected]>--- drivers/scsi/raid_class.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/scsi/raid_class.c +0
-0
drivers/scsi/raid_class.c int raid_component_add(struct raid_template *r,struct device *raid_dev, · line 250
Quoted 10 lines
drivers/scsi/raid_class.c +3
-1@@ -242,8 +242,10 @@ int raid_component_add(struct raid_template *r,struct device *raid_dev,list_add_tail (&rc->node, &rd->component_list); rc->dev.class = &raid_class.class; err =device_add (&rc->dev); -if (err) +if (err) { +put_device (&rc->dev); goto err_out; + }return 0 ;
Please move the new put_device() call under the "err_out:" label.
Thanks,
Bart.