Skip to content

Commit 4d2ffc4

Browse files
t-8chgroeck
authored andcommitted
hwmon: (core) Avoid ifdef CONFIG_THERMAL in C source file
Using an #ifdef in a C source files to have different definitions of the same symbol makes the code harder to read and understand. Furthermore it makes it harder to test compilation of the different branches. Replace the ifdeffery with IS_ENABLED() which is just a normal conditional. The resulting binary is still the same as before as the compiler optimizes away all the unused code and definitions. Signed-off-by: Thomas Weißschuh <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent 868dc3c commit 4d2ffc4

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

drivers/hwmon/hwmon.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,6 @@ static umode_t hwmon_is_visible(const struct hwmon_ops *ops,
158158

159159
/* Thermal zone handling */
160160

161-
/*
162-
* The complex conditional is necessary to avoid a cyclic dependency
163-
* between hwmon and thermal_sys modules.
164-
*/
165-
#ifdef CONFIG_THERMAL_OF
166161
static int hwmon_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
167162
{
168163
struct hwmon_thermal_data *tdata = thermal_zone_device_priv(tz);
@@ -268,6 +263,9 @@ static int hwmon_thermal_register_sensors(struct device *dev)
268263
void *drvdata = dev_get_drvdata(dev);
269264
int i;
270265

266+
if (!IS_ENABLED(CONFIG_THERMAL_OF))
267+
return 0;
268+
271269
for (i = 1; info[i]; i++) {
272270
int j;
273271

@@ -296,6 +294,9 @@ static void hwmon_thermal_notify(struct device *dev, int index)
296294
struct hwmon_device *hwdev = to_hwmon_device(dev);
297295
struct hwmon_thermal_data *tzdata;
298296

297+
if (!IS_ENABLED(CONFIG_THERMAL_OF))
298+
return;
299+
299300
list_for_each_entry(tzdata, &hwdev->tzdata, node) {
300301
if (tzdata->index == index) {
301302
thermal_zone_device_update(tzdata->tzd,
@@ -304,16 +305,6 @@ static void hwmon_thermal_notify(struct device *dev, int index)
304305
}
305306
}
306307

307-
#else
308-
static int hwmon_thermal_register_sensors(struct device *dev)
309-
{
310-
return 0;
311-
}
312-
313-
static void hwmon_thermal_notify(struct device *dev, int index) { }
314-
315-
#endif /* IS_REACHABLE(CONFIG_THERMAL) && ... */
316-
317308
static int hwmon_attr_base(enum hwmon_sensor_types type)
318309
{
319310
if (type == hwmon_in || type == hwmon_intrusion)

0 commit comments

Comments
 (0)