Skip to content

Commit 82b1ec7

Browse files
sumeetpawnikarrafaeljw
authored andcommitted
thermal: core: Increase maximum number of trip points
On one of the Chrome system, if we define more than 12 trip points, probe for thermal sensor fails with "int3403 thermal: probe of INTC1046:03 failed with error -22" and throws an error as "thermal_sys: Error: Incorrect number of thermal trips". The thermal_zone_device_register() interface needs maximum number of trip points supported in a zone as an argument. This number can't exceed THERMAL_MAX_TRIPS, which is currently set to 12. To address this issue, THERMAL_MAX_TRIPS value has to be increased. This interface also has an argument to specify a mask of trips which are writable. This mask is defined as an int. This mask sets the ceiling for increasing maximum number of supported trips. With the current implementation, maximum number of trips can be supported is 31. Also, THERMAL_MAX_TRIPS macro is used in one place only. So, remove THERMAL_MAX_TRIPS macro and compare num_trips directly with using a macro BITS_PER_TYPE(int)-1. Signed-off-by: Sumeet Pawnikar <sumeet.r.pawnikar@intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 1e6c8fb commit 82b1ec7

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

drivers/thermal/thermal_core.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,20 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
11921192
return ERR_PTR(-EINVAL);
11931193
}
11941194

1195-
if (num_trips > THERMAL_MAX_TRIPS || num_trips < 0 || mask >> num_trips) {
1195+
/*
1196+
* Max trip count can't exceed 31 as the "mask >> num_trips" condition.
1197+
* For example, shifting by 32 will result in compiler warning:
1198+
* warning: right shift count >= width of type [-Wshift-count- overflow]
1199+
*
1200+
* Also "mask >> num_trips" will always be true with 32 bit shift.
1201+
* E.g. mask = 0x80000000 for trip id 31 to be RW. Then
1202+
* mask >> 32 = 0x80000000
1203+
* This will result in failure for the below condition.
1204+
*
1205+
* Check will be true when the bit 31 of the mask is set.
1206+
* 32 bit shift will cause overflow of 4 byte integer.
1207+
*/
1208+
if (num_trips > (BITS_PER_TYPE(int) - 1) || num_trips < 0 || mask >> num_trips) {
11961209
pr_err("Incorrect number of thermal trips\n");
11971210
return ERR_PTR(-EINVAL);
11981211
}

include/linux/thermal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include <linux/workqueue.h>
1818
#include <uapi/linux/thermal.h>
1919

20-
#define THERMAL_MAX_TRIPS 12
21-
2220
/* invalid cooling state */
2321
#define THERMAL_CSTATE_INVALID -1UL
2422

0 commit comments

Comments
 (0)