Linux Hardware Monitor development
 help / color / mirror / Atom feed
* [PATCH 1/2] hwmon: (lm90) Stop work before releasing hwmon device
@ 2026-05-14 22:02 Guenter Roeck
  2026-05-14 22:02 ` [PATCH 2/2] hwmon: (lm90) Add lock protection to lm90_alert Guenter Roeck
  2026-05-14 22:39 ` [PATCH 1/2] hwmon: (lm90) Stop work before releasing hwmon device sashiko-bot
  0 siblings, 2 replies; 4+ messages in thread
From: Guenter Roeck @ 2026-05-14 22:02 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Guenter Roeck

Sashiko reports:

In lm90_probe(), the devm action to cancel the alert_work and report_work
(lm90_restore_conf) is registered in lm90_init_client() before
devm_hwmon_device_register_with_info() is called.

Because devm executes cleanup actions in reverse order during module
unbind or probe failure, the hwmon device is unregistered and freed first.

If lm90_alert_work() or lm90_report_alarms() runs in the window between
the hwmon device being freed and the delayed works being cancelled,
lm90_update_alarms() will dereference the freed data->hwmon_dev here.

Fix the problem by canceling the workers separately after registering
the hwmon device and before registering the interrupt handler. This ensures
that the workers are canceled after interrupts are disabled and before
the hwmon device is released.

Fixes: f6d0775119fb9 ("hwmon: (lm90) Rework alarm/status handling")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/lm90.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index 3c10a5066b53..50b30d719225 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -2584,15 +2584,20 @@ static void lm90_restore_conf(void *_data)
 	struct lm90_data *data = _data;
 	struct i2c_client *client = data->client;
 
-	cancel_delayed_work_sync(&data->alert_work);
-	cancel_work_sync(&data->report_work);
-
 	/* Restore initial configuration */
 	if (data->flags & LM90_HAVE_CONVRATE)
 		lm90_write_convrate(data, data->convrate_orig);
 	lm90_write_reg(client, LM90_REG_CONFIG1, data->config_orig);
 }
 
+static void lm90_stop_work(void *_data)
+{
+	struct lm90_data *data = _data;
+
+	cancel_delayed_work_sync(&data->alert_work);
+	cancel_work_sync(&data->report_work);
+}
+
 static int lm90_init_client(struct i2c_client *client, struct lm90_data *data)
 {
 	struct device_node *np = client->dev.of_node;
@@ -2902,6 +2907,10 @@ static int lm90_probe(struct i2c_client *client)
 
 	data->hwmon_dev = hwmon_dev;
 
+	err = devm_add_action_or_reset(&client->dev, lm90_stop_work, data);
+	if (err)
+		return err;
+
 	if (client->irq) {
 		dev_dbg(dev, "IRQ: %d\n", client->irq);
 		err = devm_request_threaded_irq(dev, client->irq,
-- 
2.45.2


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

end of thread, other threads:[~2026-05-14 23:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-14 22:02 [PATCH 1/2] hwmon: (lm90) Stop work before releasing hwmon device Guenter Roeck
2026-05-14 22:02 ` [PATCH 2/2] hwmon: (lm90) Add lock protection to lm90_alert Guenter Roeck
2026-05-14 23:30   ` sashiko-bot
2026-05-14 22:39 ` [PATCH 1/2] hwmon: (lm90) Stop work before releasing hwmon device sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox