0018-thermal-of-always-set-sensor-related-callbacks.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. From 8c9c4ed500e92c10dc4965dcd00692b3102a328a Mon Sep 17 00:00:00 2001
  2. From: Sascha Hauer <[email protected]>
  3. Date: Wed, 13 May 2015 10:52:37 +0200
  4. Subject: [PATCH 18/76] thermal: of: always set sensor related callbacks
  5. Now that the thermal core treats -ENOSYS like the callbacks were
  6. not present at all we no longer have to overwrite the ops during
  7. runtime but instead can always set them and return -ENOSYS if no
  8. sensor is registered.
  9. Signed-off-by: Sascha Hauer <[email protected]>
  10. ---
  11. drivers/thermal/of-thermal.c | 33 +++++++++++++--------------------
  12. 1 file changed, 13 insertions(+), 20 deletions(-)
  13. --- a/drivers/thermal/of-thermal.c
  14. +++ b/drivers/thermal/of-thermal.c
  15. @@ -91,7 +91,7 @@ static int of_thermal_get_temp(struct th
  16. {
  17. struct __thermal_zone *data = tz->devdata;
  18. - if (!data->ops->get_temp)
  19. + if (!data->ops)
  20. return -EINVAL;
  21. return data->ops->get_temp(data->sensor_data, temp);
  22. @@ -178,7 +178,7 @@ static int of_thermal_set_emul_temp(stru
  23. struct __thermal_zone *data = tz->devdata;
  24. if (!data->ops || !data->ops->set_emul_temp)
  25. - return -EINVAL;
  26. + return -ENOSYS;
  27. return data->ops->set_emul_temp(data->sensor_data, temp);
  28. }
  29. @@ -189,8 +189,8 @@ static int of_thermal_get_trend(struct t
  30. struct __thermal_zone *data = tz->devdata;
  31. int r;
  32. - if (!data->ops->get_trend)
  33. - return -EINVAL;
  34. + if (!data->ops || !data->ops->get_trend)
  35. + return -ENOSYS;
  36. r = data->ops->get_trend(data->sensor_data, trip, trend);
  37. if (r)
  38. @@ -366,6 +366,10 @@ static int of_thermal_get_crit_temp(stru
  39. }
  40. static struct thermal_zone_device_ops of_thermal_ops = {
  41. + .get_temp = of_thermal_get_temp,
  42. + .get_trend = of_thermal_get_trend,
  43. + .set_emul_temp = of_thermal_set_emul_temp,
  44. +
  45. .get_mode = of_thermal_get_mode,
  46. .set_mode = of_thermal_set_mode,
  47. @@ -399,13 +403,13 @@ thermal_zone_of_add_sensor(struct device
  48. if (!ops)
  49. return ERR_PTR(-EINVAL);
  50. + if (!ops->get_temp)
  51. + return ERR_PTR(-EINVAL);
  52. +
  53. mutex_lock(&tzd->lock);
  54. tz->ops = ops;
  55. tz->sensor_data = data;
  56. - tzd->ops->get_temp = of_thermal_get_temp;
  57. - tzd->ops->get_trend = of_thermal_get_trend;
  58. - tzd->ops->set_emul_temp = of_thermal_set_emul_temp;
  59. mutex_unlock(&tzd->lock);
  60. return tzd;
  61. @@ -535,9 +539,6 @@ void thermal_zone_of_sensor_unregister(s
  62. return;
  63. mutex_lock(&tzd->lock);
  64. - tzd->ops->get_temp = NULL;
  65. - tzd->ops->get_trend = NULL;
  66. - tzd->ops->set_emul_temp = NULL;
  67. tz->ops = NULL;
  68. tz->sensor_data = NULL;
  69. @@ -845,7 +846,6 @@ int __init of_parse_thermal_zones(void)
  70. {
  71. struct device_node *np, *child;
  72. struct __thermal_zone *tz;
  73. - struct thermal_zone_device_ops *ops;
  74. np = of_find_node_by_name(NULL, "thermal-zones");
  75. if (!np) {
  76. @@ -869,29 +869,22 @@ int __init of_parse_thermal_zones(void)
  77. continue;
  78. }
  79. - ops = kmemdup(&of_thermal_ops, sizeof(*ops), GFP_KERNEL);
  80. - if (!ops)
  81. - goto exit_free;
  82. -
  83. tzp = kzalloc(sizeof(*tzp), GFP_KERNEL);
  84. - if (!tzp) {
  85. - kfree(ops);
  86. + if (!tzp)
  87. goto exit_free;
  88. - }
  89. /* No hwmon because there might be hwmon drivers registering */
  90. tzp->no_hwmon = true;
  91. zone = thermal_zone_device_register(child->name, tz->ntrips,
  92. 0, tz,
  93. - ops, tzp,
  94. + &of_thermal_ops, tzp,
  95. tz->passive_delay,
  96. tz->polling_delay);
  97. if (IS_ERR(zone)) {
  98. pr_err("Failed to build %s zone %ld\n", child->name,
  99. PTR_ERR(zone));
  100. kfree(tzp);
  101. - kfree(ops);
  102. of_thermal_free_zone(tz);
  103. /* attempting to build remaining zones still */
  104. }