mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
hwmon: adm1275: Detect coefficient overflow
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>
This commit is contained in:
parent
553f951781
commit
72a6910103
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user