Skip to contentSkip to conversation

drivers: hwmon: ltc2992: avoid division by zero

PATCH Applied Antoniu Miclaus 2 participants 2 messages Oct 11, 2023 – Oct 25, 2023 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: hwmon: ltc2992: avoid division by zero

Do not allow setting shunt resistor to 0. This results in a division by zero when performing current value computations based on input voltages and connected resistor values.

---
 drivers/hwmon/ltc2992.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/hwmon/ltc2992.c +5 -1
index 589bcd07ce7f..001799bc28ed 100644
@@ -875,8 +875,12 @@ static int ltc2992_parse_dt(struct ltc2992_state *st)
 		}
 
 		ret = fwnode_property_read_u32(child, "shunt-resistor-micro-ohms", &val);
-		if (!ret)
+		if (!ret) {
+			if (!val)
+				return dev_err_probe(&st->client->dev, -EINVAL,
+						     "shunt resistor value cannot be zero\n");
 			st->r_sense_uohm[addr] = val;
+		}
 	}
 
 	return 0;
Signature · 1 line
2.42.0
maintainer Applied
#1 lore raw
Quoted 5 lines · Antoniu Miclaus

Do not allow setting shunt resistor to 0. This results in a division by zero when performing current value computations based on input voltages and connected resistor values.

Applied. Please note that the subject should not include "drivers:".

Guenter