mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hwmon: (npcm750-pwm-fan): stop fan timer on device detach
@ 2026-07-28  7:55 Hongyan Xu
  2026-07-28 21:15 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Hongyan Xu @ 2026-07-28  7:55 UTC (permalink / raw)
  To: linux
  Cc: jianhao.xu, andrew, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, openbmc, linux-hwmon, linux-kernel,
	Hongyan Xu, stable

When a fan tach channel is present, npcm7xx_pwm_fan_probe() starts
fan_timer. The timer callback polls tach state and rearms the timer, but
the driver has no remove callback or devm cleanup action to stop it. On
device detach, the devm-managed driver data and I/O mappings can be
released while the timer is still pending or running.

Register a devm cleanup action before starting the timer and shut the
timer down synchronously from that action.

This issue was found by a static analysis tool.

Fixes: f1fd4a4db777 ("hwmon: Add NPCM7xx PWM and Fan driver")
Cc: stable@vger.kernel.org
Signed-off-by: Hongyan Xu <getshell@seu.edu.cn>
---
 drivers/hwmon/npcm750-pwm-fan.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/npcm750-pwm-fan.c b/drivers/hwmon/npcm750-pwm-fan.c
index aea0b8659f5..6503d28ed7b 100644
--- a/drivers/hwmon/npcm750-pwm-fan.c
+++ b/drivers/hwmon/npcm750-pwm-fan.c
@@ -358,6 +358,13 @@ static void npcm7xx_fan_polling(struct timer_list *t)
 	add_timer(&data->fan_timer);
 }
 
+static void npcm7xx_fan_cleanup(void *data)
+{
+	struct npcm7xx_pwm_fan_data *fan_data = data;
+
+	timer_shutdown_sync(&fan_data->fan_timer);
+}
+
 static inline void npcm7xx_fan_compute(struct npcm7xx_pwm_fan_data *data,
 				       u8 fan, u8 cmp, u8 fan_id, u8 flag_int,
 				       u8 flag_mode, u8 flag_clear)
@@ -1016,10 +1023,16 @@ static int npcm7xx_pwm_fan_probe(struct platform_device *pdev)
 	for (i = 0; i < NPCM7XX_FAN_MAX_CHN_NUM; i++) {
 		if (data->fan_present[i]) {
 			/* fan timer initialization */
-			data->fan_timer.expires = jiffies +
-				msecs_to_jiffies(NPCM7XX_FAN_POLL_TIMER_200MS);
 			timer_setup(&data->fan_timer,
 				    npcm7xx_fan_polling, 0);
+			ret = devm_add_action_or_reset(dev,
+						       npcm7xx_fan_cleanup,
+						       data);
+			if (ret)
+				return ret;
+
+			data->fan_timer.expires = jiffies +
+				msecs_to_jiffies(NPCM7XX_FAN_POLL_TIMER_200MS);
 			add_timer(&data->fan_timer);
 			break;
 		}
-- 
2.50.1.windows.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] hwmon: (npcm750-pwm-fan): stop fan timer on device detach
  2026-07-28  7:55 [PATCH] hwmon: (npcm750-pwm-fan): stop fan timer on device detach Hongyan Xu
@ 2026-07-28 21:15 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2026-07-28 21:15 UTC (permalink / raw)
  To: Hongyan Xu
  Cc: jianhao.xu, andrew, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, openbmc, linux-hwmon, linux-kernel,
	stable

On Tue, Jul 28, 2026 at 03:55:35PM +0800, Hongyan Xu wrote:
> When a fan tach channel is present, npcm7xx_pwm_fan_probe() starts
> fan_timer. The timer callback polls tach state and rearms the timer, but
> the driver has no remove callback or devm cleanup action to stop it. On
> device detach, the devm-managed driver data and I/O mappings can be
> released while the timer is still pending or running.
> 
> Register a devm cleanup action before starting the timer and shut the
> timer down synchronously from that action.
> 
> This issue was found by a static analysis tool.
> 
> Fixes: f1fd4a4db777 ("hwmon: Add NPCM7xx PWM and Fan driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hongyan Xu <getshell@seu.edu.cn>
> ---
>  drivers/hwmon/npcm750-pwm-fan.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/npcm750-pwm-fan.c b/drivers/hwmon/npcm750-pwm-fan.c
> index aea0b8659f5..6503d28ed7b 100644
> --- a/drivers/hwmon/npcm750-pwm-fan.c
> +++ b/drivers/hwmon/npcm750-pwm-fan.c
> @@ -358,6 +358,13 @@ static void npcm7xx_fan_polling(struct timer_list *t)
>  	add_timer(&data->fan_timer);
>  }
>  
> +static void npcm7xx_fan_cleanup(void *data)
> +{
> +	struct npcm7xx_pwm_fan_data *fan_data = data;
> +
> +	timer_shutdown_sync(&fan_data->fan_timer);

Why not pass the pointer to the timer as parameter to devm_add_action_or_reset()
and just pass it on here ?

> +}
> +
>  static inline void npcm7xx_fan_compute(struct npcm7xx_pwm_fan_data *data,
>  				       u8 fan, u8 cmp, u8 fan_id, u8 flag_int,
>  				       u8 flag_mode, u8 flag_clear)
> @@ -1016,10 +1023,16 @@ static int npcm7xx_pwm_fan_probe(struct platform_device *pdev)
>  	for (i = 0; i < NPCM7XX_FAN_MAX_CHN_NUM; i++) {
>  		if (data->fan_present[i]) {
>  			/* fan timer initialization */
> -			data->fan_timer.expires = jiffies +
> -				msecs_to_jiffies(NPCM7XX_FAN_POLL_TIMER_200MS);
>  			timer_setup(&data->fan_timer,
>  				    npcm7xx_fan_polling, 0);
> +			ret = devm_add_action_or_reset(dev,
> +						       npcm7xx_fan_cleanup,
> +						       data);
> +			if (ret)
> +				return ret;
> +
> +			data->fan_timer.expires = jiffies +
> +				msecs_to_jiffies(NPCM7XX_FAN_POLL_TIMER_200MS);

Your patch does not explain why this assignment needed to be moved. Please either
explain or keep at the original location to reduce the size of the diff.

Thanks,
Guenter

>  			add_timer(&data->fan_timer);
>  			break;
>  		}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-28 21:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-28  7:55 [PATCH] hwmon: (npcm750-pwm-fan): stop fan timer on device detach Hongyan Xu
2026-07-28 21:15 ` 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®