Luis Chamberlain (1): scsi: sd: Add error handling support for add_disk()
Zhong Jinghua (1): scsi: sd: Clean up sdkp if device_add_disk() failed
drivers/scsi/sd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/2843 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/7...
FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/2843 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/7...
From: Luis Chamberlain mcgrof@kernel.org
mainline inclusion from mainline-v5.16-rc1 commit 2a7a891f4c406822801ecd676b076c64de072c9e category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I81XCK
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
----------------------------------------
We never checked for errors on add_disk() as this function returned void. Now that this is fixed, use the shiny new error handling.
As with the error handling for device_add() we follow the same logic and just put the device so that cleanup is done via the scsi_disk_release().
Link: https://lore.kernel.org/r/20211015233028.2167651-2-mcgrof@kernel.org Reviewed-by: Christoph Hellwig hch@lst.de Acked-by: Martin K. Petersen martin.petersen@oracle.com Signed-off-by: Luis Chamberlain mcgrof@kernel.org Signed-off-by: Martin K. Petersen martin.petersen@oracle.com conflict: drivers/scsi/sd.c Signed-off-by: Zhong Jinghua zhongjinghua@huawei.com Signed-off-by: Li Nan linan122@huawei.com --- drivers/scsi/sd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 7c8bfb26c995..0a83320deb14 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3498,7 +3498,13 @@ static int sd_probe(struct device *dev) pm_runtime_set_autosuspend_delay(dev, sdp->host->hostt->rpm_autosuspend_delay); } - device_add_disk(dev, gd, NULL); + + error = device_add_disk_safe(dev, gd, NULL); + if (error) { + put_device(&sdkp->dev); + goto out; + } + blk_delete_region(disk_devt(sdkp->disk), SD_MINORS, sd_default_probe); if (sdkp->security) { sdkp->opal_dev = init_opal_dev(sdkp, &sd_sec_submit);
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; }