pcmcia: fix setting of kthread task states
authorDominik Brodowski <linux@dominikbrodowski.net>
Sun, 9 Jan 2022 09:02:51 +0000 (10:02 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jan 2022 07:47:35 +0000 (08:47 +0100)
[ Upstream commit fbb3485f1f931102d8ba606f1c28123f5b48afa3 ]

We need to set TASK_INTERRUPTIBLE before calling kthread_should_stop().
Otherwise, kthread_stop() might see that the pccardd thread is still
in TASK_RUNNING state and fail to wake it up.

Additionally, we only need to set the state back to TASK_RUNNING if
kthread_should_stop() breaks the loop.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Fixes: d3046ba809ce ("pcmcia: fix a boot time warning in pcmcia cs code")
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/pcmcia/cs.c

index c3b615c94b4bffaaff0ce3579e47c4c890a6a2c0..a92cbc952b70b36f8383a7fe7bfbf81c3656c921 100644 (file)
@@ -665,18 +665,16 @@ static int pccardd(void *__skt)
                if (events || sysfs_events)
                        continue;
 
+               set_current_state(TASK_INTERRUPTIBLE);
                if (kthread_should_stop())
                        break;
 
-               set_current_state(TASK_INTERRUPTIBLE);
-
                schedule();
 
-               /* make sure we are running */
-               __set_current_state(TASK_RUNNING);
-
                try_to_freeze();
        }
+       /* make sure we are running before we exit */
+       __set_current_state(TASK_RUNNING);
 
        /* shut down socket, if a device is still present */
        if (skt->state & SOCKET_PRESENT) {