Skip to content

Commit 79e5421

Browse files
saschahauerzhang-rui
authored andcommitted
thermal: Use IS_ENABLED instead of #ifdef
Use IS_ENABLED(CONFIG_THERMAL_EMULATION) to make the code more readable and to get rid of the addtional #ifdef around the variable definitions in thermal_zone_get_temp(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
1 parent dbdf253 commit 79e5421

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

drivers/thermal/thermal_core.c

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -477,37 +477,31 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
477477
int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
478478
{
479479
int ret = -EINVAL;
480-
#ifdef CONFIG_THERMAL_EMULATION
481480
int count;
482481
int crit_temp = INT_MAX;
483482
enum thermal_trip_type type;
484-
#endif
485483

486484
if (!tz || IS_ERR(tz) || !tz->ops->get_temp)
487485
goto exit;
488486

489487
mutex_lock(&tz->lock);
490488

491489
ret = tz->ops->get_temp(tz, temp);
492-
#ifdef CONFIG_THERMAL_EMULATION
493-
if (!tz->emul_temperature)
494-
goto skip_emul;
495-
496-
for (count = 0; count < tz->trips; count++) {
497-
ret = tz->ops->get_trip_type(tz, count, &type);
498-
if (!ret && type == THERMAL_TRIP_CRITICAL) {
499-
ret = tz->ops->get_trip_temp(tz, count, &crit_temp);
500-
break;
501-
}
502-
}
503490

504-
if (ret)
505-
goto skip_emul;
491+
if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) {
492+
for (count = 0; count < tz->trips; count++) {
493+
ret = tz->ops->get_trip_type(tz, count, &type);
494+
if (!ret && type == THERMAL_TRIP_CRITICAL) {
495+
ret = tz->ops->get_trip_temp(tz, count,
496+
&crit_temp);
497+
break;
498+
}
499+
}
506500

507-
if (*temp < crit_temp)
508-
*temp = tz->emul_temperature;
509-
skip_emul:
510-
#endif
501+
if (!ret && *temp < crit_temp)
502+
*temp = tz->emul_temperature;
503+
}
504+
511505
mutex_unlock(&tz->lock);
512506
exit:
513507
return ret;
@@ -866,7 +860,6 @@ available_policies_show(struct device *dev, struct device_attribute *devattr,
866860
return count;
867861
}
868862

869-
#ifdef CONFIG_THERMAL_EMULATION
870863
static ssize_t
871864
emul_temp_store(struct device *dev, struct device_attribute *attr,
872865
const char *buf, size_t count)
@@ -892,7 +885,6 @@ emul_temp_store(struct device *dev, struct device_attribute *attr,
892885
return ret ? ret : count;
893886
}
894887
static DEVICE_ATTR(emul_temp, S_IWUSR, NULL, emul_temp_store);
895-
#endif/*CONFIG_THERMAL_EMULATION*/
896888

897889
static ssize_t
898890
sustainable_power_show(struct device *dev, struct device_attribute *devattr,
@@ -1822,11 +1814,12 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
18221814
goto unregister;
18231815
}
18241816

1825-
#ifdef CONFIG_THERMAL_EMULATION
1826-
result = device_create_file(&tz->device, &dev_attr_emul_temp);
1827-
if (result)
1828-
goto unregister;
1829-
#endif
1817+
if (IS_ENABLED(CONFIG_THERMAL_EMULATION)) {
1818+
result = device_create_file(&tz->device, &dev_attr_emul_temp);
1819+
if (result)
1820+
goto unregister;
1821+
}
1822+
18301823
/* Create policy attribute */
18311824
result = device_create_file(&tz->device, &dev_attr_policy);
18321825
if (result)

0 commit comments

Comments
 (0)