Skip to content

Commit df98976

Browse files
andy-shevgroeck
authored andcommitted
hwmon: (tmp513) Simplify with dev_err_probe()
Common pattern of handling deferred probe can be simplified with dev_err_probe(). Less code and also it prints the error value. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] [groeck: Fixed excessive line length] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 5d9ad4e commit df98976

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

drivers/hwmon/tmp513.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,9 @@ static int tmp51x_vbus_range_to_reg(struct device *dev,
630630
} else if (data->vbus_range_uvolt == TMP51X_VBUS_RANGE_16V) {
631631
data->shunt_config &= ~TMP51X_BUS_VOLTAGE_MASK;
632632
} else {
633-
dev_err(dev, "ti,bus-range-microvolt is invalid: %u\n",
634-
data->vbus_range_uvolt);
635-
return -EINVAL;
633+
return dev_err_probe(dev, -EINVAL,
634+
"ti,bus-range-microvolt is invalid: %u\n",
635+
data->vbus_range_uvolt);
636636
}
637637
return 0;
638638
}
@@ -648,8 +648,8 @@ static int tmp51x_pga_gain_to_reg(struct device *dev, struct tmp51x_data *data)
648648
} else if (data->pga_gain == 1) {
649649
data->shunt_config |= CURRENT_SENSE_VOLTAGE_40_MASK;
650650
} else {
651-
dev_err(dev, "ti,pga-gain is invalid: %u\n", data->pga_gain);
652-
return -EINVAL;
651+
return dev_err_probe(dev, -EINVAL,
652+
"ti,pga-gain is invalid: %u\n", data->pga_gain);
653653
}
654654
return 0;
655655
}
@@ -679,9 +679,9 @@ static int tmp51x_read_properties(struct device *dev, struct tmp51x_data *data)
679679

680680
// Check if shunt value is compatible with pga-gain
681681
if (data->shunt_uohms > data->pga_gain * 40 * 1000 * 1000) {
682-
dev_err(dev, "shunt-resistor: %u too big for pga_gain: %u\n",
683-
data->shunt_uohms, data->pga_gain);
684-
return -EINVAL;
682+
return dev_err_probe(dev, -EINVAL,
683+
"shunt-resistor: %u too big for pga_gain: %u\n",
684+
data->shunt_uohms, data->pga_gain);
685685
}
686686

687687
return 0;
@@ -721,22 +721,17 @@ static int tmp51x_probe(struct i2c_client *client)
721721
data->max_channels = (uintptr_t)i2c_get_match_data(client);
722722

723723
ret = tmp51x_configure(dev, data);
724-
if (ret < 0) {
725-
dev_err(dev, "error configuring the device: %d\n", ret);
726-
return ret;
727-
}
724+
if (ret < 0)
725+
return dev_err_probe(dev, ret, "error configuring the device\n");
728726

729727
data->regmap = devm_regmap_init_i2c(client, &tmp51x_regmap_config);
730-
if (IS_ERR(data->regmap)) {
731-
dev_err(dev, "failed to allocate register map\n");
732-
return PTR_ERR(data->regmap);
733-
}
728+
if (IS_ERR(data->regmap))
729+
return dev_err_probe(dev, PTR_ERR(data->regmap),
730+
"failed to allocate register map\n");
734731

735732
ret = tmp51x_init(data);
736-
if (ret < 0) {
737-
dev_err(dev, "error configuring the device: %d\n", ret);
738-
return -ENODEV;
739-
}
733+
if (ret < 0)
734+
return dev_err_probe(dev, ret, "error configuring the device\n");
740735

741736
hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
742737
data,

0 commit comments

Comments
 (0)