Skip to content

Commit

Permalink
thermal: consistently use int for temperatures
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
saschahauer authored and zhang-rui committed Aug 3, 2015
1 parent 25a0a5c commit 17e8351
Show file tree
Hide file tree
Showing 39 changed files with 152 additions and 167 deletions.
12 changes: 6 additions & 6 deletions drivers/acpi/thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,7 @@ static void acpi_thermal_check(void *data)

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

static int thermal_get_temp(struct thermal_zone_device *thermal,
unsigned long *temp)
static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp)
{
struct acpi_thermal *tz = thermal->devdata;
int result;
Expand Down Expand Up @@ -637,7 +636,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal,
}

static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
int trip, unsigned long *temp)
int trip, int *temp)
{
struct acpi_thermal *tz = thermal->devdata;
int i;
Expand Down Expand Up @@ -690,7 +689,8 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
}

static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
unsigned long *temperature) {
int *temperature)
{
struct acpi_thermal *tz = thermal->devdata;

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

if (type == THERMAL_TRIP_ACTIVE) {
unsigned long trip_temp;
unsigned long temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
int trip_temp;
int temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
tz->temperature, tz->kelvin_offset);
if (thermal_get_trip_temp(thermal, trip, &trip_temp))
return -EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion drivers/hwmon/lm75.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static inline long lm75_reg_to_mc(s16 temp, u8 resolution)

/* sysfs attributes for hwmon */

static int lm75_read_temp(void *dev, long *temp)
static int lm75_read_temp(void *dev, int *temp)
{
struct lm75_data *data = lm75_update_device(dev);

Expand Down
2 changes: 1 addition & 1 deletion drivers/hwmon/ntc_thermistor.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data)
return -EINVAL;
}

static int ntc_read_temp(void *dev, long *temp)
static int ntc_read_temp(void *dev, int *temp)
{
struct ntc_data *data = dev_get_drvdata(dev);
int ohm;
Expand Down
2 changes: 1 addition & 1 deletion drivers/hwmon/tmp102.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static struct tmp102 *tmp102_update_device(struct device *dev)
return tmp102;
}

static int tmp102_read_temp(void *dev, long *temp)
static int tmp102_read_temp(void *dev, int *temp)
{
struct tmp102 *tmp102 = tmp102_update_device(dev);

Expand Down
8 changes: 4 additions & 4 deletions drivers/input/touchscreen/sun4i-ts.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static void sun4i_ts_close(struct input_dev *dev)
writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
}

static int sun4i_get_temp(const struct sun4i_ts_data *ts, long *temp)
static int sun4i_get_temp(const struct sun4i_ts_data *ts, int *temp)
{
/* No temp_data until the first irq */
if (ts->temp_data == -1)
Expand All @@ -202,7 +202,7 @@ static int sun4i_get_temp(const struct sun4i_ts_data *ts, long *temp)
return 0;
}

static int sun4i_get_tz_temp(void *data, long *temp)
static int sun4i_get_tz_temp(void *data, int *temp)
{
return sun4i_get_temp(data, temp);
}
Expand All @@ -215,14 +215,14 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
char *buf)
{
struct sun4i_ts_data *ts = dev_get_drvdata(dev);
long temp;
int temp;
int error;

error = sun4i_get_temp(ts, &temp);
if (error)
return error;

return sprintf(buf, "%ld\n", temp);
return sprintf(buf, "%d\n", temp);
}

static ssize_t show_temp_label(struct device *dev,
Expand Down
9 changes: 4 additions & 5 deletions drivers/platform/x86/acerhdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ static void acerhdf_check_param(struct thermal_zone_device *thermal)
* as late as the polling interval is since we can't do that in the respective
* accessors of the module parameters.
*/
static int acerhdf_get_ec_temp(struct thermal_zone_device *thermal,
unsigned long *t)
static int acerhdf_get_ec_temp(struct thermal_zone_device *thermal, int *t)
{
int temp, err = 0;

Expand Down Expand Up @@ -453,7 +452,7 @@ static int acerhdf_get_trip_type(struct thermal_zone_device *thermal, int trip,
}

static int acerhdf_get_trip_hyst(struct thermal_zone_device *thermal, int trip,
unsigned long *temp)
int *temp)
{
if (trip != 0)
return -EINVAL;
Expand All @@ -464,7 +463,7 @@ static int acerhdf_get_trip_hyst(struct thermal_zone_device *thermal, int trip,
}

static int acerhdf_get_trip_temp(struct thermal_zone_device *thermal, int trip,
unsigned long *temp)
int *temp)
{
if (trip == 0)
*temp = fanon;
Expand All @@ -477,7 +476,7 @@ static int acerhdf_get_trip_temp(struct thermal_zone_device *thermal, int trip,
}

static int acerhdf_get_crit_temp(struct thermal_zone_device *thermal,
unsigned long *temperature)
int *temperature)
{
*temperature = ACERHDF_TEMP_CRIT;
return 0;
Expand Down
9 changes: 4 additions & 5 deletions drivers/platform/x86/intel_mid_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static int is_valid_adc(uint16_t adc_val, uint16_t min, uint16_t max)
* to achieve very close approximate temp value with less than
* 0.5C error
*/
static int adc_to_temp(int direct, uint16_t adc_val, unsigned long *tp)
static int adc_to_temp(int direct, uint16_t adc_val, int *tp)
{
int temp;

Expand Down Expand Up @@ -174,14 +174,13 @@ static int adc_to_temp(int direct, uint16_t adc_val, unsigned long *tp)
*
* Can sleep
*/
static int mid_read_temp(struct thermal_zone_device *tzd, unsigned long *temp)
static int mid_read_temp(struct thermal_zone_device *tzd, int *temp)
{
struct thermal_device_info *td_info = tzd->devdata;
uint16_t adc_val, addr;
uint8_t data = 0;
int ret;
unsigned long curr_temp;

int curr_temp;

addr = td_info->chnl_addr;

Expand Down Expand Up @@ -453,7 +452,7 @@ static SIMPLE_DEV_PM_OPS(mid_thermal_pm,
*
* Can sleep
*/
static int read_curr_temp(struct thermal_zone_device *tzd, unsigned long *temp)
static int read_curr_temp(struct thermal_zone_device *tzd, int *temp)
{
WARN_ON(tzd == NULL);
return mid_read_temp(tzd, temp);
Expand Down
2 changes: 1 addition & 1 deletion drivers/power/charger-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ static int cm_get_battery_temperature(struct charger_manager *cm,

#ifdef CONFIG_THERMAL
if (cm->tzd_batt) {
ret = thermal_zone_get_temp(cm->tzd_batt, (unsigned long *)temp);
ret = thermal_zone_get_temp(cm->tzd_batt, temp);
if (!ret)
/* Calibrate temperature unit */
*temp /= 100;
Expand Down
2 changes: 1 addition & 1 deletion drivers/power/power_supply_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ EXPORT_SYMBOL_GPL(power_supply_unreg_notifier);

#ifdef CONFIG_THERMAL
static int power_supply_read_temp(struct thermal_zone_device *tzd,
unsigned long *temp)
int *temp)
{
struct power_supply *psy;
union power_supply_propval val;
Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/armada_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static bool armada_is_valid(struct armada_thermal_priv *priv)
}

static int armada_get_temp(struct thermal_zone_device *thermal,
unsigned long *temp)
int *temp)
{
struct armada_thermal_priv *priv = thermal->devdata;
unsigned long reg;
Expand Down
7 changes: 3 additions & 4 deletions drivers/thermal/db8500_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ static int db8500_cdev_unbind(struct thermal_zone_device *thermal,
}

/* Callback to get current temperature */
static int db8500_sys_get_temp(struct thermal_zone_device *thermal,
unsigned long *temp)
static int db8500_sys_get_temp(struct thermal_zone_device *thermal, int *temp)
{
struct db8500_thermal_zone *pzone = thermal->devdata;

Expand Down Expand Up @@ -180,7 +179,7 @@ static int db8500_sys_get_trip_type(struct thermal_zone_device *thermal,

/* Callback to get trip point temperature */
static int db8500_sys_get_trip_temp(struct thermal_zone_device *thermal,
int trip, unsigned long *temp)
int trip, int *temp)
{
struct db8500_thermal_zone *pzone = thermal->devdata;
struct db8500_thsens_platform_data *ptrips = pzone->trip_tab;
Expand All @@ -195,7 +194,7 @@ static int db8500_sys_get_trip_temp(struct thermal_zone_device *thermal,

/* Callback to get critical trip point temperature */
static int db8500_sys_get_crit_temp(struct thermal_zone_device *thermal,
unsigned long *temp)
int *temp)
{
struct db8500_thermal_zone *pzone = thermal->devdata;
struct db8500_thsens_platform_data *ptrips = pzone->trip_tab;
Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/dove_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static int dove_init_sensor(const struct dove_thermal_priv *priv)
}

static int dove_get_temp(struct thermal_zone_device *thermal,
unsigned long *temp)
int *temp)
{
unsigned long reg;
struct dove_thermal_priv *priv = thermal->devdata;
Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/fair_share.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
static int get_trip_level(struct thermal_zone_device *tz)
{
int count = 0;
unsigned long trip_temp;
int trip_temp;
enum thermal_trip_type trip_type;

if (tz->trips == 0 || !tz->ops->get_trip_temp)
Expand Down
5 changes: 2 additions & 3 deletions drivers/thermal/gov_bang_bang.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@

static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
{
long trip_temp;
unsigned long trip_hyst;
int trip_temp, trip_hyst;
struct thermal_instance *instance;

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

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

Expand Down
4 changes: 2 additions & 2 deletions drivers/thermal/hisi_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data)
mutex_unlock(&data->thermal_lock);
}

static int hisi_thermal_get_temp(void *_sensor, long *temp)
static int hisi_thermal_get_temp(void *_sensor, int *temp)
{
struct hisi_thermal_sensor *sensor = _sensor;
struct hisi_thermal_data *data = sensor->thermal;
Expand All @@ -178,7 +178,7 @@ static int hisi_thermal_get_temp(void *_sensor, long *temp)
data->irq_bind_sensor = sensor_id;
mutex_unlock(&data->thermal_lock);

dev_dbg(&data->pdev->dev, "id=%d, irq=%d, temp=%ld, thres=%d\n",
dev_dbg(&data->pdev->dev, "id=%d, irq=%d, temp=%d, thres=%d\n",
sensor->id, data->irq_enabled, *temp, sensor->thres_temp);
/*
* Bind irq to sensor for two cases:
Expand Down
27 changes: 13 additions & 14 deletions drivers/thermal/imx_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ struct imx_thermal_data {
enum thermal_device_mode mode;
struct regmap *tempmon;
u32 c1, c2; /* See formula in imx_get_sensor_data() */
unsigned long temp_passive;
unsigned long temp_critical;
unsigned long alarm_temp;
unsigned long last_temp;
int temp_passive;
int temp_critical;
int alarm_temp;
int last_temp;
bool irq_enabled;
int irq;
struct clk *thermal_clk;
const struct thermal_soc_data *socdata;
};

static void imx_set_panic_temp(struct imx_thermal_data *data,
signed long panic_temp)
int panic_temp)
{
struct regmap *map = data->tempmon;
int critical_value;
Expand All @@ -121,7 +121,7 @@ static void imx_set_panic_temp(struct imx_thermal_data *data,
}

static void imx_set_alarm_temp(struct imx_thermal_data *data,
signed long alarm_temp)
int alarm_temp)
{
struct regmap *map = data->tempmon;
int alarm_value;
Expand All @@ -133,7 +133,7 @@ static void imx_set_alarm_temp(struct imx_thermal_data *data,
TEMPSENSE0_ALARM_VALUE_SHIFT);
}

static int imx_get_temp(struct thermal_zone_device *tz, unsigned long *temp)
static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
{
struct imx_thermal_data *data = tz->devdata;
struct regmap *map = data->tempmon;
Expand Down Expand Up @@ -189,13 +189,13 @@ static int imx_get_temp(struct thermal_zone_device *tz, unsigned long *temp)
if (data->alarm_temp == data->temp_critical &&
*temp < data->temp_passive) {
imx_set_alarm_temp(data, data->temp_passive);
dev_dbg(&tz->device, "thermal alarm off: T < %lu\n",
dev_dbg(&tz->device, "thermal alarm off: T < %d\n",
data->alarm_temp / 1000);
}
}

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

Expand Down Expand Up @@ -262,8 +262,7 @@ static int imx_get_trip_type(struct thermal_zone_device *tz, int trip,
return 0;
}

static int imx_get_crit_temp(struct thermal_zone_device *tz,
unsigned long *temp)
static int imx_get_crit_temp(struct thermal_zone_device *tz, int *temp)
{
struct imx_thermal_data *data = tz->devdata;

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

static int imx_get_trip_temp(struct thermal_zone_device *tz, int trip,
unsigned long *temp)
int *temp)
{
struct imx_thermal_data *data = tz->devdata;

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

static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip,
unsigned long temp)
int temp)
{
struct imx_thermal_data *data = tz->devdata;

Expand Down Expand Up @@ -434,7 +433,7 @@ static irqreturn_t imx_thermal_alarm_irq_thread(int irq, void *dev)
{
struct imx_thermal_data *data = dev;

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

thermal_zone_device_update(data->tz);
Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/int340x_thermal/int3400_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static int int3400_thermal_run_osc(acpi_handle handle,
}

static int int3400_thermal_get_temp(struct thermal_zone_device *thermal,
unsigned long *temp)
int *temp)
{
*temp = 20 * 1000; /* faked temp sensor with 20C */
return 0;
Expand Down
Loading

0 comments on commit 17e8351

Please sign in to comment.