Skip to contentSkip to conversation

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

PATCH Superseded Eugene Shalygin 2 participants 2 messages Jul 12

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Eugene Shalygin

author maintainer
#0 lore raw

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

Take INITIAL_JIFFIES into account when setting up next update time.

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(-)
drivers/hwmon/asus-ec-sensors.c +4 -4
index 29a23484cbe7..4746c3718664 100644
@@ -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;
 
Signature · 1 line
2.55.0
#1 lore raw
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…

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 <[email protected]>

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.

Quoted 4 lines
drivers/hwmon/asus-ec-sensors.c +0 -0
index 29a23484cbe7b..4746c3718664b 100644

[ ... ]

drivers/hwmon/asus-ec-sensors.c static int get_cached_value_or_update(const struct device *dev, · line 1283

Quoted 8 lines
drivers/hwmon/asus-ec-sensors.c +2 -1
@@ -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.

Quoted 8 lines
drivers/hwmon/asus-ec-sensors.c +0 -2
 			dev_err(dev, "update_ec_sensors() failure\n");
 			return -EIO;
 		}
-
-		state->last_updated = jiffies;
 	}
 
 	*value = state->sensors[sensor_index].cached_value;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1