Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17e8351a authored by Sascha Hauer's avatar Sascha Hauer Committed by Zhang Rui
Browse files

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: default avatarSascha Hauer <s.hauer@pengutronix.de>
Acked-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: default avatarJean Delvare <jdelvare@suse.de>
Reviewed-by: default avatarLukasz Majewski <l.majewski@samsung.com>
Reviewed-by: default avatarDarren Hart <dvhart@linux.intel.com>
Reviewed-by: default avatarHeiko Stuebner <heiko@sntech.de>
Reviewed-by: default avatarPeter 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: default avatarZhang Rui <rui.zhang@intel.com>
parent 25a0a5ce
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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) {
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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);

+1 −1
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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);

+4 −4
Original line number Diff line number Diff line
@@ -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)
@@ -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);
}
@@ -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,
Loading