Skip to contentSkip to conversation

scsi: ppa: cancel delayed work before freeing on detach

PATCH New Tristan Madani 1 participant 1 message Oct 19

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scsi: ppa: cancel delayed work before freeing on detach

From: Tristan Madani <[email protected]>

ppa_detach() frees the ppa_struct without cancelling the pending delayed work ppa_tq. If ppa_interrupt() is still scheduled or running when the struct is freed, the work function accesses freed memory via container_of().

Add cancel_delayed_work_sync() after scsi_remove_host() has drained all in-flight commands and before the struct is freed. The cancel is placed after host removal so that ppa_interrupt() can still poll in-flight commands to completion during the drain, and no new commands can be queued after scsi_remove_host() returns.

Fixes c4028958b6eca ("WorkStruct: make allyesconfig")

---
Changes in v2:
- Moved cancel_delayed_work_sync() after scsi_remove_host() so that ppa_interrupt() can still poll in-flight commands to completion during the host drain. In v1 the cancel was placed before list_del_init() which could stall scsi_remove_host() by killing the polling mechanism for in-flight commands.

 drivers/scsi/ppa.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/ppa.c +1 -0
index 8a4e910d5758f..d4fc8eedc29ce 100644
@@ -1139,6 +1139,7 @@ static void ppa_detach(struct parport *pb)
 			list_del_init(&dev->list);
 			scsi_remove_host(dev->host);
 			scsi_host_put(dev->host);
+			cancel_delayed_work_sync(&dev->ppa_tq);
 			parport_unregister_device(dev->dev);
 			kfree(dev);
 			break;
Signature · 1 line
2.47.3