Skip to content

Commit fb44721

Browse files
andy-shevgroeck
authored andcommitted
hwmon: (ina233) 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. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20260219141532.2259642-1-andriy.shevchenko@linux.intel.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 7735390 commit fb44721

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

drivers/hwmon/pmbus/ina233.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static int ina233_read_word_data(struct i2c_client *client, int page,
8585
static int ina233_probe(struct i2c_client *client)
8686
{
8787
struct device *dev = &client->dev;
88+
const char *propname;
8889
int ret, m, R;
8990
u32 rshunt;
9091
u32 max_current;
@@ -114,27 +115,28 @@ static int ina233_probe(struct i2c_client *client)
114115

115116
/* If INA233 skips current/power, shunt-resistor and current-lsb aren't needed. */
116117
/* read rshunt value (uOhm) */
117-
ret = device_property_read_u32(dev, "shunt-resistor", &rshunt);
118-
if (ret) {
119-
if (ret != -EINVAL)
120-
return dev_err_probe(dev, ret, "Shunt resistor property read fail.\n");
118+
propname = "shunt-resistor";
119+
if (device_property_present(dev, propname)) {
120+
ret = device_property_read_u32(dev, propname, &rshunt);
121+
if (ret)
122+
return dev_err_probe(dev, ret, "%s property read fail.\n", propname);
123+
} else {
121124
rshunt = INA233_RSHUNT_DEFAULT;
122125
}
123126
if (!rshunt)
124-
return dev_err_probe(dev, -EINVAL,
125-
"Shunt resistor cannot be zero.\n");
127+
return dev_err_probe(dev, -EINVAL, "%s cannot be zero.\n", propname);
126128

127129
/* read Maximum expected current value (uA) */
128-
ret = device_property_read_u32(dev, "ti,maximum-expected-current-microamp", &max_current);
129-
if (ret) {
130-
if (ret != -EINVAL)
131-
return dev_err_probe(dev, ret,
132-
"Maximum expected current property read fail.\n");
130+
propname = "ti,maximum-expected-current-microamp";
131+
if (device_property_present(dev, propname)) {
132+
ret = device_property_read_u32(dev, propname, &max_current);
133+
if (ret)
134+
return dev_err_probe(dev, ret, "%s property read fail.\n", propname);
135+
} else {
133136
max_current = INA233_MAX_CURRENT_DEFAULT;
134137
}
135138
if (max_current < 32768)
136-
return dev_err_probe(dev, -EINVAL,
137-
"Maximum expected current cannot less then 32768.\n");
139+
return dev_err_probe(dev, -EINVAL, "%s cannot be less than 32768.\n", propname);
138140

139141
/* Calculate Current_LSB according to the spec formula */
140142
current_lsb = max_current / 32768;

0 commit comments

Comments
 (0)