mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drivers: hwmon: ltc2992: avoid division by zero
@ 2023-10-11 13:57 Antoniu Miclaus
  2023-10-25 19:38 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Antoniu Miclaus @ 2023-10-11 13:57 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, linux-hwmon, linux-kernel; +Cc: 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.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
 drivers/hwmon/ltc2992.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/ltc2992.c b/drivers/hwmon/ltc2992.c
index 589bcd07ce7f..001799bc28ed 100644
--- a/drivers/hwmon/ltc2992.c
+++ b/drivers/hwmon/ltc2992.c
@@ -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;
-- 
2.42.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] drivers: hwmon: ltc2992: avoid division by zero
  2023-10-11 13:57 [PATCH] drivers: hwmon: ltc2992: avoid division by zero Antoniu Miclaus
@ 2023-10-25 19:38 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2023-10-25 19:38 UTC (permalink / raw)
  To: Antoniu Miclaus; +Cc: Jean Delvare, linux-hwmon, linux-kernel

On Wed, Oct 11, 2023 at 04:57:53PM +0300, Antoniu Miclaus wrote:
> 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>

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

Guenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-25 19:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-11 13:57 [PATCH] drivers: hwmon: ltc2992: avoid division by zero Antoniu Miclaus
2023-10-25 19:38 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®