Skip to content

Commit 17e8351

Browse files
saschahauerzhang-rui
authored andcommitted
thermal: consistently use int for temperatures
The thermal code uses int, long and unsigned long for temperatures in different places. Using an unsigned type limits the thermal framework to positive temperatures without need. Also several drivers currently will report temperatures near UINT_MAX for temperatures below 0°C. This will probably immediately shut the machine down due to overtemperature if started below 0°C. 'long' is 64bit on several architectures. This is not needed since INT_MAX °mC is above the melting point of all known materials. Consistently use a plain 'int' for temperatures throughout the thermal code and the drivers. This only changes the places in the drivers where the temperature is passed around as pointer, when drivers internally use another type this is not changed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Acked-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Jean Delvare <jdelvare@suse.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com> Reviewed-by: Darren Hart <dvhart@linux.intel.com> Reviewed-by: Heiko Stuebner <heiko@sntech.de> Reviewed-by: Peter Feuerer <peter@piie.net> Cc: Punit Agrawal <punit.agrawal@arm.com> Cc: Zhang Rui <rui.zhang@intel.com> Cc: Eduardo Valentin <edubezval@gmail.com> Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Jean Delvare <jdelvare@suse.de> Cc: Peter Feuerer <peter@piie.net> Cc: Heiko Stuebner <heiko@sntech.de> Cc: Lukasz Majewski <l.majewski@samsung.com> Cc: Stephen Warren <swarren@wwwdotorg.org> Cc: Thierry Reding <thierry.reding@gmail.com> Cc: linux-acpi@vger.kernel.org Cc: platform-driver-x86@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-omap@vger.kernel.org Cc: linux-samsung-soc@vger.kernel.org Cc: Guenter Roeck <linux@roeck-us.net> Cc: Rafael J. Wysocki <rjw@rjwysocki.net> Cc: Maxime Ripard <maxime.ripard@free-electrons.com> Cc: Darren Hart <dvhart@infradead.org> Cc: lm-sensors@lm-sensors.org Signed-off-by: Zhang Rui <rui.zhang@intel.com>
1 parent 25a0a5c commit 17e8351

39 files changed

+152
-167
lines changed

drivers/acpi/thermal.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,7 @@ static void acpi_thermal_check(void *data)
529529

530530
/* sys I/F for generic thermal sysfs support */
531531

532-
static int thermal_get_temp(struct thermal_zone_device *thermal,
533-
unsigned long *temp)
532+
static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp)
534533
{
535534
struct acpi_thermal *tz = thermal->devdata;
536535
int result;
@@ -637,7 +636,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal,
637636
}
638637

639638
static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
640-
int trip, unsigned long *temp)
639+
int trip, int *temp)
641640
{
642641
struct acpi_thermal *tz = thermal->devdata;
643642
int i;
@@ -690,7 +689,8 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
690689
}
691690

692691
static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
693-
unsigned long *temperature) {
692+
int *temperature)
693+
{
694694
struct acpi_thermal *tz = thermal->devdata;
695695

696696
if (tz->trips.critical.flags.valid) {
@@ -713,8 +713,8 @@ static int thermal_get_trend(struct thermal_zone_device *thermal,
713713
return -EINVAL;
714714

715715
if (type == THERMAL_TRIP_ACTIVE) {
716-
unsigned long trip_temp;
717-
unsigned long temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
716+
int trip_temp;
717+
int temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
718718
tz->temperature, tz->kelvin_offset);
719719
if (thermal_get_trip_temp(thermal, trip, &trip_temp))
720720
return -EINVAL;

drivers/hwmon/lm75.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static inline long lm75_reg_to_mc(s16 temp, u8 resolution)
104104

105105
/* sysfs attributes for hwmon */
106106

107-
static int lm75_read_temp(void *dev, long *temp)
107+
static int lm75_read_temp(void *dev, int *temp)
108108
{
109109
struct lm75_data *data = lm75_update_device(dev);
110110

drivers/hwmon/ntc_thermistor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data)
477477
return -EINVAL;
478478
}
479479

480-
static int ntc_read_temp(void *dev, long *temp)
480+
static int ntc_read_temp(void *dev, int *temp)
481481
{
482482
struct ntc_data *data = dev_get_drvdata(dev);
483483
int ohm;

drivers/hwmon/tmp102.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static struct tmp102 *tmp102_update_device(struct device *dev)
9898
return tmp102;
9999
}
100100

101-
static int tmp102_read_temp(void *dev, long *temp)
101+
static int tmp102_read_temp(void *dev, int *temp)
102102
{
103103
struct tmp102 *tmp102 = tmp102_update_device(dev);
104104

drivers/input/touchscreen/sun4i-ts.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static void sun4i_ts_close(struct input_dev *dev)
191191
writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
192192
}
193193

194-
static int sun4i_get_temp(const struct sun4i_ts_data *ts, long *temp)
194+
static int sun4i_get_temp(const struct sun4i_ts_data *ts, int *temp)
195195
{
196196
/* No temp_data until the first irq */
197197
if (ts->temp_data == -1)
@@ -202,7 +202,7 @@ static int sun4i_get_temp(const struct sun4i_ts_data *ts, long *temp)
202202
return 0;
203203
}
204204

205-
static int sun4i_get_tz_temp(void *data, long *temp)
205+
static int sun4i_get_tz_temp(void *data, int *temp)
206206
{
207207
return sun4i_get_temp(data, temp);
208208
}
@@ -215,14 +215,14 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
215215
char *buf)
216216
{
217217
struct sun4i_ts_data *ts = dev_get_drvdata(dev);
218-
long temp;
218+
int temp;
219219
int error;
220220

221221
error = sun4i_get_temp(ts, &temp);
222222
if (error)
223223
return error;
224224

225-
return sprintf(buf, "%ld\n", temp);
225+
return sprintf(buf, "%d\n", temp);
226226
}
227227

228228
static ssize_t show_temp_label(struct device *dev,

drivers/platform/x86/acerhdf.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,7 @@ static void acerhdf_check_param(struct thermal_zone_device *thermal)
346346
* as late as the polling interval is since we can't do that in the respective
347347
* accessors of the module parameters.
348348
*/
349-
static int acerhdf_get_ec_temp(struct thermal_zone_device *thermal,
350-
unsigned long *t)
349+
static int acerhdf_get_ec_temp(struct thermal_zone_device *thermal, int *t)
351350
{
352351
int temp, err = 0;
353352

@@ -453,7 +452,7 @@ static int acerhdf_get_trip_type(struct thermal_zone_device *thermal, int trip,
453452
}
454453

455454
static int acerhdf_get_trip_hyst(struct thermal_zone_device *thermal, int trip,
456-
unsigned long *temp)
455+
int *temp)
457456
{
458457
if (trip != 0)
459458
return -EINVAL;
@@ -464,7 +463,7 @@ static int acerhdf_get_trip_hyst(struct thermal_zone_device *thermal, int trip,
464463
}
465464

466465
static int acerhdf_get_trip_temp(struct thermal_zone_device *thermal, int trip,
467-
unsigned long *temp)
466+
int *temp)
468467
{
469468
if (trip == 0)
470469
*temp = fanon;
@@ -477,7 +476,7 @@ static int acerhdf_get_trip_temp(struct thermal_zone_device *thermal, int trip,
477476
}
478477

479478
static int acerhdf_get_crit_temp(struct thermal_zone_device *thermal,
480-
unsigned long *temperature)
479+
int *temperature)
481480
{
482481
*temperature = ACERHDF_TEMP_CRIT;
483482
return 0;

drivers/platform/x86/intel_mid_thermal.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static int is_valid_adc(uint16_t adc_val, uint16_t min, uint16_t max)
132132
* to achieve very close approximate temp value with less than
133133
* 0.5C error
134134
*/
135-
static int adc_to_temp(int direct, uint16_t adc_val, unsigned long *tp)
135+
static int adc_to_temp(int direct, uint16_t adc_val, int *tp)
136136
{
137137
int temp;
138138

@@ -174,14 +174,13 @@ static int adc_to_temp(int direct, uint16_t adc_val, unsigned long *tp)
174174
*
175175
* Can sleep
176176
*/
177-
static int mid_read_temp(struct thermal_zone_device *tzd, unsigned long *temp)
177+
static int mid_read_temp(struct thermal_zone_device *tzd, int *temp)
178178
{
179179
struct thermal_device_info *td_info = tzd->devdata;
180180
uint16_t adc_val, addr;
181181
uint8_t data = 0;
182182
int ret;
183-
unsigned long curr_temp;
184-
183+
int curr_temp;
185184

186185
addr = td_info->chnl_addr;
187186

@@ -453,7 +452,7 @@ static SIMPLE_DEV_PM_OPS(mid_thermal_pm,
453452
*
454453
* Can sleep
455454
*/
456-
static int read_curr_temp(struct thermal_zone_device *tzd, unsigned long *temp)
455+
static int read_curr_temp(struct thermal_zone_device *tzd, int *temp)
457456
{
458457
WARN_ON(tzd == NULL);
459458
return mid_read_temp(tzd, temp);

drivers/power/charger-manager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ static int cm_get_battery_temperature(struct charger_manager *cm,
619619

620620
#ifdef CONFIG_THERMAL
621621
if (cm->tzd_batt) {
622-
ret = thermal_zone_get_temp(cm->tzd_batt, (unsigned long *)temp);
622+
ret = thermal_zone_get_temp(cm->tzd_batt, temp);
623623
if (!ret)
624624
/* Calibrate temperature unit */
625625
*temp /= 100;

drivers/power/power_supply_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ EXPORT_SYMBOL_GPL(power_supply_unreg_notifier);
557557

558558
#ifdef CONFIG_THERMAL
559559
static int power_supply_read_temp(struct thermal_zone_device *tzd,
560-
unsigned long *temp)
560+
int *temp)
561561
{
562562
struct power_supply *psy;
563563
union power_supply_propval val;

drivers/thermal/armada_thermal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static bool armada_is_valid(struct armada_thermal_priv *priv)
155155
}
156156

157157
static int armada_get_temp(struct thermal_zone_device *thermal,
158-
unsigned long *temp)
158+
int *temp)
159159
{
160160
struct armada_thermal_priv *priv = thermal->devdata;
161161
unsigned long reg;

drivers/thermal/db8500_thermal.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ static int db8500_cdev_unbind(struct thermal_zone_device *thermal,
107107
}
108108

109109
/* Callback to get current temperature */
110-
static int db8500_sys_get_temp(struct thermal_zone_device *thermal,
111-
unsigned long *temp)
110+
static int db8500_sys_get_temp(struct thermal_zone_device *thermal, int *temp)
112111
{
113112
struct db8500_thermal_zone *pzone = thermal->devdata;
114113

@@ -180,7 +179,7 @@ static int db8500_sys_get_trip_type(struct thermal_zone_device *thermal,
180179

181180
/* Callback to get trip point temperature */
182181
static int db8500_sys_get_trip_temp(struct thermal_zone_device *thermal,
183-
int trip, unsigned long *temp)
182+
int trip, int *temp)
184183
{
185184
struct db8500_thermal_zone *pzone = thermal->devdata;
186185
struct db8500_thsens_platform_data *ptrips = pzone->trip_tab;
@@ -195,7 +194,7 @@ static int db8500_sys_get_trip_temp(struct thermal_zone_device *thermal,
195194

196195
/* Callback to get critical trip point temperature */
197196
static int db8500_sys_get_crit_temp(struct thermal_zone_device *thermal,
198-
unsigned long *temp)
197+
int *temp)
199198
{
200199
struct db8500_thermal_zone *pzone = thermal->devdata;
201200
struct db8500_thsens_platform_data *ptrips = pzone->trip_tab;

drivers/thermal/dove_thermal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static int dove_init_sensor(const struct dove_thermal_priv *priv)
9393
}
9494

9595
static int dove_get_temp(struct thermal_zone_device *thermal,
96-
unsigned long *temp)
96+
int *temp)
9797
{
9898
unsigned long reg;
9999
struct dove_thermal_priv *priv = thermal->devdata;

drivers/thermal/fair_share.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
static int get_trip_level(struct thermal_zone_device *tz)
3535
{
3636
int count = 0;
37-
unsigned long trip_temp;
37+
int trip_temp;
3838
enum thermal_trip_type trip_type;
3939

4040
if (tz->trips == 0 || !tz->ops->get_trip_temp)

drivers/thermal/gov_bang_bang.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525

2626
static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
2727
{
28-
long trip_temp;
29-
unsigned long trip_hyst;
28+
int trip_temp, trip_hyst;
3029
struct thermal_instance *instance;
3130

3231
tz->ops->get_trip_temp(tz, trip, &trip_temp);
3332
tz->ops->get_trip_hyst(tz, trip, &trip_hyst);
3433

35-
dev_dbg(&tz->device, "Trip%d[temp=%ld]:temp=%d:hyst=%ld\n",
34+
dev_dbg(&tz->device, "Trip%d[temp=%d]:temp=%d:hyst=%d\n",
3635
trip, trip_temp, tz->temperature,
3736
trip_hyst);
3837

drivers/thermal/hisi_thermal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data)
155155
mutex_unlock(&data->thermal_lock);
156156
}
157157

158-
static int hisi_thermal_get_temp(void *_sensor, long *temp)
158+
static int hisi_thermal_get_temp(void *_sensor, int *temp)
159159
{
160160
struct hisi_thermal_sensor *sensor = _sensor;
161161
struct hisi_thermal_data *data = sensor->thermal;
@@ -178,7 +178,7 @@ static int hisi_thermal_get_temp(void *_sensor, long *temp)
178178
data->irq_bind_sensor = sensor_id;
179179
mutex_unlock(&data->thermal_lock);
180180

181-
dev_dbg(&data->pdev->dev, "id=%d, irq=%d, temp=%ld, thres=%d\n",
181+
dev_dbg(&data->pdev->dev, "id=%d, irq=%d, temp=%d, thres=%d\n",
182182
sensor->id, data->irq_enabled, *temp, sensor->thres_temp);
183183
/*
184184
* Bind irq to sensor for two cases:

drivers/thermal/imx_thermal.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,18 @@ struct imx_thermal_data {
9898
enum thermal_device_mode mode;
9999
struct regmap *tempmon;
100100
u32 c1, c2; /* See formula in imx_get_sensor_data() */
101-
unsigned long temp_passive;
102-
unsigned long temp_critical;
103-
unsigned long alarm_temp;
104-
unsigned long last_temp;
101+
int temp_passive;
102+
int temp_critical;
103+
int alarm_temp;
104+
int last_temp;
105105
bool irq_enabled;
106106
int irq;
107107
struct clk *thermal_clk;
108108
const struct thermal_soc_data *socdata;
109109
};
110110

111111
static void imx_set_panic_temp(struct imx_thermal_data *data,
112-
signed long panic_temp)
112+
int panic_temp)
113113
{
114114
struct regmap *map = data->tempmon;
115115
int critical_value;
@@ -121,7 +121,7 @@ static void imx_set_panic_temp(struct imx_thermal_data *data,
121121
}
122122

123123
static void imx_set_alarm_temp(struct imx_thermal_data *data,
124-
signed long alarm_temp)
124+
int alarm_temp)
125125
{
126126
struct regmap *map = data->tempmon;
127127
int alarm_value;
@@ -133,7 +133,7 @@ static void imx_set_alarm_temp(struct imx_thermal_data *data,
133133
TEMPSENSE0_ALARM_VALUE_SHIFT);
134134
}
135135

136-
static int imx_get_temp(struct thermal_zone_device *tz, unsigned long *temp)
136+
static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
137137
{
138138
struct imx_thermal_data *data = tz->devdata;
139139
struct regmap *map = data->tempmon;
@@ -189,13 +189,13 @@ static int imx_get_temp(struct thermal_zone_device *tz, unsigned long *temp)
189189
if (data->alarm_temp == data->temp_critical &&
190190
*temp < data->temp_passive) {
191191
imx_set_alarm_temp(data, data->temp_passive);
192-
dev_dbg(&tz->device, "thermal alarm off: T < %lu\n",
192+
dev_dbg(&tz->device, "thermal alarm off: T < %d\n",
193193
data->alarm_temp / 1000);
194194
}
195195
}
196196

197197
if (*temp != data->last_temp) {
198-
dev_dbg(&tz->device, "millicelsius: %ld\n", *temp);
198+
dev_dbg(&tz->device, "millicelsius: %d\n", *temp);
199199
data->last_temp = *temp;
200200
}
201201

@@ -262,8 +262,7 @@ static int imx_get_trip_type(struct thermal_zone_device *tz, int trip,
262262
return 0;
263263
}
264264

265-
static int imx_get_crit_temp(struct thermal_zone_device *tz,
266-
unsigned long *temp)
265+
static int imx_get_crit_temp(struct thermal_zone_device *tz, int *temp)
267266
{
268267
struct imx_thermal_data *data = tz->devdata;
269268

@@ -272,7 +271,7 @@ static int imx_get_crit_temp(struct thermal_zone_device *tz,
272271
}
273272

274273
static int imx_get_trip_temp(struct thermal_zone_device *tz, int trip,
275-
unsigned long *temp)
274+
int *temp)
276275
{
277276
struct imx_thermal_data *data = tz->devdata;
278277

@@ -282,7 +281,7 @@ static int imx_get_trip_temp(struct thermal_zone_device *tz, int trip,
282281
}
283282

284283
static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip,
285-
unsigned long temp)
284+
int temp)
286285
{
287286
struct imx_thermal_data *data = tz->devdata;
288287

@@ -434,7 +433,7 @@ static irqreturn_t imx_thermal_alarm_irq_thread(int irq, void *dev)
434433
{
435434
struct imx_thermal_data *data = dev;
436435

437-
dev_dbg(&data->tz->device, "THERMAL ALARM: T > %lu\n",
436+
dev_dbg(&data->tz->device, "THERMAL ALARM: T > %d\n",
438437
data->alarm_temp / 1000);
439438

440439
thermal_zone_device_update(data->tz);

drivers/thermal/int340x_thermal/int3400_thermal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ static int int3400_thermal_run_osc(acpi_handle handle,
186186
}
187187

188188
static int int3400_thermal_get_temp(struct thermal_zone_device *thermal,
189-
unsigned long *temp)
189+
int *temp)
190190
{
191191
*temp = 20 * 1000; /* faked temp sensor with 20C */
192192
return 0;

0 commit comments

Comments
 (0)