All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hwmon: (asus-ec-sensors) fix EC read intervals
@ 2026-07-12 10:54 Eugene Shalygin
  2026-07-12 11:02 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Eugene Shalygin @ 2026-07-12 10:54 UTC (permalink / raw)
  To: eugene.shalygin
  Cc: Guenter Roeck, open list:ASUS EC HARDWARE MONITOR DRIVER,
	open list

Take INITIAL_JIFFIES into account when setting up next update time.

Signed-off-by: Eugene Shalygin <eugene.shalygin@gmail.com>

Fixes: d0ddfd241e57 ("hwmon: (asus-ec-sensors) add driver for ASUS EC")
---
 drivers/hwmon/asus-ec-sensors.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/asus-ec-sensors.c b/drivers/hwmon/asus-ec-sensors.c
index 29a23484cbe7..4746c3718664 100644
--- a/drivers/hwmon/asus-ec-sensors.c
+++ b/drivers/hwmon/asus-ec-sensors.c
@@ -1009,7 +1009,7 @@ struct ec_sensors_data {
 	/* sorted list of unique register banks */
 	u8 banks[ASUS_EC_MAX_BANK + 1];
 	/* in jiffies */
-	unsigned long last_updated;
+	u64 next_update;
 	struct lock_data lock_data;
 	/* number of board EC sensors */
 	u8 nr_sensors;
@@ -1278,13 +1278,12 @@ static int get_cached_value_or_update(const struct device *dev,
 				      int sensor_index,
 				      struct ec_sensors_data *state, s32 *value)
 {
-	if (time_after(jiffies, state->last_updated + HZ)) {
+	if (time_after64(get_jiffies_64(), state->next_update)) {
+		state->next_update = get_jiffies_64() + HZ;
 		if (update_ec_sensors(dev, state)) {
 			dev_err(dev, "update_ec_sensors() failure\n");
 			return -EIO;
 		}
-
-		state->last_updated = jiffies;
 	}
 
 	*value = state->sensors[sensor_index].cached_value;
@@ -1402,6 +1401,7 @@ static int asus_ec_probe(struct platform_device *pdev)
 	if (!ec_data)
 		return -ENOMEM;
 
+	ec_data->next_update = INITIAL_JIFFIES;
 	dev_set_drvdata(dev, ec_data);
 	ec_data->board_info = pboard_info;
 
-- 
2.55.0


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

* Re: [PATCH] hwmon: (asus-ec-sensors) fix EC read intervals
  2026-07-12 10:54 [PATCH] hwmon: (asus-ec-sensors) fix EC read intervals Eugene Shalygin
@ 2026-07-12 11:02 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-07-12 11:02 UTC (permalink / raw)
  To: Eugene Shalygin; +Cc: linux-hwmon

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unconditional advancement of the update timestamp masks hardware read errors, causing silent propagation of stale or uninitialized data to userspace.
--

--- Patch [1]: [PATCH] hwmon: (asus-ec-sensors) fix EC read intervals ---
commit 6080114048f396c35a55a9a09a1833289acbf3be
Author: Eugene Shalygin <eugene.shalygin@gmail.com>

hwmon: (asus-ec-sensors) fix EC read intervals

This commit updates the driver to take INITIAL_JIFFIES into account when
setting up the next update time. It changes the last_updated tracker to a
next_update timestamp and advances it by HZ prior to performing hardware
sensor reads.

> diff --git a/drivers/hwmon/asus-ec-sensors.c b/drivers/hwmon/asus-ec-sensors.c
> index 29a23484cbe7b..4746c3718664b 100644
> --- a/drivers/hwmon/asus-ec-sensors.c
> +++ b/drivers/hwmon/asus-ec-sensors.c

[ ... ]

> @@ -1278,13 +1278,12 @@ static int get_cached_value_or_update(const struct device *dev,
>  				      int sensor_index,
>  				      struct ec_sensors_data *state, s32 *value)
>  {
> -	if (time_after(jiffies, state->last_updated + HZ)) {
> +	if (time_after64(get_jiffies_64(), state->next_update)) {
> +		state->next_update = get_jiffies_64() + HZ;
>  		if (update_ec_sensors(dev, state)) {

[Severity: High]
Does unconditional advancement of state->next_update before verifying the
hardware read succeeded cause stale data to be reported to userspace?

If update_ec_sensors() fails (for example, due to ACPI mutex contention
returning -EBUSY), the timestamp remains advanced. Any subsequent attribute
reads within the 1-second timeout window will bypass the update check.

These subsequent reads will successfully return uninitialized (zero) or stale
cached_value data with a return code of 0, potentially disrupting thermal
management policies.

>  			dev_err(dev, "update_ec_sensors() failure\n");
>  			return -EIO;
>  		}
> -
> -		state->last_updated = jiffies;
>  	}
>  
>  	*value = state->sensors[sensor_index].cached_value;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260712105422.920360-1-eugene.shalygin@gmail.com?part=1

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

end of thread, other threads:[~2026-07-12 11:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-12 10:54 [PATCH] hwmon: (asus-ec-sensors) fix EC read intervals Eugene Shalygin
2026-07-12 11:02 ` sashiko-bot

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.