linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: take module reference during async scan
@ 2020-09-07 15:47 Tomas Henzl
  2020-09-07 16:57 ` Bart Van Assche
  2020-09-07 17:46 ` James Bottomley
  0 siblings, 2 replies; 12+ messages in thread
From: Tomas Henzl @ 2020-09-07 15:47 UTC (permalink / raw)
  To: linux-scsi

During an async scan the driver shost->hostt structures are used,
that may cause issues when the driver is removed at that time.
As protection take the module reference.

Signed-off-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/scsi_scan.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index f2437a757..c9cc0862c 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1825,6 +1825,8 @@ static void do_scan_async(void *_data, async_cookie_t c)
 
 	do_scsi_scan_host(shost);
 	scsi_finish_async_scan(data);
+
+	module_put(shost->hostt->module);
 }
 
 /**
@@ -1848,6 +1850,12 @@ void scsi_scan_host(struct Scsi_Host *shost)
 		return;
 	}
 
+	/* protection against surprise driver removal
+	 * module_put is called from do_scan_async
+	 */
+	if (!try_module_get(shost->hostt->module))
+		return;
+
 	/* register with the async subsystem so wait_for_device_probe()
 	 * will flush this work
 	 */
-- 
2.25.4


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

end of thread, other threads:[~2020-09-08 14:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-07 15:47 [PATCH] scsi: take module reference during async scan Tomas Henzl
2020-09-07 16:57 ` Bart Van Assche
2020-09-07 21:12   ` Tomas Henzl
2020-09-07 17:46 ` James Bottomley
2020-09-07 20:09   ` Tomas Henzl
2020-09-07 20:24     ` James Bottomley
2020-09-07 21:02       ` Tomas Henzl
2020-09-07 22:02         ` James Bottomley
2020-09-08  8:22           ` Tomas Henzl
2020-09-07 21:32   ` Douglas Gilbert
2020-09-07 22:56     ` James Bottomley
2020-09-08 14:04     ` John Garry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).