FAILED: patch "[PATCH] hwmon: (pwm-fan) Stop RPM timer before freeing tach data" failed to apply to 6.6-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 26d5ff79768548efb1e604bb6e8697c101e06269
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026092254-carat-drift-7011@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 26d5ff79768548efb1e604bb6e8697c101e06269 Mon Sep 17 00:00:00 2001
From: Yibo Tan <[email protected]>
Date: Fri, 11 Sep 2026 15:18:09 +0800
Subject: [PATCH] hwmon: (pwm-fan) Stop RPM timer before freeing tach data
sample_timer() rearms the RPM timer and accesses the devm-managed ctx->tachs and ctx->pulses_per_revolution arrays. The cleanup action which stops the timer is registered before those arrays are allocated.
Since devres releases entries in reverse order, driver detach can free the arrays before pwm_fan_cleanup() shuts down the timer. A timer expiry in that window accesses the freed tach data.
With a KASAN kernel, a test-only kprobe delayed entry to pwm_fan_cleanup() while normal sysfs unbind ran. Each of three runs reported three four-byte reads and two four-byte writes in sample_timer() after its backing devm allocations had been freed. The helper did not invoke the timer callback, cleanup actions or free functions.
With the fix, three matching unbind runs completed without KASAN, BUG, WARNING, Oops or panic. Instrumentation confirmed that timer retirement completed before the first timer backing allocation was released.
Split timer retirement from the power cleanup and register its devres action after the timer backing data and IRQ actions are installed. This preserves the early power rollback action while ensuring the timer is retired before its backing data is released. Use timer_shutdown_sync() because the callback can rearm itself.
drivers/hwmon/pwm-fan.c +12 -1
@@ -483,7 +483,6 @@ static void pwm_fan_cleanup(void *__ctx) {struct pwm_fan_ctx *ctx = __ctx; -timer_delete_sync (&ctx->rpm_timer);if (ctx->pwm_shutdown) { ctx->enable_mode = pwm_enable_reg_enable;__set_pwm (ctx, ctx->pwm_shutdown);
@@ -494,6 +493,13 @@ 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;
@@ -644,6 +650,10 @@ 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); +if (ret) +return ret; + ctx->sample_start =ktime_get ();mod_timer (&ctx->rpm_timer, jiffies +HZ );
@@ -700,6 +710,7 @@ static void pwm_fan_shutdown(struct platform_device *pdev) {struct pwm_fan_ctx *ctx =platform_get_drvdata (pdev); +pwm_fan_timer_cleanup (ctx);pwm_fan_cleanup (ctx); }
Sasha Levin
maintainerPATCH 1/1 hwmon: (pwm-fan) Stop RPM timer before freeing tach data
From: Yibo Tan <[email protected]>
[ Upstream commit 26d5ff79768548efb1e604bb6e8697c101e06269 ]
sample_timer() rearms the RPM timer and accesses the devm-managed ctx->tachs and ctx->pulses_per_revolution arrays. The cleanup action which stops the timer is registered before those arrays are allocated.
Since devres releases entries in reverse order, driver detach can free the arrays before pwm_fan_cleanup() shuts down the timer. A timer expiry in that window accesses the freed tach data.
With a KASAN kernel, a test-only kprobe delayed entry to pwm_fan_cleanup() while normal sysfs unbind ran. Each of three runs reported three four-byte reads and two four-byte writes in sample_timer() after its backing devm allocations had been freed. The helper did not invoke the timer callback, cleanup actions or free functions.
With the fix, three matching unbind runs completed without KASAN, BUG, WARNING, Oops or panic. Instrumentation confirmed that timer retirement completed before the first timer backing allocation was released.
Split timer retirement from the power cleanup and register its devres action after the timer backing data and IRQ actions are installed. This preserves the early power rollback action while ensuring the timer is retired before its backing data is released. Use timer_shutdown_sync() because the callback can rearm itself.
--- drivers/hwmon/pwm-fan.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/hwmon/pwm-fan.c +12 -1
@@ -466,12 +466,18 @@ static void pwm_fan_cleanup(void *__ctx) {struct pwm_fan_ctx *ctx = __ctx; -del_timer_sync (&ctx->rpm_timer);/* Switch off everything */ ctx->enable_mode = pwm_disable_reg_disable;pwm_fan_power_off (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;
@@ -606,6 +612,10 @@ 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); +if (ret) +return ret; + ctx->sample_start =ktime_get ();mod_timer (&ctx->rpm_timer, jiffies +HZ );
@@ -647,6 +657,7 @@ static void pwm_fan_shutdown(struct platform_device *pdev) {struct pwm_fan_ctx *ctx =platform_get_drvdata (pdev); +pwm_fan_timer_cleanup (ctx);pwm_fan_cleanup (ctx); }
Signature · 1 line
2.53.0