From: Li Youhong <[email protected]>

stop_sync_thread() only flushes sync_work when work_pending() is true.
Once the work is running, PENDING is cleared, so an in-flight
md_start_sync() can be missed and teardown can race with it.

Use work_busy() instead, so both queued and executing sync_work are
flushed.

Fixes: db5e653d7c9f ("md: delay choosing sync action to md_start_sync()")
Cc: [email protected]
Signed-off-by: Li Youhong <[email protected]>

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 03e35386a802..1974943bf746 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -5213,7 +5213,7 @@ static void stop_sync_thread(struct mddev *mddev, bool 
locked)
         * never happen
         */
        md_wakeup_thread_directly(&mddev->sync_thread);
-       if (work_pending(&mddev->sync_work))
+       if (work_busy(&mddev->sync_work))
                flush_work(&mddev->sync_work);
 
        wait_event(resync_wait,


Reply via email to