]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
hwmon: adm1275: Detect coefficient overflow
authorMatti Vaittinen <mazziesaccount@gmail.com>
Fri, 26 Jun 2026 07:23:58 +0000 (10:23 +0300)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 29 Jun 2026 20:46:10 +0000 (13:46 -0700)
Sashiko detected potential coefficient overflow if large shunt resistor
is used. When going unnoticed it can cause "drastically incorrect
telemetry scaling factors" as Sashiko put it.

I am not convinced such "drastically incorrect telemetry scaling
factors" could have gone unnoticed, so I suspect such large shunt
resistors aren't really used. Well, it shouldn't hurt to detect the
error and abort the probe before Really Wrong current / power -values
are reported to user by the hwmon.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Link: https://lore.kernel.org/r/d9e3320dbd62e094ff89598cb3aac5b5e716f9e7.1782458224.git.mazziesaccount@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/pmbus/adm1275.c

index cf7790bef652dca8974221b605cf5b10dfef4ee5..d3c3ff85dba33b332abdbfb4164e5a8a85852917 100644 (file)
@@ -839,15 +839,25 @@ static int adm1275_probe(struct i2c_client *client)
                info->R[PSC_VOLTAGE_OUT] = coefficients[voindex].R;
        }
        if (cindex >= 0) {
+               u32 m;
+
                /* Scale current with sense resistor value */
-               info->m[PSC_CURRENT_OUT] =
-                       coefficients[cindex].m * shunt / 1000;
+               if (unlikely(check_mul_overflow(coefficients[cindex].m, shunt, &m))) {
+                       dev_err(&client->dev, "Current coefficient overflow\n");
+                       return -EOVERFLOW;
+               }
+               info->m[PSC_CURRENT_OUT] = m / 1000;
                info->b[PSC_CURRENT_OUT] = coefficients[cindex].b;
                info->R[PSC_CURRENT_OUT] = coefficients[cindex].R;
        }
        if (pindex >= 0) {
-               info->m[PSC_POWER] =
-                       coefficients[pindex].m * shunt / 1000;
+               u32 m;
+
+               if (unlikely(check_mul_overflow(coefficients[pindex].m, shunt, &m))) {
+                       dev_err(&client->dev, "Power coefficient overflow\n");
+                       return -EOVERFLOW;
+               }
+               info->m[PSC_POWER] = m / 1000;
                info->b[PSC_POWER] = coefficients[pindex].b;
                info->R[PSC_POWER] = coefficients[pindex].R;
        }