Skip to content

Commit 04b5b5c

Browse files
PeterZhu789martinkpetersen
authored andcommitted
scsi: core: Fix possible memory leak if device_add() fails
If device_add() returns error, the name allocated by dev_set_name() needs be freed. As the comment of device_add() says, put_device() should be used 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(). Fixes: ee959b0 ("SCSI: convert struct class_device to struct device") Signed-off-by: Zhu Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 9426d3c commit 04b5b5c

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

drivers/scsi/raid_class.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ int raid_component_add(struct raid_template *r,struct device *raid_dev,
248248
return 0;
249249

250250
err_out:
251+
put_device(&rc->dev);
251252
list_del(&rc->node);
252253
rd->component_count--;
253254
put_device(component_dev);

0 commit comments

Comments
 (0)