[PATCH v1 1/1] hwmon: (isl28022) Don't check for specific errors when parsing properties

From: Andy Shevchenko

Date: Thu Feb 19 2026 - 09:06:47 EST


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@xxxxxxxxxxxxxxx>
---
drivers/hwmon/isl28022.c | 42 +++++++++++++++++++++++-----------------
1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/drivers/hwmon/isl28022.c b/drivers/hwmon/isl28022.c
index c2e559dde63f..c69ff4a46525 100644
--- a/drivers/hwmon/isl28022.c
+++ b/drivers/hwmon/isl28022.c
@@ -337,21 +337,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:
@@ -375,20 +382,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;

--
2.50.1