From: sashiko-bot@kernel.org
To: "Guenter Roeck" <linux@roeck-us.net>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v2 2/2] hwmon: (lm90) Add lock protection to lm90_alert
Date: Fri, 15 May 2026 01:18:36 +0000 [thread overview]
Message-ID: <20260515011837.54DECC2BCC6@smtp.kernel.org> (raw)
In-Reply-To: <20260514235626.1403695-2-linux@roeck-us.net>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Race condition between sysfs reads and devres teardown (`lm90_stop_work`) leaves delayed work enqueued after the data structure is freed.
--
commit a26cbd27d33d410e7909a5d68c680507e329f297
Author: Guenter Roeck <linux@roeck-us.net>
hwmon: (lm90) Add lock protection to lm90_alert
This commit adds hwmon_lock protection to lm90_alert() to prevent
concurrent sysfs writes from overwriting hardware register modifications
made during alert handling.
> diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
> index 08a568f7b56f9..9d0c23420842a 100644
> --- a/drivers/hwmon/lm90.c
> +++ b/drivers/hwmon/lm90.c
> @@ -2944,6 +2944,7 @@ static void lm90_alert(struct i2c_client *client, enum i2c_alert_protocol type,
> */
> struct lm90_data *data = i2c_get_clientdata(client);
>
> + hwmon_lock(data->hwmon_dev);
> if (!data->shutdown && (data->flags & LM90_HAVE_BROKEN_ALERT) &&
> (data->current_alarms & data->alert_alarms)) {
> if (!(data->config & 0x80)) {
> @@ -2953,6 +2954,7 @@ static void lm90_alert(struct i2c_client *client, enum i2c_alert_protocol type,
> schedule_delayed_work(&data->alert_work,
> max_t(int, HZ, msecs_to_jiffies(data->update_interval)));
> }
> + hwmon_unlock(data->hwmon_dev);
While this isn't a regression introduced by this patch, could a similar race
condition cause a use-after-free during driver unbind?
In lm90_probe(), the hwmon device is registered via
devm_hwmon_device_register_with_info() before registering the teardown action
lm90_stop_work(). Since devres actions execute in LIFO order,
lm90_stop_work() runs while the hwmon device and sysfs attributes are still
accessible.
lm90_stop_work() sets data->shutdown = true and completes
cancel_delayed_work_sync() without acquiring hwmon_lock(data->hwmon_dev).
Could this race with a concurrent sysfs read operation in
lm90_update_alarms_locked()?
CPU1 (sysfs read)
hwmon_lock(data->hwmon_dev);
// checks data->shutdown, sees false
// preempted before scheduling work...
CPU2 (unbind)
lm90_stop_work()
data->shutdown = true;
cancel_delayed_work_sync(&data->alert_work);
// proceeds to unregister device, blocking on CPU1's sysfs read
CPU1 (resumes)
schedule_delayed_work(&data->alert_work, ...);
hwmon_unlock(data->hwmon_dev);
After CPU1 releases the lock, CPU2 unblocks, finishes unregistering the
device, and devres frees the data structure. The incorrectly enqueued work
timer will then fire and access the freed memory.
Should lm90_stop_work() also acquire hwmon_lock() when setting
data->shutdown = true to serialize against concurrent sysfs operations?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260514235626.1403695-1-linux@roeck-us.net?part=2
next prev parent reply other threads:[~2026-05-15 1:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-14 23:56 [PATCH v2 1/2] hwmon: (lm90) Stop work before releasing hwmon device Guenter Roeck
2026-05-14 23:56 ` [PATCH v2 2/2] hwmon: (lm90) Add lock protection to lm90_alert Guenter Roeck
2026-05-15 1:18 ` sashiko-bot [this message]
2026-05-15 0:37 ` [PATCH v2 1/2] hwmon: (lm90) Stop work before releasing hwmon device sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260515011837.54DECC2BCC6@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.