Skip to contentSkip to conversation

pcmcia: fix setting of kthread task states

PATCH In review Dominik Brodowski 2 participants 2 messages Jan 9, 2022 Pcmcia

lore
Share & tools
lore

Dominik Brodowski

author maintainer
#0 lore raw

PATCH 1/1 pcmcia: fix setting of kthread task states

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.

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

Cc Matthew Wilcox <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Fixes d3046ba809ce ("pcmcia: fix a boot time warning in pcmcia cs code")
---
 drivers/pcmcia/cs.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/pcmcia/cs.c +3 -5
index e211e2619680..f70197154a36 100644
@@ -666,18 +666,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) {
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Dominik Brodowski

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.

Quoted 8 lines

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

Cc Matthew Wilcox <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Fixes d3046ba809ce ("pcmcia: fix a boot time warning in pcmcia cs code")