Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (adt7470) Fix warning on module removal

When removing the adt7470 module, a warning might be printed:

do not call blocking ops when !TASK_RUNNING; state=1
set at [<ffffffffa006052b>] adt7470_update_thread+0x7b/0x130 [adt7470]

This happens because adt7470_update_thread() can leave the kthread in
TASK_INTERRUPTIBLE state when the kthread is being stopped before
the call of set_current_state(). Since kthread_exit() might sleep in
exit_signals(), the warning is printed.
Fix that by using schedule_timeout_interruptible() and removing
the call of set_current_state().
This causes TASK_INTERRUPTIBLE to be set after kthread_should_stop()
which might cause the kthread to exit.

Reported-by: Zheyu Ma <zheyuma97@gmail.com>
Fixes: 93cacfd41f82 (hwmon: (adt7470) Allow faster removal)
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Tested-by: Zheyu Ma <zheyuma97@gmail.com>
Link: https://lore.kernel.org/r/20220407101312.13331-1-W_Armin@gmx.de
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Armin Wolf and committed by
Guenter Roeck
7b2666ce 4fd45cc8

+2 -2
+2 -2
drivers/hwmon/adt7470.c
··· 19 19 #include <linux/log2.h> 20 20 #include <linux/kthread.h> 21 21 #include <linux/regmap.h> 22 + #include <linux/sched.h> 22 23 #include <linux/slab.h> 23 24 #include <linux/util_macros.h> 24 25 ··· 295 294 adt7470_read_temperatures(data); 296 295 mutex_unlock(&data->lock); 297 296 298 - set_current_state(TASK_INTERRUPTIBLE); 299 297 if (kthread_should_stop()) 300 298 break; 301 299 302 - schedule_timeout(msecs_to_jiffies(data->auto_update_interval)); 300 + schedule_timeout_interruptible(msecs_to_jiffies(data->auto_update_interval)); 303 301 } 304 302 305 303 return 0;