0013-thermal-Use-IS_ENABLED-instead-of-ifdef.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. From bddcae2b66a23bfb6d381d089b0b862235480a9b Mon Sep 17 00:00:00 2001
  2. From: Sascha Hauer <[email protected]>
  3. Date: Wed, 13 May 2015 10:52:32 +0200
  4. Subject: [PATCH 13/76] thermal: Use IS_ENABLED instead of #ifdef
  5. Use IS_ENABLED(CONFIG_THERMAL_EMULATION) to make the code more readable
  6. and to get rid of the addtional #ifdef around the variable definitions
  7. in thermal_zone_get_temp().
  8. Signed-off-by: Sascha Hauer <[email protected]>
  9. ---
  10. drivers/thermal/thermal_core.c | 45 +++++++++++++++++-----------------------
  11. 1 file changed, 19 insertions(+), 26 deletions(-)
  12. --- a/drivers/thermal/thermal_core.c
  13. +++ b/drivers/thermal/thermal_core.c
  14. @@ -417,11 +417,9 @@ static void handle_thermal_trip(struct t
  15. int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
  16. {
  17. int ret = -EINVAL;
  18. -#ifdef CONFIG_THERMAL_EMULATION
  19. int count;
  20. int crit_temp = INT_MAX;
  21. enum thermal_trip_type type;
  22. -#endif
  23. if (!tz || IS_ERR(tz) || !tz->ops->get_temp)
  24. goto exit;
  25. @@ -429,25 +427,21 @@ int thermal_zone_get_temp(struct thermal
  26. mutex_lock(&tz->lock);
  27. ret = tz->ops->get_temp(tz, temp);
  28. -#ifdef CONFIG_THERMAL_EMULATION
  29. - if (!tz->emul_temperature)
  30. - goto skip_emul;
  31. -
  32. - for (count = 0; count < tz->trips; count++) {
  33. - ret = tz->ops->get_trip_type(tz, count, &type);
  34. - if (!ret && type == THERMAL_TRIP_CRITICAL) {
  35. - ret = tz->ops->get_trip_temp(tz, count, &crit_temp);
  36. - break;
  37. - }
  38. - }
  39. - if (ret)
  40. - goto skip_emul;
  41. + if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) {
  42. + for (count = 0; count < tz->trips; count++) {
  43. + ret = tz->ops->get_trip_type(tz, count, &type);
  44. + if (!ret && type == THERMAL_TRIP_CRITICAL) {
  45. + ret = tz->ops->get_trip_temp(tz, count,
  46. + &crit_temp);
  47. + break;
  48. + }
  49. + }
  50. - if (*temp < crit_temp)
  51. - *temp = tz->emul_temperature;
  52. -skip_emul:
  53. -#endif
  54. + if (!ret && *temp < crit_temp)
  55. + *temp = tz->emul_temperature;
  56. + }
  57. +
  58. mutex_unlock(&tz->lock);
  59. exit:
  60. return ret;
  61. @@ -800,7 +794,6 @@ policy_show(struct device *dev, struct d
  62. return sprintf(buf, "%s\n", tz->governor->name);
  63. }
  64. -#ifdef CONFIG_THERMAL_EMULATION
  65. static ssize_t
  66. emul_temp_store(struct device *dev, struct device_attribute *attr,
  67. const char *buf, size_t count)
  68. @@ -826,7 +819,6 @@ emul_temp_store(struct device *dev, stru
  69. return ret ? ret : count;
  70. }
  71. static DEVICE_ATTR(emul_temp, S_IWUSR, NULL, emul_temp_store);
  72. -#endif/*CONFIG_THERMAL_EMULATION*/
  73. static DEVICE_ATTR(type, 0444, type_show, NULL);
  74. static DEVICE_ATTR(temp, 0444, temp_show, NULL);
  75. @@ -1566,11 +1558,12 @@ struct thermal_zone_device *thermal_zone
  76. goto unregister;
  77. }
  78. -#ifdef CONFIG_THERMAL_EMULATION
  79. - result = device_create_file(&tz->device, &dev_attr_emul_temp);
  80. - if (result)
  81. - goto unregister;
  82. -#endif
  83. + if (IS_ENABLED(CONFIG_THERMAL_EMULATION)) {
  84. + result = device_create_file(&tz->device, &dev_attr_emul_temp);
  85. + if (result)
  86. + goto unregister;
  87. + }
  88. +
  89. /* Create policy attribute */
  90. result = device_create_file(&tz->device, &dev_attr_policy);
  91. if (result)