* [PATCH] hwmon: (adt7470) Fix warning on module removal
@ 2022-04-07 10:13 Armin Wolf
2022-04-07 10:53 ` Zheyu Ma
2022-04-08 15:38 ` Guenter Roeck
0 siblings, 2 replies; 3+ messages in thread
From: Armin Wolf @ 2022-04-07 10:13 UTC (permalink / raw)
To: zheyuma97; +Cc: jdelvare, linux, linux-hwmon, linux-kernel
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.
Reported-by: Zheyu Ma <zheyuma97@gmail.com>
Fixes: 93cacfd41f82 (hwmon: (adt7470) Allow faster removal)
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
drivers/hwmon/adt7470.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index fb6d14d213a1..c67cd037a93f 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon: (adt7470) Fix warning on module removal
2022-04-07 10:13 [PATCH] hwmon: (adt7470) Fix warning on module removal Armin Wolf
@ 2022-04-07 10:53 ` Zheyu Ma
2022-04-08 15:38 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: Zheyu Ma @ 2022-04-07 10:53 UTC (permalink / raw)
To: Armin Wolf; +Cc: jdelvare, linux, linux-hwmon, Linux Kernel Mailing List
On Thu, Apr 7, 2022 at 6:13 PM Armin Wolf <W_Armin@gmx.de> wrote:
>
> 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.
>
> Reported-by: Zheyu Ma <zheyuma97@gmail.com>
> Fixes: 93cacfd41f82 (hwmon: (adt7470) Allow faster removal)
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
> drivers/hwmon/adt7470.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
> index fb6d14d213a1..c67cd037a93f 100644
> --- a/drivers/hwmon/adt7470.c
> +++ b/drivers/hwmon/adt7470.c
> @@ -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: Zheyu Ma <zheyuma97@gmail.com>
Thanks,
Zheyu Ma
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon: (adt7470) Fix warning on module removal
2022-04-07 10:13 [PATCH] hwmon: (adt7470) Fix warning on module removal Armin Wolf
2022-04-07 10:53 ` Zheyu Ma
@ 2022-04-08 15:38 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2022-04-08 15:38 UTC (permalink / raw)
To: Armin Wolf; +Cc: zheyuma97, jdelvare, linux-hwmon, linux-kernel
On Thu, Apr 07, 2022 at 12:13:12PM +0200, Armin Wolf wrote:
> 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.
>
> 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>
Applied.
Thanks,
Guenter
> ---
> drivers/hwmon/adt7470.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> --
> 2.30.2
>
> diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
> index fb6d14d213a1..c67cd037a93f 100644
> --- a/drivers/hwmon/adt7470.c
> +++ b/drivers/hwmon/adt7470.c
> @@ -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;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-08 15:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 10:13 [PATCH] hwmon: (adt7470) Fix warning on module removal Armin Wolf
2022-04-07 10:53 ` Zheyu Ma
2022-04-08 15:38 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®