hl_device_fini() uses flush_delayed_work() to drain
device_reset_work.reset_work, but a flush cannot stop the work from
being armed again afterwards, so the reset work can still fire while -
or after - the device is torn down.

Simply switching the flush to disable_delayed_work_sync() is not
enough: a reset retry sitting on its timer holds reset_info.in_reset,
and only the work itself clears it (via out_err once
device_fini_pending is set).  Killing the work without running it
strands in_reset, and hl_device_fini() then waits for the full
HL_HARD_RESET_MAX_TIMEOUT and returns without tearing the device
down.

So keep the flush first: with device_fini_pending set, a pending
retry runs immediately and clears in_reset via out_err.  Then, after
in_reset has been claimed for fini - so no new reset can be queued
and the reset thread does not re-arm - disable the work to guarantee
nothing is pending or running during the teardown.

Found by static analysis.

Signed-off-by: Chengyu Liu <[email protected]>
---
v2: keep the flush so a pending reset retry still runs and clears
    in_reset (sashiko review); the disable now happens after in_reset
    is claimed for fini, where no new reset can be queued and the
    reset thread does not re-arm.

 drivers/accel/habanalabs/common/device.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/accel/habanalabs/common/device.c 
b/drivers/accel/habanalabs/common/device.c
index 09b27bac3a31..c27c13e693d5 100644
--- a/drivers/accel/habanalabs/common/device.c
+++ b/drivers/accel/habanalabs/common/device.c
@@ -2527,6 +2527,13 @@ void hl_device_fini(struct hl_device *hdev)
                }
        }
 
+       /*
+        * in_reset is claimed now, so no new reset can be queued and the
+        * reset thread does not re-arm with device_fini_pending set; make
+        * sure no reset work is left pending or running during teardown.
+        */
+       disable_delayed_work_sync(&hdev->device_reset_work.reset_work);
+
        
cancel_delayed_work_sync(&hdev->device_release_watchdog_work.reset_work);
 
        /* Disable PCI access from device F/W so it won't send us additional
-- 
2.25.1

Reply via email to