[PATCH AUTOSEL 6.18-6.12] hwmon: (raspberrypi) Fix delayed-work teardown race
Sasha Levin
sashal at kernel.org
Mon Aug 31 06:21:33 PDT 2026
From: Shubham Chakraborty <chakrabortyshubham66 at gmail.com>
[ Upstream commit eb0d491e2787aa359f0d930151ff6e5e5df70fb9 ]
The delayed polling work rearms itself from the work function, so use
explicit delayed-work setup and cleanup instead of
devm_delayed_work_autocancel().
Initialize the delayed work with INIT_DELAYED_WORK() and register a
devres cleanup action that calls disable_delayed_work_sync() during
teardown.
This addresses the concern raised during review about the polling work
being able to requeue itself while the driver is being removed.
Signed-off-by: Shubham Chakraborty <chakrabortyshubham66 at gmail.com>
Link: https://lore.kernel.org/r/20260517080445.103962-4-chakrabortyshubham66@gmail.com
Signed-off-by: Guenter Roeck <linux at roeck-us.net>
Signed-off-by: Sasha Levin <sashal at kernel.org>
---
LLM Generated explanations, may be completely bogus:
Those background searches finished and match the earlier analysis:
- On **6.18.44 (HEAD)**, `git log --grep` does not find this fix — only
unrelated teardown commits show up.
- On **master**, the fix is **`eb0d491e2787a`** (`hwmon: (raspberrypi)
Fix delayed-work teardown race`), merged via the `hwmon-for-v7.2` tag.
- It is present on **next** branches (`all-next`, `arch-next`, etc.) but
**not** on the checked-out **6.18.y** stable tree.
That confirms the patch still needs to be backported to 6.18.44, and the
**YES** recommendation stands.
drivers/hwmon/raspberrypi-hwmon.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/hwmon/raspberrypi-hwmon.c b/drivers/hwmon/raspberrypi-hwmon.c
index a2938881ccd2f..b0f0f50986b9a 100644
--- a/drivers/hwmon/raspberrypi-hwmon.c
+++ b/drivers/hwmon/raspberrypi-hwmon.c
@@ -7,7 +7,6 @@
* Copyright (C) 2018 Stefan Wahren <stefan.wahren at i2se.com>
*/
#include <linux/device.h>
-#include <linux/devm-helpers.h>
#include <linux/err.h>
#include <linux/hwmon.h>
#include <linux/module.h>
@@ -72,6 +71,13 @@ static void get_values_poll(struct work_struct *work)
schedule_delayed_work(&data->get_values_poll_work, 2 * HZ);
}
+static void rpi_hwmon_cancel_poll_work(void *res)
+{
+ struct rpi_hwmon_data *data = res;
+
+ disable_delayed_work_sync(&data->get_values_poll_work);
+}
+
static int rpi_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
@@ -117,8 +123,8 @@ static int rpi_hwmon_probe(struct platform_device *pdev)
if (IS_ERR(data->hwmon_dev))
return PTR_ERR(data->hwmon_dev);
- ret = devm_delayed_work_autocancel(dev, &data->get_values_poll_work,
- get_values_poll);
+ INIT_DELAYED_WORK(&data->get_values_poll_work, get_values_poll);
+ ret = devm_add_action_or_reset(dev, rpi_hwmon_cancel_poll_work, data);
if (ret)
return ret;
platform_set_drvdata(pdev, data);
--
2.53.0
More information about the linux-arm-kernel
mailing list