blob: 28d3d3f79554ef9aa7d8e1ec210627d802613bbf [file] [log] [blame]
From 9f018d39a25c4dc57b06e63da7e73f52e81f530b Mon Sep 17 00:00:00 2001
From: James Bottomley <>
Date: Wed, 8 Jan 2020 17:21:32 -0800
Subject: [PATCH] scsi: enclosure: Fix stale device oops with hot replug
commit 529244bd1afc102ab164429d338d310d5d65e60d upstream.
Doing an add/remove/add on a SCSI device in an enclosure leads to an oops
caused by poisoned values in the enclosure device list pointers. The
reason is because we are keeping the enclosure device across the enclosed
device add/remove/add but the current code is doing a
device_add/device_del/device_add on it. This is the wrong thing to do in
sysfs, so fix it by not doing a device_del on the enclosure device simply
because of a hot remove of the drive in the slot.
[mkp: added missing email addresses]
Fixes: 43d8eb9cfd0a ("[SCSI] ses: add support for enclosure component hot removal")
Signed-off-by: James Bottomley <>
Reported-by: Luo Jiaxing <>
Tested-by: John Garry <>
Signed-off-by: Martin K. Petersen <>
Signed-off-by: Paul Gortmaker <>
diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c
index 6d27ccfe0680..3c2d405bc79b 100644
--- a/drivers/misc/enclosure.c
+++ b/drivers/misc/enclosure.c
@@ -406,10 +406,9 @@ int enclosure_remove_device(struct enclosure_device *edev, struct device *dev)
cdev = &edev->component[i];
if (cdev->dev == dev) {
- device_del(&cdev->cdev);
cdev->dev = NULL;
- return device_add(&cdev->cdev);
+ return 0;
return -ENODEV;