Skip to content

Commit 44e3ad8

Browse files
mitagroeck
authored andcommitted
hwmon: Reduce indentation level in __hwmon_device_register()
Reduce indentation level in __hwmon_device_register() by preparing a helper function. This just improves code readability. No functional change. Cc: Jean Delvare <[email protected]> Cc: Guenter Roeck <[email protected]> Signed-off-by: Akinobu Mita <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent 5a56a39 commit 44e3ad8

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

drivers/hwmon/hwmon.c

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,40 @@ static int hwmon_thermal_add_sensor(struct device *dev, int index)
179179

180180
return 0;
181181
}
182+
183+
static int hwmon_thermal_register_sensors(struct device *dev)
184+
{
185+
struct hwmon_device *hwdev = to_hwmon_device(dev);
186+
const struct hwmon_chip_info *chip = hwdev->chip;
187+
const struct hwmon_channel_info **info = chip->info;
188+
void *drvdata = dev_get_drvdata(dev);
189+
int i;
190+
191+
for (i = 1; info[i]; i++) {
192+
int j;
193+
194+
if (info[i]->type != hwmon_temp)
195+
continue;
196+
197+
for (j = 0; info[i]->config[j]; j++) {
198+
int err;
199+
200+
if (!(info[i]->config[j] & HWMON_T_INPUT) ||
201+
!chip->ops->is_visible(drvdata, hwmon_temp,
202+
hwmon_temp_input, j))
203+
continue;
204+
205+
err = hwmon_thermal_add_sensor(dev, j);
206+
if (err)
207+
return err;
208+
}
209+
}
210+
211+
return 0;
212+
}
213+
182214
#else
183-
static int hwmon_thermal_add_sensor(struct device *dev, int index)
215+
static int hwmon_thermal_register_sensors(struct device *dev)
184216
{
185217
return 0;
186218
}
@@ -596,7 +628,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
596628
{
597629
struct hwmon_device *hwdev;
598630
struct device *hdev;
599-
int i, j, err, id;
631+
int i, err, id;
600632

601633
/* Complain about invalid characters in hwmon name attribute */
602634
if (name && (!strlen(name) || strpbrk(name, "-* \t\n")))
@@ -664,30 +696,14 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
664696
if (dev && dev->of_node && chip && chip->ops->read &&
665697
chip->info[0]->type == hwmon_chip &&
666698
(chip->info[0]->config[0] & HWMON_C_REGISTER_TZ)) {
667-
const struct hwmon_channel_info **info = chip->info;
668-
669-
for (i = 1; info[i]; i++) {
670-
if (info[i]->type != hwmon_temp)
671-
continue;
672-
673-
for (j = 0; info[i]->config[j]; j++) {
674-
if (!chip->ops->is_visible(drvdata, hwmon_temp,
675-
hwmon_temp_input, j))
676-
continue;
677-
if (info[i]->config[j] & HWMON_T_INPUT) {
678-
err = hwmon_thermal_add_sensor(hdev, j);
679-
if (err) {
680-
device_unregister(hdev);
681-
/*
682-
* Don't worry about hwdev;
683-
* hwmon_dev_release(), called
684-
* from device_unregister(),
685-
* will free it.
686-
*/
687-
goto ida_remove;
688-
}
689-
}
690-
}
699+
err = hwmon_thermal_register_sensors(hdev);
700+
if (err) {
701+
device_unregister(hdev);
702+
/*
703+
* Don't worry about hwdev; hwmon_dev_release(), called
704+
* from device_unregister(), will free it.
705+
*/
706+
goto ida_remove;
691707
}
692708
}
693709

0 commit comments

Comments
 (0)