Skip to content

Commit

Permalink
hwmon: (ltc2992) Avoid division by zero
Browse files Browse the repository at this point in the history
[ Upstream commit 10b0290 ]

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.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Link: https://lore.kernel.org/r/20231011135754.13508-1-antoniu.miclaus@analog.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
amiclaus authored and Sasha Levin committed Aug 22, 2024
1 parent 298dafa commit 18b5486
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/hwmon/ltc2992.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 18b5486

Please sign in to comment.