0017-thermal-Allow-sensor-ops-to-fail-with-ENOSYS.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. From 5b622cb2d6ff44b1fb0750beee61f93f2c00548a Mon Sep 17 00:00:00 2001
  2. From: Sascha Hauer <[email protected]>
  3. Date: Wed, 13 May 2015 10:52:36 +0200
  4. Subject: [PATCH 17/76] thermal: Allow sensor ops to fail with -ENOSYS
  5. The thermal core uses the existence of the .get_temp, .get_trend and
  6. .set_emul_temp to detect whether this operation exists and should be
  7. used or whether it should be emulated in software. This makes problems
  8. for of-thermal which has to modify the struct thermal_zone_device_ops
  9. during runtime whenever a sensor is registered or unregistered.
  10. Let the core test for -ENOSYS from these callbacks and treat it like
  11. if the callbacks were not present.
  12. This allows of-thermal to always set the sensor related callbacks and
  13. to make struct thermal_zone_device_ops const again.
  14. Signed-off-by: Sascha Hauer <[email protected]>
  15. ---
  16. drivers/thermal/thermal_core.c | 24 +++++++++++++++++-------
  17. 1 file changed, 17 insertions(+), 7 deletions(-)
  18. --- a/drivers/thermal/thermal_core.c
  19. +++ b/drivers/thermal/thermal_core.c
  20. @@ -416,13 +416,16 @@ static void handle_thermal_trip(struct t
  21. */
  22. int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
  23. {
  24. - int ret = -EINVAL;
  25. + int ret;
  26. int count;
  27. int crit_temp = INT_MAX;
  28. enum thermal_trip_type type;
  29. - if (!tz || IS_ERR(tz) || !tz->ops->get_temp)
  30. - goto exit;
  31. + if (!tz || IS_ERR(tz))
  32. + return -EINVAL;
  33. +
  34. + if (!tz->ops->get_temp)
  35. + return -ENOSYS;
  36. mutex_lock(&tz->lock);
  37. @@ -448,7 +451,7 @@ int thermal_zone_get_temp(struct thermal
  38. }
  39. mutex_unlock(&tz->lock);
  40. -exit:
  41. +
  42. return ret;
  43. }
  44. EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
  45. @@ -460,10 +463,11 @@ void thermal_zone_device_update(struct t
  46. if (atomic_read(&in_suspend))
  47. return;
  48. - if (!tz->ops->get_temp)
  49. + ret = thermal_zone_get_temp(tz, &temp);
  50. +
  51. + if (ret == -ENOSYS)
  52. return;
  53. - ret = thermal_zone_get_temp(tz, &temp);
  54. if (ret) {
  55. if (ret != -EAGAIN)
  56. dev_warn(&tz->device,
  57. @@ -803,10 +807,16 @@ emul_temp_store(struct device *dev, stru
  58. if (kstrtoul(buf, 10, &temperature))
  59. return -EINVAL;
  60. - if (!tz->ops->set_emul_temp) {
  61. + if (tz->ops->set_emul_temp)
  62. + ret = tz->ops->set_emul_temp(tz, temperature);
  63. + else
  64. + ret = -ENOSYS;
  65. +
  66. + if (ret == -ENOSYS) {
  67. mutex_lock(&tz->lock);
  68. tz->emul_temperature = temperature;
  69. mutex_unlock(&tz->lock);
  70. + ret = 0;
  71. } else {
  72. ret = tz->ops->set_emul_temp(tz, temperature);
  73. }