summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorNicolin Chen <nicoleotsuka@gmail.com>2018-10-08 23:24:51 +0200
committerGuenter Roeck <linux@roeck-us.net>2018-10-11 05:37:13 +0200
commita6e43263ed01fa617e0a0c13ea8a5f1538573380 (patch)
tree2081d1c550cdda7732cad817df32c34277274339 /drivers/hwmon
parenthwmon: (tmp421) make const array 'names' static (diff)
downloadlinux-a6e43263ed01fa617e0a0c13ea8a5f1538573380.tar.xz
linux-a6e43263ed01fa617e0a0c13ea8a5f1538573380.zip
hwmon: (ina3221) Validate shunt resistor value from DT
The input->shunt_resistor is int type while the value from DT is unsigned int. Meanwhile, a divide-by-zero error would happen if the value is 0. So this patch just simply validates the value. Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/ina3221.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
index c3a497aed345..4f3ed24efe8e 100644
--- a/drivers/hwmon/ina3221.c
+++ b/drivers/hwmon/ina3221.c
@@ -536,8 +536,14 @@ static int ina3221_probe_child_from_dt(struct device *dev,
of_property_read_string(child, "label", &input->label);
/* Overwrite default shunt resistor value optionally */
- if (!of_property_read_u32(child, "shunt-resistor-micro-ohms", &val))
+ if (!of_property_read_u32(child, "shunt-resistor-micro-ohms", &val)) {
+ if (val < 1 || val > INT_MAX) {
+ dev_err(dev, "invalid shunt resistor value %u of %s\n",
+ val, child->name);
+ return -EINVAL;
+ }
input->shunt_resistor = val;
+ }
return 0;
}