FAILED: patch "[PATCH] hwmon: (aquacomputer_d5next) Avoid truncating scaled sensor readings" failed to apply to 6.1-stable tree
Sasha Levin
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x c221091f7e30c64280e4cbfa27dc4c05edc96d0c
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From c221091f7e30c64280e4cbfa27dc4c05edc96d0c Mon Sep 17 00:00:00 2001
From: Vas Zayarskiy <[email protected]>
Date: Sun, 27 Sep 2026 22:13:12 +0300
Subject: [PATCH] hwmon: (aquacomputer_d5next) Avoid truncating scaled sensor
readings
High Flow Next power is reported in watts. Multiplying the 16-bit value by one million can overflow both the signed intermediate and the u32 cache. Store power in long, perform the conversion in u64, and clamp to LONG_MAX. The other existing power conversions fit in a signed 32-bit value. Return -ENODATA for unavailable power instead of exposing the stored error as a reading.
The power cache is updated by HID reports without the hwmon read mutex. Read it once with READ_ONCE() and use that snapshot for both the availability check and the returned value. Mark the corresponding updates with WRITE_ONCE() so that the shared accesses are explicit.
Widen the shared current cache to u32. The Aquastream XT conversion to milliamperes can exceed 65535 mA; clamp its negative conversion results to zero before assigning to the unsigned cache. This also permits devices with scaled aggregate currents to store milliamperes directly.
--- drivers/hwmon/aquacomputer_d5next.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
drivers/hwmon/aquacomputer_d5next.c +18 -11
@@ -19,6 +19,7 @@#include <linux/hwmon.h> #include <linux/jiffies.h> #include <linux/ktime.h> +#include <linux/limits.h> #include <linux/module.h> #include <linux/seq_file.h> #include <linux/unaligned.h>
@@ -612,9 +613,9 @@ struct aqc_data {u32 speed_input_min[1 ];u32 speed_input_target[1 ];u32 speed_input_max[1 ]; -u32 power_input[8 ]; +long power_input[8 ];u16 voltage_input[8 ]; -u16 current_input[8 ]; +u32 current_input[8 ];/* Label values */ const char *const *temp_label;
@@ -989,7 +990,7 @@ static int aqc_legacy_read(struct aqc_data *priv)/* Calculation derived from linear regression */ sensor_value =get_unaligned_le16 (priv->buffer +AQUASTREAMXT_PUMP_CURR_OFFSET ); - priv->current_input[0 ] =DIV_ROUND_CLOSEST (sensor_value *176 ,100 ) -52 ; + priv->current_input[0 ] =max (DIV_ROUND_CLOSEST (sensor_value *176 ,100 ) -52 ,0 ); sensor_value =get_unaligned_le16 (priv->buffer +AQUASTREAMXT_PUMP_VOLTAGE_OFFSET ); priv->voltage_input[0 ] =DIV_ROUND_CLOSEST (sensor_value *1000 ,61 );
@@ -1019,6 +1020,7 @@ static int aqc_legacy_read(struct aqc_data *priv)static int aqc_read (struct device *dev,enum hwmon_sensor_types type,u32 attr,int channel,long *val) { +long power;int ret;struct aqc_data *priv =dev_get_drvdata (dev);
@@ -1083,7 +1085,10 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, }break ;case hwmon_power: - *val = priv->power_input[channel]; + power =READ_ONCE (priv->power_input[channel]); +if (power == -ENODATA ) +return -ENODATA ; + *val = power;break ;case hwmon_pwm:switch (priv->kind) {
@@ -1383,9 +1388,9 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8 priv->speed_input[i] =get_unaligned_be16 (data + priv->fan_sensor_offsets[i] + priv->fan_structure->speed); - priv->power_input[i] = -get_unaligned_be16 (data + priv->fan_sensor_offsets[i] + - priv->fan_structure->power) *10000 ; +WRITE_ONCE (priv->power_input[i], +get_unaligned_be16 (data + priv->fan_sensor_offsets[i] + + priv->fan_structure->power) *10000 ); priv->voltage_input[i] =get_unaligned_be16 (data + priv->fan_sensor_offsets[i] + priv->fan_structure->voltage) *10 ;
@@ -1425,7 +1430,8 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8 priv->speed_input[2 ] =get_unaligned_be16 (data +AQUASTREAMULT_PRESSURE_OFFSET ); priv->speed_input[3 ] =get_unaligned_be16 (data +AQUASTREAMULT_FLOW_SENSOR_OFFSET ); - priv->power_input[1 ] =get_unaligned_be16 (data +AQUASTREAMULT_PUMP_POWER ) *10000 ; +WRITE_ONCE (priv->power_input[1 ], +get_unaligned_be16 (data +AQUASTREAMULT_PUMP_POWER ) *10000 ); priv->voltage_input[1 ] =get_unaligned_be16 (data +AQUASTREAMULT_PUMP_VOLTAGE ) *10 ;
@@ -1438,10 +1444,11 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8case highflownext:/* If external temp sensor is not connected, its power reading is also N/A */ if (priv->temp_input[1 ] == -ENODATA ) - priv->power_input[0 ] = -ENODATA ; +WRITE_ONCE (priv->power_input[0 ], -ENODATA );else - priv->power_input[0 ] = -get_unaligned_be16 (data +HIGHFLOWNEXT_POWER ) *1000000 ; +WRITE_ONCE (priv->power_input[0 ], +min_t (u64,get_unaligned_be16 (data +HIGHFLOWNEXT_POWER ) * +1000000ULL ,LONG_MAX )); priv->voltage_input[0 ] =get_unaligned_be16 (data +HIGHFLOWNEXT_5V_VOLTAGE ) *10 ; priv->voltage_input[1] =
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 hwmon: (aquacomputer_d5next) Avoid truncating scaled sensor readings
From: Vas Zayarskiy <[email protected]>
[ Upstream commit c221091f7e30c64280e4cbfa27dc4c05edc96d0c ]
High Flow Next power is reported in watts. Multiplying the 16-bit value by one million can overflow both the signed intermediate and the u32 cache. Store power in long, perform the conversion in u64, and clamp to LONG_MAX. The other existing power conversions fit in a signed 32-bit value. Return -ENODATA for unavailable power instead of exposing the stored error as a reading.
The power cache is updated by HID reports without the hwmon read mutex. Read it once with READ_ONCE() and use that snapshot for both the availability check and the returned value. Mark the corresponding updates with WRITE_ONCE() so that the shared accesses are explicit.
Widen the shared current cache to u32. The Aquastream XT conversion to milliamperes can exceed 65535 mA; clamp its negative conversion results to zero before assigning to the unsigned cache. This also permits devices with scaled aggregate currents to store milliamperes directly.
--- drivers/hwmon/aquacomputer_d5next.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/hwmon/aquacomputer_d5next.c +15 -9
@@ -17,6 +17,7 @@#include <linux/hwmon.h> #include <linux/jiffies.h> #include <linux/ktime.h> +#include <linux/limits.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/seq_file.h>
@@ -302,9 +303,9 @@ struct aqc_data {/* Sensor values */ s32 temp_input[20 ];/* Max 4 physical and 16 virtual */ u16 speed_input[8 ]; -u32 power_input[8 ]; +long power_input[8 ];u16 voltage_input[8 ]; -u16 current_input[8 ]; +u32 current_input[8 ];/* Label values */ const char *const *temp_label;
@@ -515,6 +516,7 @@ static umode_t aqc_is_visible(const void *data, enum hwmon_sensor_types type, u3static int aqc_read (struct device *dev,enum hwmon_sensor_types type,u32 attr,int channel,long *val) { +long power;int ret;struct aqc_data *priv =dev_get_drvdata (dev);
@@ -532,7 +534,10 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, *val = priv->speed_input[channel];break ;case hwmon_power: - *val = priv->power_input[channel]; + power =READ_ONCE (priv->power_input[channel]); +if (power == -ENODATA ) +return -ENODATA ; + *val = power;break ;case hwmon_pwm:if (priv->fan_ctrl_offsets) {
@@ -743,9 +748,9 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8for (i =0 ; i < priv->num_fans; i++) { priv->speed_input[i] =get_unaligned_be16 (data + priv->fan_sensor_offsets[i] +AQC_FAN_SPEED_OFFSET ); - priv->power_input[i] = -get_unaligned_be16 (data + priv->fan_sensor_offsets[i] + -AQC_FAN_POWER_OFFSET ) *10000 ; +WRITE_ONCE (priv->power_input[i], +get_unaligned_be16 (data + priv->fan_sensor_offsets[i] + +AQC_FAN_POWER_OFFSET ) *10000 ); priv->voltage_input[i] =get_unaligned_be16 (data + priv->fan_sensor_offsets[i] +AQC_FAN_VOLTAGE_OFFSET ) *10 ;
@@ -768,10 +773,11 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8case highflownext:/* If external temp sensor is not connected, its power reading is also N/A */ if (priv->temp_input[1 ] == -ENODATA ) - priv->power_input[0 ] = -ENODATA ; +WRITE_ONCE (priv->power_input[0 ], -ENODATA );else - priv->power_input[0 ] = -get_unaligned_be16 (data +HIGHFLOWNEXT_POWER ) *1000000 ; +WRITE_ONCE (priv->power_input[0 ], +min_t (u64,get_unaligned_be16 (data +HIGHFLOWNEXT_POWER ) * +1000000ULL ,LONG_MAX )); priv->voltage_input[0 ] =get_unaligned_be16 (data +HIGHFLOWNEXT_5V_VOLTAGE ) *10 ; priv->voltage_input[1] =
Signature · 1 line
2.53.0