
From: Zhong Jinghua <zhongjinghua@huawei.com> 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: 2a7a891f4c40 ("scsi: sd: Add error handling support for add_disk()") Signed-off-by: Zhong Jinghua <zhongjinghua@huawei.com> Signed-off-by: Li Nan <linan122@huawei.com> --- drivers/scsi/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 0a83320deb14..5385805e06a8 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3501,7 +3501,7 @@ static int sd_probe(struct device *dev) error = device_add_disk_safe(dev, gd, NULL); if (error) { - put_device(&sdkp->dev); + device_unregister(&sdkp->dev); goto out; } -- 2.39.2