mirror of
https://github.com/torvalds/linux.git
synced 2024-11-13 07:31:45 +00:00
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>
This commit is contained in:
parent
8b9bf554dd
commit
a6e43263ed
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user