Skip to contentSkip to conversation

hwmon: (adt7470) Fix warning on module removal

PATCH Applied Armin Wolf 3 participants 3 messages Apr 7, 2022 – Apr 8, 2022 Hardware monitoring

lore
Share & tools
lore

Armin Wolf

author
#0 lore raw

PATCH 1/1 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.

Compile-tested only.

Fixes 93cacfd41f82 (hwmon: (adt7470) Allow faster removal)
---
 drivers/hwmon/adt7470.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/adt7470.c +2 -2
index fb6d14d213a1..c67cd037a93f 100644
@@ -19,6 +19,7 @@
 #include <linux/log2.h>
 #include <linux/kthread.h>
 #include <linux/regmap.h>
+#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/util_macros.h>
 
@@ -294,11 +295,10 @@ static int adt7470_update_thread(void *p)
 		adt7470_read_temperatures(data);
 		mutex_unlock(&data->lock);
 
-		set_current_state(TASK_INTERRUPTIBLE);
 		if (kthread_should_stop())
 			break;
 
-		schedule_timeout(msecs_to_jiffies(data->auto_update_interval));
+		schedule_timeout_interruptible(msecs_to_jiffies(data->auto_update_interval));
 	}
 
 	return 0;

--
2.30.2

Tested-by on v1 1/1
#1 lore raw
Quoted 50 lines · Armin Wolf

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.

Compile-tested only.

Fixes 93cacfd41f82 (hwmon: (adt7470) Allow faster removal)
---
 drivers/hwmon/adt7470.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/adt7470.c +2 -3
index fb6d14d213a1..c67cd037a93f 100644
@@ -19,6 +19,7 @@
 #include <linux/log2.h>
 #include <linux/kthread.h>
 #include <linux/regmap.h>
+#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/util_macros.h>
 
@@ -294,11 +295,10 @@ static int adt7470_update_thread(void *p)
                adt7470_read_temperatures(data);
                mutex_unlock(&data->lock);
 
-               set_current_state(TASK_INTERRUPTIBLE);
                if (kthread_should_stop())
                        break;
 
-               schedule_timeout(msecs_to_jiffies(data->auto_update_interval));
+               schedule_timeout_interruptible(msecs_to_jiffies(data->auto_update_interval));
        }
 
        return 0;
--
Quoted 2 lines

2.30.2

Thanks,
Zheyu Ma

maintainer Applied
#2 lore raw
In reply to Armin Wolf
Quoted 14 lines · Armin Wolf

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.

Quoted 6 lines

Compile-tested only.

Fixes 93cacfd41f82 (hwmon: (adt7470) Allow faster removal)

Applied.

Thanks,
Guenter

Quoted 32 lines
---
 drivers/hwmon/adt7470.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--
2.30.2

drivers/hwmon/adt7470.c +2 -2
index fb6d14d213a1..c67cd037a93f 100644
@@ -19,6 +19,7 @@
 #include <linux/log2.h>
 #include <linux/kthread.h>
 #include <linux/regmap.h>
+#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/util_macros.h>
 
@@ -294,11 +295,10 @@ static int adt7470_update_thread(void *p)
 		adt7470_read_temperatures(data);
 		mutex_unlock(&data->lock);
 
-		set_current_state(TASK_INTERRUPTIBLE);
 		if (kthread_should_stop())
 			break;
 
-		schedule_timeout(msecs_to_jiffies(data->auto_update_interval));
+		schedule_timeout_interruptible(msecs_to_jiffies(data->auto_update_interval));
 	}
 
 	return 0;