public inbox for linux-hwmon@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] hwmon: (isl28022) Don't check for specific errors when parsing properties
@ 2026-02-19 14:05 Andy Shevchenko
  2026-02-19 14:21 ` Geert Uytterhoeven
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2026-02-19 14:05 UTC (permalink / raw)
  To: Andy Shevchenko, linux-hwmon, linux-kernel, linux-renesas-soc
  Cc: Carsten Spieß, Guenter Roeck, Geert Uytterhoeven,
	Magnus Damm

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>
---
 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-17 21:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-19 14:05 [PATCH v1 1/1] hwmon: (isl28022) Don't check for specific errors when parsing properties Andy Shevchenko
2026-02-19 14:21 ` Geert Uytterhoeven
2026-02-19 14:30   ` Andy Shevchenko
2026-02-20 20:49     ` Guenter Roeck
2026-03-17 20:51       ` Andy Shevchenko
2026-03-17 21:09   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox