]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hwmon: (isl28022) Don't check for specific errors when parsing properties
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 19 Feb 2026 14:05:32 +0000 (15:05 +0100)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 12 Apr 2026 14:24:59 +0000 (07:24 -0700)
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>
drivers/hwmon/isl28022.c

index c5a34ceedcdb2832602e297c0a93b60009f18a32..96fcfbfff48f4c98e8675c67cea1901e9be6bc21 100644 (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;