Commit e7afdd19 authored by Zhong Jinghua's avatar Zhong Jinghua Committed by Li Nan
Browse files

scsi: sd: Clean up sdkp if device_add_disk() failed

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I81XCK



----------------------------------------

If device_add_disk fail, we should clear the resources requested by
device_add, otherwise sdkp is not be cleared and will cause memory
leaks.

Fix it by call device_del to clean the sdkp.

Fixes: 2a7a891f ("scsi: sd: Add error handling support for add_disk()")
Signed-off-by: default avatarZhong Jinghua <zhongjinghua@huawei.com>
Signed-off-by: default avatarLi Nan <linan122@huawei.com>
parent f172bfbe
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -3501,7 +3501,7 @@ static int sd_probe(struct device *dev)


	error = device_add_disk_safe(dev, gd, NULL);
	error = device_add_disk_safe(dev, gd, NULL);
	if (error) {
	if (error) {
		put_device(&sdkp->dev);
		device_unregister(&sdkp->dev);
		goto out;
		goto out;
	}
	}