Skip to contentSkip to conversation

hwmon: pwm-fan: use managed timer shutdown

PATCH In review Kirtikumar Anandrao Ramchandani 2 participants 2 messages Nov 4 1 message not in the archive Hardware monitoring

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 2/2 hwmon: pwm-fan: use managed timer shutdown

Replace the private devres timer cleanup action with devm_timer_autoshutdown(). Keep initialization and action registration at their existing positions, preserving the cleanup order. The system shutdown path continues to call timer_shutdown_sync() directly.

---
 drivers/hwmon/pwm-fan.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/hwmon/pwm-fan.c +3 -9
index 9cabbe9f8..6b02c2687 100644
@@ -8,6 +8,7 @@
  */
 
 #include <linux/delay.h>
+#include <linux/devm-helpers.h>
 #include <linux/hwmon.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
@@ -493,13 +494,6 @@ static void pwm_fan_cleanup(void *__ctx)
 	}
 }
 
-static void pwm_fan_timer_cleanup(void *__ctx)
-{
-	struct pwm_fan_ctx *ctx = __ctx;
-
-	timer_shutdown_sync(&ctx->rpm_timer);
-}
-
 static int pwm_fan_probe(struct platform_device *pdev)
 {
 	struct thermal_cooling_device *cdev;
@@ -650,7 +644,7 @@ static int pwm_fan_probe(struct platform_device *pdev)
 	}
 
 	if (ctx->tach_count > 0) {
-		ret = devm_add_action_or_reset(dev, pwm_fan_timer_cleanup, ctx);
+		ret = devm_timer_autoshutdown(dev, &ctx->rpm_timer);
 		if (ret)
 			return ret;
 
@@ -710,7 +704,7 @@ static void pwm_fan_shutdown(struct platform_device *pdev)
 {
 	struct pwm_fan_ctx *ctx = platform_get_drvdata(pdev);
 
-	pwm_fan_timer_cleanup(ctx);
+	timer_shutdown_sync(&ctx->rpm_timer);
 	pwm_fan_cleanup(ctx);
 }
maintainer
#2 lore raw
Quoted 6 lines · Kirtikumar Anandrao Ramchandani

Replace the private devres timer cleanup action with devm_timer_autoshutdown(). Keep initialization and action registration at their existing positions, preserving the cleanup order. The system shutdown path continues to call timer_shutdown_sync() directly.

I fail to see how this would improve the code. This looks like just a random change to me with no real benefit. It just replaces devm_add_action_or_reset() with devm_timer_autoshutdown().

It also seems logically wrong: devm functions should be associated with some initialization or action (such as devm_kzalloc -> kfree), and not require a separate cleanup. I'd expect to see a devm_timer_setup() or similar instead, if at all.

Guenter

Quoted 47 lines
---
  drivers/hwmon/pwm-fan.c | 12 +++---------
  1 file changed, 3 insertions(+), 9 deletions(-)
drivers/hwmon/pwm-fan.c +3 -9
index 9cabbe9f8..6b02c2687 100644
@@ -8,6 +8,7 @@
   */
 
  #include <linux/delay.h>
+#include <linux/devm-helpers.h>
  #include <linux/hwmon.h>
  #include <linux/interrupt.h>
  #include <linux/module.h>
@@ -493,13 +494,6 @@ static void pwm_fan_cleanup(void *__ctx)
  	}
  }
 
-static void pwm_fan_timer_cleanup(void *__ctx)
-{
-	struct pwm_fan_ctx *ctx = __ctx;
-
-	timer_shutdown_sync(&ctx->rpm_timer);
-}
-
  static int pwm_fan_probe(struct platform_device *pdev)
  {
  	struct thermal_cooling_device *cdev;
@@ -650,7 +644,7 @@ static int pwm_fan_probe(struct platform_device *pdev)
  	}
 
  	if (ctx->tach_count > 0) {
-		ret = devm_add_action_or_reset(dev, pwm_fan_timer_cleanup, ctx);
+		ret = devm_timer_autoshutdown(dev, &ctx->rpm_timer);
  		if (ret)
  			return ret;
 
@@ -710,7 +704,7 @@ static void pwm_fan_shutdown(struct platform_device *pdev)
  {
  	struct pwm_fan_ctx *ctx = platform_get_drvdata(pdev);
 
-	pwm_fan_timer_cleanup(ctx);
+	timer_shutdown_sync(&ctx->rpm_timer);
  	pwm_fan_cleanup(ctx);
  }