Linux Hardware Monitor development
 help / color / mirror / Atom feed
* [PATCH] hwmon: (fschmd) avoid client->dev dereference in watchdog_release
@ 2026-05-23  5:10 Chen-Shi-Hong
  2026-05-23  5:44 ` sashiko-bot
  2026-05-23 13:24 ` Guenter Roeck
  0 siblings, 2 replies; 4+ messages in thread
From: Chen-Shi-Hong @ 2026-05-23  5:10 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux-hwmon, linux-kernel, Chen-Shi-Hong

fschmd_remove() can detach the i2c client while the watchdog device
is still open.

If watchdog_release() later takes the unexpected-close path, it calls
watchdog_trigger() and then logs the event with dev_crit() using
data->client->dev. However, the client may already have been cleared
by the remove path.

watchdog_trigger() already checks whether data->client is still valid
and returns -ENODEV if the client is gone. Use its return value to
decide whether to emit the message, and log with watchdog_name instead
of dereferencing data->client->dev.

This avoids relying on a device pointer that may no longer be valid
during release after device removal.

Signed-off-by: Chen-Shi-Hong <eric039eric@gmail.com>
---
 drivers/hwmon/fschmd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c
index 1211fa2259e5..d1e7fc72e81f 100644
--- a/drivers/hwmon/fschmd.c
+++ b/drivers/hwmon/fschmd.c
@@ -834,9 +834,9 @@ static int watchdog_release(struct inode *inode, struct file *filp)
 		watchdog_stop(data);
 		data->watchdog_expect_close = 0;
 	} else {
-		watchdog_trigger(data);
-		dev_crit(&data->client->dev,
-			"unexpected close, not stopping watchdog!\n");
+		if (!watchdog_trigger(data))
+			pr_crit("%s: unexpected close, not stopping watchdog!\n",
+				data->watchdog_name);
 	}
 
 	clear_bit(0, &data->watchdog_is_open);
-- 
2.53.0


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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-23  5:10 [PATCH] hwmon: (fschmd) avoid client->dev dereference in watchdog_release Chen-Shi-Hong
2026-05-23  5:44 ` sashiko-bot
2026-05-23 13:24 ` Guenter Roeck
2026-05-23 13:44   ` Chen-Shi-Hong

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