mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 1/1] hwmon: (ina233) Don't check for specific errors when parsing properties
@ 2026-02-19 14:15 Andy Shevchenko
  2026-04-12 14:26 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2026-02-19 14:15 UTC (permalink / raw)
  To: Leo Yang, Andy Shevchenko, linux-hwmon, linux-kernel; +Cc: Guenter Roeck

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/pmbus/ina233.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/drivers/hwmon/pmbus/ina233.c b/drivers/hwmon/pmbus/ina233.c
index dde1e1678394..6ee1bce32755 100644
--- a/drivers/hwmon/pmbus/ina233.c
+++ b/drivers/hwmon/pmbus/ina233.c
@@ -82,6 +82,7 @@ static int ina233_read_word_data(struct i2c_client *client, int page,
 static int ina233_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
+	const char *propname;
 	int ret, m, R;
 	u32 rshunt;
 	u32 max_current;
@@ -111,27 +112,28 @@ static int ina233_probe(struct i2c_client *client)
 
 	/* If INA233 skips current/power, shunt-resistor and current-lsb aren't needed.	*/
 	/* read rshunt value (uOhm) */
-	ret = device_property_read_u32(dev, "shunt-resistor", &rshunt);
-	if (ret) {
-		if (ret != -EINVAL)
-			return dev_err_probe(dev, ret, "Shunt resistor property read fail.\n");
+	propname = "shunt-resistor";
+	if (device_property_present(dev, propname)) {
+		ret = device_property_read_u32(dev, propname, &rshunt);
+		if (ret)
+			return dev_err_probe(dev, ret, "%s property read fail.\n", propname);
+	} else {
 		rshunt = INA233_RSHUNT_DEFAULT;
 	}
 	if (!rshunt)
-		return dev_err_probe(dev, -EINVAL,
-				     "Shunt resistor cannot be zero.\n");
+		return dev_err_probe(dev, -EINVAL, "%s cannot be zero.\n", propname);
 
 	/* read Maximum expected current value (uA) */
-	ret = device_property_read_u32(dev, "ti,maximum-expected-current-microamp", &max_current);
-	if (ret) {
-		if (ret != -EINVAL)
-			return dev_err_probe(dev, ret,
-					     "Maximum expected current property read fail.\n");
+	propname = "ti,maximum-expected-current-microamp";
+	if (device_property_present(dev, propname)) {
+		ret = device_property_read_u32(dev, propname, &max_current);
+		if (ret)
+			return dev_err_probe(dev, ret, "%s property read fail.\n", propname);
+	} else {
 		max_current = INA233_MAX_CURRENT_DEFAULT;
 	}
 	if (max_current < 32768)
-		return dev_err_probe(dev, -EINVAL,
-				     "Maximum expected current cannot less then 32768.\n");
+		return dev_err_probe(dev, -EINVAL, "%s cannot be less than 32768.\n", propname);
 
 	/* Calculate Current_LSB according to the spec formula */
 	current_lsb = max_current / 32768;
-- 
2.50.1


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

* Re: [PATCH v1 1/1] hwmon: (ina233) Don't check for specific errors when parsing properties
  2026-02-19 14:15 [PATCH v1 1/1] hwmon: (ina233) Don't check for specific errors when parsing properties Andy Shevchenko
@ 2026-04-12 14:26 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2026-04-12 14:26 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Leo Yang, linux-hwmon, linux-kernel

On Thu, Feb 19, 2026 at 03:15:32PM +0100, Andy Shevchenko wrote:
> 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>

Applied.

Thanks,
Guenter

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

end of thread, other threads:[~2026-04-12 14:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-19 14:15 [PATCH v1 1/1] hwmon: (ina233) Don't check for specific errors when parsing properties Andy Shevchenko
2026-04-12 14:26 ` Guenter Roeck

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

all inboxes | Powered by JetHome®