mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v5 2/2] usb: storage: set surprise_removal flag on physical removal
@ 2026-10-09 11:31 胡连勤
  2026-11-20 11:49 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: 胡连勤 @ 2026-10-09 11:31 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen, Bart Van Assche,
	Greg Kroah-Hartman, Alan Stern
  Cc: Christoph Hellwig, Jens Axboe, Hannes Reinecke, Mike Christie,
	Damien Le Moal, John Garry, Shin'ichiro Kawasaki, linux-scsi,
	linux-usb, linux-block, linux-kernel, usb-storage, stable,
	胡连勤

Set the surprise_removal flag in struct Scsi_Host when the USB device
state is USB_STATE_NOTATTACHED, indicating the device has been
physically removed and cannot handle I/O.

This flag is checked by sd_remove() (added in the previous patch) to
skip sync_filesystem() during surprise removal, avoiding a hang waiting
for I/O that can never complete.

For orderly removal (e.g. rmmod, sysfs unbind) the USB device state is
not NOTATTACHED, so the flag is not set and sync proceeds normally,
preserving dirty data writeback.

Signed-off-by: Lianqin Hu <hulianqin@vivo.com>
---
 drivers/usb/storage/usb.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 064c7fc8e368..f6c81f7ff9f1 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -930,6 +930,9 @@ static void quiesce_and_remove_host(struct us_data *us)
 	if (us->pusb_dev->state == USB_STATE_NOTATTACHED) {
 		set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
 		wake_up(&us->delay_wait);
+
+		/* Device is physically gone, cannot handle I/O */
+		host->surprise_removal = 1;
 	}
 
 	/*
-- 
2.48.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-20 12:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-09 11:31 [PATCH v5 2/2] usb: storage: set surprise_removal flag on physical removal 胡连勤
2026-11-20 11:49 ` Greg Kroah-Hartman
2026-11-20 12:31   ` 答复: " 胡连勤

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®