Skip to contentSkip to conversation

hwmon: (pmbus/tps25990) Don't check for specific errors when parsing properties

PATCH Applied Andy Shevchenko 2 participants 2 messages Feb 19 – Apr 12

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (pmbus/tps25990) 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.

---
 drivers/hwmon/pmbus/tps25990.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/hwmon/pmbus/tps25990.c +10 -4
index c13edd7e1abf..05c6288ecafc 100644
@@ -402,12 +402,18 @@ static int tps25990_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
 	struct pmbus_driver_info *info;
-	u32 rimon = TPS25990_DEFAULT_RIMON;
+	const char *propname;
+	u32 rimon;
 	int ret;
 
-	ret = device_property_read_u32(dev, "ti,rimon-micro-ohms", &rimon);
-	if (ret < 0 && ret != -EINVAL)
-		return dev_err_probe(dev, ret, "failed to get rimon\n");
+	propname = "ti,rimon-micro-ohms";
+	if (device_property_present(dev, propname)) {
+		ret = device_property_read_u32(dev, propname, &rimon);
+		if (ret)
+			return dev_err_probe(dev, ret, "failed to get %s\n", propname);
+	} else {
+		rimon = TPS25990_DEFAULT_RIMON;
+	}
 
 	info = devm_kmemdup(dev, &tps25990_base_info, sizeof(*info), GFP_KERNEL);
 	if (!info)
Signature · 1 line
2.50.1
maintainer Applied
#1 lore raw
Quoted 5 lines · Andy Shevchenko

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.

Applied.

Thanks,
Guenter

Quoted 31 lines
---
 drivers/hwmon/pmbus/tps25990.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/hwmon/pmbus/tps25990.c +10 -4
index c13edd7e1abf..05c6288ecafc 100644
@@ -402,12 +402,18 @@ static int tps25990_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
 	struct pmbus_driver_info *info;
-	u32 rimon = TPS25990_DEFAULT_RIMON;
+	const char *propname;
+	u32 rimon;
 	int ret;
 
-	ret = device_property_read_u32(dev, "ti,rimon-micro-ohms", &rimon);
-	if (ret < 0 && ret != -EINVAL)
-		return dev_err_probe(dev, ret, "failed to get rimon\n");
+	propname = "ti,rimon-micro-ohms";
+	if (device_property_present(dev, propname)) {
+		ret = device_property_read_u32(dev, propname, &rimon);
+		if (ret)
+			return dev_err_probe(dev, ret, "failed to get %s\n", propname);
+	} else {
+		rimon = TPS25990_DEFAULT_RIMON;
+	}
 
 	info = devm_kmemdup(dev, &tps25990_base_info, sizeof(*info), GFP_KERNEL);
 	if (!info)