hwmon: (isl28022) Don't check for specific errors when parsing properties

Instead of checking for the specific error codes (that can be considered
a layering violation to some extent) check for the property existence first
and then either parse it, or apply a default value.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20260219140532.2259235-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
Andy Shevchenko
2026-04-12 07:24:59 -07:00
committed by Guenter Roeck
parent a69ae329d4
commit 77353904e1
+24 -18
View File
@@ -338,21 +338,28 @@ DEFINE_SHOW_ATTRIBUTE(shunt_voltage);
*/
static int isl28022_read_properties(struct device *dev, struct isl28022_data *data)
{
const char *propname;
u32 val;
int err;
err = device_property_read_u32(dev, "shunt-resistor-micro-ohms", &val);
if (err == -EINVAL)
propname = "shunt-resistor-micro-ohms";
if (device_property_present(dev, propname)) {
err = device_property_read_u32(dev, propname, &val);
if (err)
return err;
} else {
val = 10000;
else if (err < 0)
return err;
}
data->shunt = val;
err = device_property_read_u32(dev, "renesas,shunt-range-microvolt", &val);
if (err == -EINVAL)
propname = "renesas,shunt-range-microvolt";
if (device_property_present(dev, propname)) {
err = device_property_read_u32(dev, propname, &val);
if (err)
return err;
} else {
val = 320000;
else if (err < 0)
return err;
}
switch (val) {
case 40000:
@@ -376,20 +383,19 @@ static int isl28022_read_properties(struct device *dev, struct isl28022_data *da
goto shunt_invalid;
break;
default:
return dev_err_probe(dev, -EINVAL,
"renesas,shunt-range-microvolt invalid value %d\n",
val);
return dev_err_probe(dev, -EINVAL, "%s invalid value %u\n", propname, val);
}
err = device_property_read_u32(dev, "renesas,average-samples", &val);
if (err == -EINVAL)
propname = "renesas,average-samples";
if (device_property_present(dev, propname)) {
err = device_property_read_u32(dev, propname, &val);
if (err)
return err;
} else {
val = 1;
else if (err < 0)
return err;
}
if (val > 128 || hweight32(val) != 1)
return dev_err_probe(dev, -EINVAL,
"renesas,average-samples invalid value %d\n",
val);
return dev_err_probe(dev, -EINVAL, "%s invalid value %u\n", propname, val);
data->average = val;