2023-02-19 14:37:38

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 00/17] Self-encapsulate the thermal zone device structure

The exported thermal headers expose the thermal core structure while those
should be private to the framework. The initial idea was the thermal sensor
drivers use the thermal zone device structure pointer to pass it around from
the ops to the thermal framework API like a handler.

Unfortunately, different drivers are using and abusing the internals of this
structure to hook the associated struct device, read the internals values, take
the lock, etc ...

rn order to fix this situation, let's encapsulate the structure leaking the
more in the different drivers: the thermal_zone_device structure.

This series revisit the existing drivers using the thermal zone private
structure internals to change the access to something else. For instance, the
get_temp() ops is using the tz->dev to write a debug trace. Despite the trace
is not helpful, we can check the return value for the get_temp() ops in the
call site and show the message in this place.

With this set of changes, the thermal_zone_device is almost self-encapsulated.
As usual, the acpi driver needs a more complex changes, so that will come in a
separate series along with the structure moved the private core headers.

Cc: "Rafael J. Wysocki" <[email protected]>
Cc: Zhang Rui <[email protected]>
Cc: Len Brown <[email protected]>
Cc: Damien Le Moal <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Jean Delvare <[email protected]>
Cc: Guenter Roeck <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: Lars-Peter Clausen <[email protected]>
Cc: Chen-Yu Tsai <[email protected]>
Cc: Jernej Skrabec <[email protected]>
Cc: Samuel Holland <[email protected]>
Cc: Dmitry Torokhov <[email protected]>
Cc: Raju Rangoju <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Ido Schimmel <[email protected]>
Cc: Petr Machata <[email protected]>
Cc: Gregory Greenman <[email protected]>
Cc: Kalle Valo <[email protected]>
Cc: Sebastian Reichel <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Daniel Lezcano <[email protected]>
Cc: Amit Kucheria <[email protected]>
Cc: Florian Fainelli <[email protected]>
Cc: Broadcom internal kernel review list <[email protected]>
Cc: Ray Jui <[email protected]>
Cc: Scott Branden <[email protected]>
Cc: Markus Mayer <[email protected]>
Cc: Support Opensource <[email protected]>
Cc: Andy Gross <[email protected]>
Cc: Bjorn Andersson <[email protected]>
Cc: Konrad Dybcio <[email protected]>
Cc: Thara Gopinath <[email protected]>
Cc: "Niklas Söderlund" <[email protected]>
Cc: Heiko Stuebner <[email protected]>
Cc: Bartlomiej Zolnierkiewicz <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Alim Akhtar <[email protected]>
Cc: Orson Zhai <[email protected]>
Cc: Baolin Wang <[email protected]>
Cc: Chunyan Zhang <[email protected]>
Cc: Vasily Khoruzhick <[email protected]>
Cc: Yangtao Li <[email protected]>
Cc: Thierry Reding <[email protected]>
Cc: Jonathan Hunter <[email protected]>
Cc: Talel Shenhar <[email protected]>
Cc: Eduardo Valentin <[email protected]>
Cc: Keerthy <[email protected]>
Cc: Kunihiko Hayashi <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Matthias Brugger <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Cc: Stefan Wahren <[email protected]>
Cc: Zheng Yongjun <[email protected]>
Cc: Yang Li <[email protected]>
Cc: Srinivas Pandruvada <[email protected]>
Cc: Daniel Golle <[email protected]>
Cc: Balsam CHIHI <[email protected]>
Cc: Mikko Perttunen <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]


Daniel Lezcano (17):
thermal/core: Add a thermal zone 'devdata' accessor
thermal/core: Show a debug message when get_temp() fails
thermal: Remove debug or error messages in get_temp() ops
thermal/hwmon: Do not set no_hwmon before calling
thermal_add_hwmon_sysfs()
thermal/hwmon: Use the right device for devm_thermal_add_hwmon_sysfs()
thermal: Don't use 'device' internal thermal zone structure field
thermal/hwmon: Use the thermal API instead tampering the internals
thermal/drivers/spear: Don't use tz->device but pdev->dev
thermal: Add a thermal zone id accessor
thermal: Do not access 'type' field, use the tz id instead
thermal/drivers/da9062: Don't access the thermal zone device fields
thermal/hwmon: Use the thermal_core.h header
thermal/drivers/tegra: Remove unneeded lock when setting a trip point
thermal/tegra: Do not enable the thermal zone, it is already enabled
thermal/drivers/acerhdf: Make interval setting only at module load
time
thermal/drivers/acerhdf: Remove pointless governor test
thermal/traces: Replace the thermal zone structure parameter with the
field value

drivers/acpi/thermal.c | 18 +++----
drivers/ata/ahci_imx.c | 2 +-
drivers/hwmon/hwmon.c | 4 +-
drivers/hwmon/pmbus/pmbus_core.c | 2 +-
drivers/hwmon/scmi-hwmon.c | 4 +-
drivers/hwmon/scpi-hwmon.c | 2 +-
drivers/iio/adc/sun4i-gpadc-iio.c | 2 +-
drivers/input/touchscreen/sun4i-ts.c | 2 +-
.../ethernet/chelsio/cxgb4/cxgb4_thermal.c | 2 +-
.../ethernet/mellanox/mlxsw/core_thermal.c | 18 +++----
drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 4 +-
drivers/platform/x86/acerhdf.c | 19 ++------
drivers/power/supply/power_supply_core.c | 2 +-
drivers/regulator/max8973-regulator.c | 2 +-
drivers/thermal/amlogic_thermal.c | 2 +-
drivers/thermal/armada_thermal.c | 14 ++----
drivers/thermal/broadcom/bcm2711_thermal.c | 3 +-
drivers/thermal/broadcom/bcm2835_thermal.c | 3 +-
drivers/thermal/broadcom/brcmstb_thermal.c | 8 ++--
drivers/thermal/broadcom/ns-thermal.c | 2 +-
drivers/thermal/broadcom/sr-thermal.c | 2 +-
drivers/thermal/da9062-thermal.c | 13 +++--
drivers/thermal/dove_thermal.c | 7 +--
drivers/thermal/gov_fair_share.c | 2 +-
drivers/thermal/gov_power_allocator.c | 4 +-
drivers/thermal/gov_step_wise.c | 2 +-
drivers/thermal/hisi_thermal.c | 5 +-
drivers/thermal/imx8mm_thermal.c | 4 +-
drivers/thermal/imx_sc_thermal.c | 9 ++--
drivers/thermal/imx_thermal.c | 47 +++++--------------
drivers/thermal/intel/intel_pch_thermal.c | 2 +-
drivers/thermal/intel/intel_soc_dts_iosf.c | 13 ++---
drivers/thermal/intel/x86_pkg_temp_thermal.c | 4 +-
drivers/thermal/k3_bandgap.c | 4 +-
drivers/thermal/k3_j72xx_bandgap.c | 2 +-
drivers/thermal/kirkwood_thermal.c | 7 +--
drivers/thermal/max77620_thermal.c | 6 +--
drivers/thermal/mediatek/auxadc_thermal.c | 4 +-
drivers/thermal/mediatek/lvts_thermal.c | 9 ++--
drivers/thermal/qcom/qcom-spmi-adc-tm5.c | 6 +--
drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 6 +--
drivers/thermal/qcom/tsens.c | 4 +-
drivers/thermal/qoriq_thermal.c | 4 +-
drivers/thermal/rcar_gen3_thermal.c | 5 +-
drivers/thermal/rcar_thermal.c | 8 +---
drivers/thermal/rockchip_thermal.c | 8 +---
drivers/thermal/rzg2l_thermal.c | 3 +-
drivers/thermal/samsung/exynos_tmu.c | 4 +-
drivers/thermal/spear_thermal.c | 10 ++--
drivers/thermal/sprd_thermal.c | 2 +-
drivers/thermal/st/st_thermal.c | 2 -
drivers/thermal/sun8i_thermal.c | 4 +-
drivers/thermal/tegra/tegra-bpmp-thermal.c | 6 ++-
drivers/thermal/tegra/tegra30-tsensor.c | 31 ++++++------
drivers/thermal/thermal-generic-adc.c | 7 ++-
drivers/thermal/thermal_core.c | 17 ++++++-
drivers/thermal/thermal_helpers.c | 3 ++
drivers/thermal/thermal_hwmon.c | 19 +++-----
drivers/thermal/thermal_hwmon.h | 4 +-
drivers/thermal/thermal_mmio.c | 2 +-
.../ti-soc-thermal/ti-thermal-common.c | 10 ++--
drivers/thermal/uniphier_thermal.c | 2 +-
include/linux/thermal.h | 4 ++
include/trace/events/thermal.h | 24 +++++-----
.../trace/events/thermal_power_allocator.h | 12 ++---
65 files changed, 203 insertions(+), 265 deletions(-)

--
2.34.1



2023-02-19 14:39:04

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 02/17] thermal/core: Show a debug message when get_temp() fails

The different thermal drivers are showing an error in case the
get_temp() fails. Actually no traces should be displayed in the
backend ops but in the call site of this ops.

Furthermore, the message is often a dev_dbg message where the
tz->device is used, thus using the internal of the structure from the
driver.

Show a debug message if the thermal_zone_get_temp() fails to read the
sensor temperature, so code showing the message is factored out and
the tz->device accesss is in the scope of the thermal core framework.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/thermal/thermal_helpers.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c
index 0f648131b0b5..9558339f5633 100644
--- a/drivers/thermal/thermal_helpers.c
+++ b/drivers/thermal/thermal_helpers.c
@@ -107,6 +107,9 @@ int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
*temp = tz->emul_temperature;
}

+ if (ret)
+ dev_dbg(&tz->device, "Failed to get temperature: %d\n", ret);
+
return ret;
}

--
2.34.1


2023-02-19 14:39:04

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 03/17] thermal: Remove debug or error messages in get_temp() ops

Some get_temp() ops implementation are showing an error or a debug
message if the reading of the sensor fails.

The debug message is already displayed from the call site of this
ops. So we can remove it.

On the other side, the error should not be displayed because in
production that can raise tons of messages.

Finally, some drivers are showing a debug message with the
temperature, this is also accessible through the trace from the core
code in the temperature_update() function.

Another benefit is the dev_* messages are accessing the thermal zone
device field from the structure, so we encapsulate even more the code
by preventing these accesses.

Remove those messages.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/thermal/armada_thermal.c | 10 ++--------
drivers/thermal/broadcom/brcmstb_thermal.c | 4 +---
drivers/thermal/dove_thermal.c | 5 +----
drivers/thermal/hisi_thermal.c | 3 ---
drivers/thermal/imx_sc_thermal.c | 5 +----
drivers/thermal/imx_thermal.c | 4 +---
drivers/thermal/kirkwood_thermal.c | 5 +----
drivers/thermal/max77620_thermal.c | 4 +---
drivers/thermal/rockchip_thermal.c | 3 ---
drivers/thermal/st/st_thermal.c | 2 --
drivers/thermal/thermal-generic-adc.c | 5 ++---
11 files changed, 10 insertions(+), 40 deletions(-)

diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c
index 82d3e15d51f6..9bbebde09dc4 100644
--- a/drivers/thermal/armada_thermal.c
+++ b/drivers/thermal/armada_thermal.c
@@ -360,11 +360,8 @@ static int armada_select_channel(struct armada_thermal_priv *priv, int channel)
* we must absolutely wait for the sensor validity bit to ensure we read
* actual data.
*/
- if (armada_wait_sensor_validity(priv)) {
- dev_err(priv->dev,
- "Temperature sensor reading not valid\n");
+ if (armada_wait_sensor_validity(priv))
return -EIO;
- }

return 0;
}
@@ -402,11 +399,8 @@ static int armada_get_temp_legacy(struct thermal_zone_device *thermal,
int ret;

/* Valid check */
- if (!armada_is_valid(priv)) {
- dev_err(priv->dev,
- "Temperature sensor reading not valid\n");
+ if (!armada_is_valid(priv))
return -EIO;
- }

/* Do the actual reading */
ret = armada_read_sensor(priv, temp);
diff --git a/drivers/thermal/broadcom/brcmstb_thermal.c b/drivers/thermal/broadcom/brcmstb_thermal.c
index 668cdc16b108..ae1981506da0 100644
--- a/drivers/thermal/broadcom/brcmstb_thermal.c
+++ b/drivers/thermal/broadcom/brcmstb_thermal.c
@@ -158,10 +158,8 @@ static int brcmstb_get_temp(struct thermal_zone_device *tz, int *temp)

val = __raw_readl(priv->tmon_base + AVS_TMON_STATUS);

- if (!(val & AVS_TMON_STATUS_valid_msk)) {
- dev_err(priv->dev, "reading not valid\n");
+ if (!(val & AVS_TMON_STATUS_valid_msk))
return -EIO;
- }

val = (val & AVS_TMON_STATUS_data_msk) >> AVS_TMON_STATUS_data_shift;

diff --git a/drivers/thermal/dove_thermal.c b/drivers/thermal/dove_thermal.c
index ed7d1173d9fd..9cd54740713f 100644
--- a/drivers/thermal/dove_thermal.c
+++ b/drivers/thermal/dove_thermal.c
@@ -91,11 +91,8 @@ static int dove_get_temp(struct thermal_zone_device *thermal,

/* Valid check */
reg = readl_relaxed(priv->control + PMU_TEMP_DIOD_CTRL1_REG);
- if ((reg & PMU_TDC1_TEMP_VALID_MASK) == 0x0) {
- dev_err(&thermal->device,
- "Temperature sensor reading not valid\n");
+ if ((reg & PMU_TDC1_TEMP_VALID_MASK) == 0x0)
return -EIO;
- }

/*
* Calculate temperature. According to Marvell internal
diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c
index 043751e6a31d..1e13fe80a9f3 100644
--- a/drivers/thermal/hisi_thermal.c
+++ b/drivers/thermal/hisi_thermal.c
@@ -436,9 +436,6 @@ static int hisi_thermal_get_temp(struct thermal_zone_device *tz, int *temp)

*temp = data->ops->get_temp(sensor);

- dev_dbg(&data->pdev->dev, "tzd=%p, id=%d, temp=%d, thres=%d\n",
- sensor->tzd, sensor->id, *temp, sensor->thres_temp);
-
return 0;
}

diff --git a/drivers/thermal/imx_sc_thermal.c b/drivers/thermal/imx_sc_thermal.c
index ca10d6a68f0f..26102d1c6bde 100644
--- a/drivers/thermal/imx_sc_thermal.c
+++ b/drivers/thermal/imx_sc_thermal.c
@@ -58,11 +58,8 @@ static int imx_sc_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
hdr->size = 2;

ret = imx_scu_call_rpc(thermal_ipc_handle, &msg, true);
- if (ret) {
- dev_err(&sensor->tzd->device, "read temp sensor %d failed, ret %d\n",
- sensor->resource_id, ret);
+ if (ret)
return ret;
- }

*temp = msg.data.resp.celsius * 1000 + msg.data.resp.tenths * 100;

diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index c3c14cd26aee..f621b778b0f0 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -265,10 +265,8 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)

regmap_read(map, soc_data->temp_data, &val);

- if ((val & soc_data->temp_valid_mask) == 0) {
- dev_dbg(&tz->device, "temp measurement never finished\n");
+ if ((val & soc_data->temp_valid_mask) == 0)
return -EAGAIN;
- }

n_meas = (val & soc_data->temp_value_mask)
>> soc_data->temp_value_shift;
diff --git a/drivers/thermal/kirkwood_thermal.c b/drivers/thermal/kirkwood_thermal.c
index 8e39c875ba58..f8c098a262fa 100644
--- a/drivers/thermal/kirkwood_thermal.c
+++ b/drivers/thermal/kirkwood_thermal.c
@@ -33,11 +33,8 @@ static int kirkwood_get_temp(struct thermal_zone_device *thermal,

/* Valid check */
if (!((reg >> KIRKWOOD_THERMAL_VALID_OFFSET) &
- KIRKWOOD_THERMAL_VALID_MASK)) {
- dev_err(&thermal->device,
- "Temperature sensor reading not valid\n");
+ KIRKWOOD_THERMAL_VALID_MASK))
return -EIO;
- }

/*
* Calculate temperature. According to Marvell internal
diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c
index 05b6e9a2a283..1dad8cb00735 100644
--- a/drivers/thermal/max77620_thermal.c
+++ b/drivers/thermal/max77620_thermal.c
@@ -51,10 +51,8 @@ static int max77620_thermal_read_temp(struct thermal_zone_device *tz, int *temp)
int ret;

ret = regmap_read(mtherm->rmap, MAX77620_REG_STATLBT, &val);
- if (ret < 0) {
- dev_err(mtherm->dev, "Failed to read STATLBT: %d\n", ret);
+ if (ret < 0)
return ret;
- }

if (val & MAX77620_IRQ_TJALRM2_MASK)
*temp = MAX77620_TJALARM2_TEMP;
diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c
index dafbdbb7c0c0..bd593ec712ee 100644
--- a/drivers/thermal/rockchip_thermal.c
+++ b/drivers/thermal/rockchip_thermal.c
@@ -1233,9 +1233,6 @@ static int rockchip_thermal_get_temp(struct thermal_zone_device *tz, int *out_te

retval = tsadc->get_temp(&tsadc->table,
sensor->id, thermal->regs, out_temp);
- dev_dbg(&thermal->pdev->dev, "sensor %d - temp: %d, retval: %d\n",
- sensor->id, *out_temp, retval);
-
return retval;
}

diff --git a/drivers/thermal/st/st_thermal.c b/drivers/thermal/st/st_thermal.c
index 1009f08e64e3..4d39626a4345 100644
--- a/drivers/thermal/st/st_thermal.c
+++ b/drivers/thermal/st/st_thermal.c
@@ -127,8 +127,6 @@ static int st_thermal_get_temp(struct thermal_zone_device *th, int *temperature)
temp += sensor->cdata->temp_adjust_val;
temp = mcelsius(temp);

- dev_dbg(dev, "temperature: %d\n", temp);
-
*temperature = temp;

return 0;
diff --git a/drivers/thermal/thermal-generic-adc.c b/drivers/thermal/thermal-generic-adc.c
index 8e2ff0df7e64..7f3eda31d0fa 100644
--- a/drivers/thermal/thermal-generic-adc.c
+++ b/drivers/thermal/thermal-generic-adc.c
@@ -59,10 +59,9 @@ static int gadc_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
int ret;

ret = iio_read_channel_processed(gti->channel, &val);
- if (ret < 0) {
- dev_err(gti->dev, "IIO channel read failed %d\n", ret);
+ if (ret < 0)
return ret;
- }
+
*temp = gadc_thermal_adc_to_temp(gti, val);

return 0;
--
2.34.1


2023-02-19 14:39:05

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 04/17] thermal/hwmon: Do not set no_hwmon before calling thermal_add_hwmon_sysfs()

The thermal->tzp->no_hwmon parameter is only used when calling
thermal_zone_device_register().

Setting it to 'false' before calling thermal_add_hwmon_sysfs() has no
effect.

Remove the call and again prevent the drivers to access the thermal
internals.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/thermal/broadcom/bcm2711_thermal.c | 1 -
drivers/thermal/broadcom/bcm2835_thermal.c | 1 -
drivers/thermal/rcar_gen3_thermal.c | 1 -
drivers/thermal/rcar_thermal.c | 5 -----
drivers/thermal/rockchip_thermal.c | 1 -
drivers/thermal/rzg2l_thermal.c | 1 -
6 files changed, 10 deletions(-)

diff --git a/drivers/thermal/broadcom/bcm2711_thermal.c b/drivers/thermal/broadcom/bcm2711_thermal.c
index 18b1a4d9ecc7..0a499435431c 100644
--- a/drivers/thermal/broadcom/bcm2711_thermal.c
+++ b/drivers/thermal/broadcom/bcm2711_thermal.c
@@ -98,7 +98,6 @@ static int bcm2711_thermal_probe(struct platform_device *pdev)

priv->thermal = thermal;

- thermal->tzp->no_hwmon = false;
return thermal_add_hwmon_sysfs(thermal);
}

diff --git a/drivers/thermal/broadcom/bcm2835_thermal.c b/drivers/thermal/broadcom/bcm2835_thermal.c
index de2f573863da..8ed7a80122a0 100644
--- a/drivers/thermal/broadcom/bcm2835_thermal.c
+++ b/drivers/thermal/broadcom/bcm2835_thermal.c
@@ -267,7 +267,6 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)
* Thermal_zone doesn't enable hwmon as default,
* enable it here
*/
- tz->tzp->no_hwmon = false;
err = thermal_add_hwmon_sysfs(tz);
if (err)
goto err_tz;
diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c
index 8ad713cb4bf7..4ea9d4bd8e6f 100644
--- a/drivers/thermal/rcar_gen3_thermal.c
+++ b/drivers/thermal/rcar_gen3_thermal.c
@@ -527,7 +527,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
}
tsc->zone = zone;

- tsc->zone->tzp->no_hwmon = false;
ret = thermal_add_hwmon_sysfs(tsc->zone);
if (ret)
goto error_unregister;
diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
index 538ed6731589..919f0e32d3c5 100644
--- a/drivers/thermal/rcar_thermal.c
+++ b/drivers/thermal/rcar_thermal.c
@@ -509,11 +509,6 @@ static int rcar_thermal_probe(struct platform_device *pdev)
}

if (chip->use_of_thermal) {
- /*
- * thermal_zone doesn't enable hwmon as default,
- * but, enable it here to keep compatible
- */
- priv->zone->tzp->no_hwmon = false;
ret = thermal_add_hwmon_sysfs(priv->zone);
if (ret)
goto error_unregister;
diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c
index bd593ec712ee..3211b70c85b9 100644
--- a/drivers/thermal/rockchip_thermal.c
+++ b/drivers/thermal/rockchip_thermal.c
@@ -1451,7 +1451,6 @@ static int rockchip_thermal_probe(struct platform_device *pdev)

for (i = 0; i < thermal->chip->chn_num; i++) {
rockchip_thermal_toggle_sensor(&thermal->sensors[i], true);
- thermal->sensors[i].tzd->tzp->no_hwmon = false;
error = thermal_add_hwmon_sysfs(thermal->sensors[i].tzd);
if (error)
dev_warn(&pdev->dev,
diff --git a/drivers/thermal/rzg2l_thermal.c b/drivers/thermal/rzg2l_thermal.c
index d3ba2a74e42d..a2f21c941cfe 100644
--- a/drivers/thermal/rzg2l_thermal.c
+++ b/drivers/thermal/rzg2l_thermal.c
@@ -216,7 +216,6 @@ static int rzg2l_thermal_probe(struct platform_device *pdev)
}

priv->zone = zone;
- priv->zone->tzp->no_hwmon = false;
ret = thermal_add_hwmon_sysfs(priv->zone);
if (ret)
goto err;
--
2.34.1


2023-02-19 14:39:05

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 05/17] thermal/hwmon: Use the right device for devm_thermal_add_hwmon_sysfs()

The devres variant of thermal_add_hwmon_sysfs() only takes the thermal
zone structure pointer as parameter.

Actually, it uses the tz->device to add it in the devres list.

It is preferable to use the device registering the thermal zone
instead of the thermal zone device itself. That prevents the driver
accessing the thermal zone structure internals and it is from my POV
more correct regarding how devm_ is used.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/thermal/amlogic_thermal.c | 2 +-
drivers/thermal/imx8mm_thermal.c | 2 +-
drivers/thermal/imx_sc_thermal.c | 2 +-
drivers/thermal/k3_bandgap.c | 2 +-
drivers/thermal/mediatek/auxadc_thermal.c | 2 +-
drivers/thermal/qcom/qcom-spmi-adc-tm5.c | 2 +-
drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 2 +-
drivers/thermal/qcom/tsens.c | 2 +-
drivers/thermal/qoriq_thermal.c | 2 +-
drivers/thermal/sun8i_thermal.c | 2 +-
drivers/thermal/tegra/tegra30-tsensor.c | 2 +-
drivers/thermal/thermal_hwmon.c | 4 ++--
drivers/thermal/thermal_hwmon.h | 4 ++--
drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 2 +-
14 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/thermal/amlogic_thermal.c b/drivers/thermal/amlogic_thermal.c
index 9235fda4ec1e..337153042318 100644
--- a/drivers/thermal/amlogic_thermal.c
+++ b/drivers/thermal/amlogic_thermal.c
@@ -285,7 +285,7 @@ static int amlogic_thermal_probe(struct platform_device *pdev)
return ret;
}

- if (devm_thermal_add_hwmon_sysfs(pdata->tzd))
+ if (devm_thermal_add_hwmon_sysfs(&pdev->dev, pdata->tzd))
dev_warn(&pdev->dev, "Failed to add hwmon sysfs attributes\n");

ret = amlogic_thermal_initialize(pdata);
diff --git a/drivers/thermal/imx8mm_thermal.c b/drivers/thermal/imx8mm_thermal.c
index 750240f4fa32..e0830dcec4a0 100644
--- a/drivers/thermal/imx8mm_thermal.c
+++ b/drivers/thermal/imx8mm_thermal.c
@@ -343,7 +343,7 @@ static int imx8mm_tmu_probe(struct platform_device *pdev)
}
tmu->sensors[i].hw_id = i;

- if (devm_thermal_add_hwmon_sysfs(tmu->sensors[i].tzd))
+ if (devm_thermal_add_hwmon_sysfs(&pdev->dev, tmu->sensors[i].tzd))
dev_warn(&pdev->dev, "failed to add hwmon sysfs attributes\n");
}

diff --git a/drivers/thermal/imx_sc_thermal.c b/drivers/thermal/imx_sc_thermal.c
index 26102d1c6bde..631bda2401eb 100644
--- a/drivers/thermal/imx_sc_thermal.c
+++ b/drivers/thermal/imx_sc_thermal.c
@@ -116,7 +116,7 @@ static int imx_sc_thermal_probe(struct platform_device *pdev)
return ret;
}

- if (devm_thermal_add_hwmon_sysfs(sensor->tzd))
+ if (devm_thermal_add_hwmon_sysfs(&pdev->dev, sensor->tzd))
dev_warn(&pdev->dev, "failed to add hwmon sysfs attributes\n");
}

diff --git a/drivers/thermal/k3_bandgap.c b/drivers/thermal/k3_bandgap.c
index 8cbd7361b492..ee059997d00d 100644
--- a/drivers/thermal/k3_bandgap.c
+++ b/drivers/thermal/k3_bandgap.c
@@ -222,7 +222,7 @@ static int k3_bandgap_probe(struct platform_device *pdev)
goto err_alloc;
}

- if (devm_thermal_add_hwmon_sysfs(data[id].tzd))
+ if (devm_thermal_add_hwmon_sysfs(dev, data[id].tzd))
dev_warn(dev, "Failed to add hwmon sysfs attributes\n");
}

diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c
index d7bf725d224b..d4b8246d4991 100644
--- a/drivers/thermal/mediatek/auxadc_thermal.c
+++ b/drivers/thermal/mediatek/auxadc_thermal.c
@@ -1210,7 +1210,7 @@ static int mtk_thermal_probe(struct platform_device *pdev)
goto err_disable_clk_peri_therm;
}

- ret = devm_thermal_add_hwmon_sysfs(tzdev);
+ ret = devm_thermal_add_hwmon_sysfs(&pdev->dev, tzdev);
if (ret)
dev_warn(&pdev->dev, "error in thermal_add_hwmon_sysfs");

diff --git a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
index b0269daf128a..e3c8c9dc93e2 100644
--- a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
+++ b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
@@ -689,7 +689,7 @@ static int adc_tm5_register_tzd(struct adc_tm5_chip *adc_tm)
return PTR_ERR(tzd);
}
adc_tm->channels[i].tzd = tzd;
- if (devm_thermal_add_hwmon_sysfs(tzd))
+ if (devm_thermal_add_hwmon_sysfs(adc_tm->dev, tzd))
dev_warn(adc_tm->dev,
"Failed to add hwmon sysfs attributes\n");
}
diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
index c817b03deb00..f82e0051d30e 100644
--- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
+++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
@@ -459,7 +459,7 @@ static int qpnp_tm_probe(struct platform_device *pdev)
return ret;
}

- if (devm_thermal_add_hwmon_sysfs(chip->tz_dev))
+ if (devm_thermal_add_hwmon_sysfs(&pdev->dev, chip->tz_dev))
dev_warn(&pdev->dev,
"Failed to add hwmon sysfs attributes\n");

diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index 8020ead2794e..49c1fdca36dd 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -1189,7 +1189,7 @@ static int tsens_register(struct tsens_priv *priv)
if (priv->ops->enable)
priv->ops->enable(priv, i);

- if (devm_thermal_add_hwmon_sysfs(tzd))
+ if (devm_thermal_add_hwmon_sysfs(priv->dev, tzd))
dev_warn(priv->dev,
"Failed to add hwmon sysfs attributes\n");
}
diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index 8b6fe0c9ade2..e6f244d18c59 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -157,7 +157,7 @@ static int qoriq_tmu_register_tmu_zone(struct device *dev,
return ret;
}

- if (devm_thermal_add_hwmon_sysfs(tzd))
+ if (devm_thermal_add_hwmon_sysfs(dev, tzd))
dev_warn(dev,
"Failed to add hwmon sysfs attributes\n");

diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c
index 085b7b0b7c72..ec4aa60dd1fb 100644
--- a/drivers/thermal/sun8i_thermal.c
+++ b/drivers/thermal/sun8i_thermal.c
@@ -475,7 +475,7 @@ static int sun8i_ths_register(struct ths_device *tmdev)
if (IS_ERR(tmdev->sensor[i].tzd))
return PTR_ERR(tmdev->sensor[i].tzd);

- if (devm_thermal_add_hwmon_sysfs(tmdev->sensor[i].tzd))
+ if (devm_thermal_add_hwmon_sysfs(tmdev->dev, tmdev->sensor[i].tzd))
dev_warn(tmdev->dev,
"Failed to add hwmon sysfs attributes\n");
}
diff --git a/drivers/thermal/tegra/tegra30-tsensor.c b/drivers/thermal/tegra/tegra30-tsensor.c
index 537413acc6d2..ceb5b1b338a9 100644
--- a/drivers/thermal/tegra/tegra30-tsensor.c
+++ b/drivers/thermal/tegra/tegra30-tsensor.c
@@ -528,7 +528,7 @@ static int tegra_tsensor_register_channel(struct tegra_tsensor *ts,
return 0;
}

- if (devm_thermal_add_hwmon_sysfs(tsc->tzd))
+ if (devm_thermal_add_hwmon_sysfs(ts->dev, tsc->tzd))
dev_warn(ts->dev, "failed to add hwmon sysfs attributes\n");

return 0;
diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
index c594c42bea6d..964db7941e31 100644
--- a/drivers/thermal/thermal_hwmon.c
+++ b/drivers/thermal/thermal_hwmon.c
@@ -263,7 +263,7 @@ static void devm_thermal_hwmon_release(struct device *dev, void *res)
thermal_remove_hwmon_sysfs(*(struct thermal_zone_device **)res);
}

-int devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
+int devm_thermal_add_hwmon_sysfs(struct device *dev, struct thermal_zone_device *tz)
{
struct thermal_zone_device **ptr;
int ret;
@@ -280,7 +280,7 @@ int devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
}

*ptr = tz;
- devres_add(&tz->device, ptr);
+ devres_add(dev, ptr);

return ret;
}
diff --git a/drivers/thermal/thermal_hwmon.h b/drivers/thermal/thermal_hwmon.h
index 1a9d65f6a6a8..b429f6e7abdb 100644
--- a/drivers/thermal/thermal_hwmon.h
+++ b/drivers/thermal/thermal_hwmon.h
@@ -17,7 +17,7 @@

#ifdef CONFIG_THERMAL_HWMON
int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz);
-int devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz);
+int devm_thermal_add_hwmon_sysfs(struct device *dev, struct thermal_zone_device *tz);
void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz);
#else
static inline int
@@ -27,7 +27,7 @@ thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
}

static inline int
-devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
+devm_thermal_add_hwmon_sysfs(struct device *dev, struct thermal_zone_device *tz)
{
return 0;
}
diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
index 7f6b71d11eed..9fb1ca5e39f6 100644
--- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
+++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
@@ -182,7 +182,7 @@ int ti_thermal_expose_sensor(struct ti_bandgap *bgp, int id,
ti_bandgap_set_sensor_data(bgp, id, data);
ti_bandgap_write_update_interval(bgp, data->sensor_id, interval);

- if (devm_thermal_add_hwmon_sysfs(data->ti_thermal))
+ if (devm_thermal_add_hwmon_sysfs(bgp->dev, data->ti_thermal))
dev_warn(bgp->dev, "failed to add hwmon sysfs attributes\n");

return 0;
--
2.34.1


2023-02-19 14:39:05

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

The thermal zone device structure is exposed to the different drivers
and obviously they access the internals while that should be
restricted to the core thermal code.

In order to self-encapsulate the thermal core code, we need to prevent
the drivers accessing directly the thermal zone structure and provide
accessor functions to deal with.

Provide an accessor to the 'devdata' structure and make use of it in
the different drivers.

No functional changes intended.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/acpi/thermal.c | 16 ++++++++--------
drivers/ata/ahci_imx.c | 2 +-
drivers/hwmon/hwmon.c | 4 ++--
drivers/hwmon/pmbus/pmbus_core.c | 2 +-
drivers/hwmon/scmi-hwmon.c | 2 +-
drivers/hwmon/scpi-hwmon.c | 2 +-
drivers/iio/adc/sun4i-gpadc-iio.c | 2 +-
drivers/input/touchscreen/sun4i-ts.c | 2 +-
.../net/ethernet/chelsio/cxgb4/cxgb4_thermal.c | 2 +-
.../net/ethernet/mellanox/mlxsw/core_thermal.c | 14 +++++++-------
drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 4 ++--
drivers/power/supply/power_supply_core.c | 2 +-
drivers/regulator/max8973-regulator.c | 2 +-
drivers/thermal/armada_thermal.c | 4 ++--
drivers/thermal/broadcom/bcm2711_thermal.c | 2 +-
drivers/thermal/broadcom/bcm2835_thermal.c | 2 +-
drivers/thermal/broadcom/brcmstb_thermal.c | 4 ++--
drivers/thermal/broadcom/ns-thermal.c | 2 +-
drivers/thermal/broadcom/sr-thermal.c | 2 +-
drivers/thermal/da9062-thermal.c | 2 +-
drivers/thermal/dove_thermal.c | 2 +-
drivers/thermal/hisi_thermal.c | 2 +-
drivers/thermal/imx8mm_thermal.c | 2 +-
drivers/thermal/imx_sc_thermal.c | 2 +-
drivers/thermal/imx_thermal.c | 6 +++---
drivers/thermal/intel/intel_pch_thermal.c | 2 +-
drivers/thermal/intel/intel_soc_dts_iosf.c | 13 +++++--------
drivers/thermal/intel/x86_pkg_temp_thermal.c | 4 ++--
drivers/thermal/k3_bandgap.c | 2 +-
drivers/thermal/k3_j72xx_bandgap.c | 2 +-
drivers/thermal/kirkwood_thermal.c | 2 +-
drivers/thermal/max77620_thermal.c | 2 +-
drivers/thermal/mediatek/auxadc_thermal.c | 2 +-
drivers/thermal/mediatek/lvts_thermal.c | 4 ++--
drivers/thermal/qcom/qcom-spmi-adc-tm5.c | 4 ++--
drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 4 ++--
drivers/thermal/qoriq_thermal.c | 2 +-
drivers/thermal/rcar_gen3_thermal.c | 4 ++--
drivers/thermal/rcar_thermal.c | 3 +--
drivers/thermal/rockchip_thermal.c | 4 ++--
drivers/thermal/rzg2l_thermal.c | 2 +-
drivers/thermal/samsung/exynos_tmu.c | 4 ++--
drivers/thermal/spear_thermal.c | 8 ++++----
drivers/thermal/sprd_thermal.c | 2 +-
drivers/thermal/sun8i_thermal.c | 2 +-
drivers/thermal/tegra/tegra-bpmp-thermal.c | 6 ++++--
drivers/thermal/tegra/tegra30-tsensor.c | 4 ++--
drivers/thermal/thermal-generic-adc.c | 2 +-
drivers/thermal/thermal_core.c | 6 ++++++
drivers/thermal/thermal_mmio.c | 2 +-
.../thermal/ti-soc-thermal/ti-thermal-common.c | 4 ++--
drivers/thermal/uniphier_thermal.c | 2 +-
include/linux/thermal.h | 2 ++
53 files changed, 97 insertions(+), 91 deletions(-)

diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 0b4b844f9d4c..69d0da6456d5 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -498,7 +498,7 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)

static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp)
{
- struct acpi_thermal *tz = thermal->devdata;
+ struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);
int result;

if (!tz)
@@ -516,7 +516,7 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp)
static int thermal_get_trip_type(struct thermal_zone_device *thermal,
int trip, enum thermal_trip_type *type)
{
- struct acpi_thermal *tz = thermal->devdata;
+ struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);
int i;

if (!tz || trip < 0)
@@ -560,7 +560,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, int *temp)
{
- struct acpi_thermal *tz = thermal->devdata;
+ struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);
int i;

if (!tz || trip < 0)
@@ -613,7 +613,7 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
int *temperature)
{
- struct acpi_thermal *tz = thermal->devdata;
+ struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);

if (tz->trips.critical.flags.valid) {
*temperature = deci_kelvin_to_millicelsius_with_offset(
@@ -628,7 +628,7 @@ static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
static int thermal_get_trend(struct thermal_zone_device *thermal,
int trip, enum thermal_trend *trend)
{
- struct acpi_thermal *tz = thermal->devdata;
+ struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);
enum thermal_trip_type type;
int i;

@@ -670,7 +670,7 @@ static int thermal_get_trend(struct thermal_zone_device *thermal,

static void acpi_thermal_zone_device_hot(struct thermal_zone_device *thermal)
{
- struct acpi_thermal *tz = thermal->devdata;
+ struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);

acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
dev_name(&tz->device->dev),
@@ -679,7 +679,7 @@ static void acpi_thermal_zone_device_hot(struct thermal_zone_device *thermal)

static void acpi_thermal_zone_device_critical(struct thermal_zone_device *thermal)
{
- struct acpi_thermal *tz = thermal->devdata;
+ struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);

acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
dev_name(&tz->device->dev),
@@ -693,7 +693,7 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
bool bind)
{
struct acpi_device *device = cdev->devdata;
- struct acpi_thermal *tz = thermal->devdata;
+ struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);
struct acpi_device *dev;
acpi_handle handle;
int i;
diff --git a/drivers/ata/ahci_imx.c b/drivers/ata/ahci_imx.c
index a950767f7948..0ef928528aec 100644
--- a/drivers/ata/ahci_imx.c
+++ b/drivers/ata/ahci_imx.c
@@ -418,7 +418,7 @@ static int __sata_ahci_read_temperature(void *dev, int *temp)

static int sata_ahci_read_temperature(struct thermal_zone_device *tz, int *temp)
{
- return __sata_ahci_read_temperature(tz->devdata, temp);
+ return __sata_ahci_read_temperature(thermal_zone_device_get_data(tz), temp);
}

static ssize_t sata_ahci_show_temp(struct device *dev,
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 33edb5c02f7d..b33477d04c2b 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -154,7 +154,7 @@ static DEFINE_IDA(hwmon_ida);
#ifdef CONFIG_THERMAL_OF
static int hwmon_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct hwmon_thermal_data *tdata = tz->devdata;
+ struct hwmon_thermal_data *tdata = thermal_zone_device_get_data(tz);
struct hwmon_device *hwdev = to_hwmon_device(tdata->dev);
int ret;
long t;
@@ -171,7 +171,7 @@ static int hwmon_thermal_get_temp(struct thermal_zone_device *tz, int *temp)

static int hwmon_thermal_set_trips(struct thermal_zone_device *tz, int low, int high)
{
- struct hwmon_thermal_data *tdata = tz->devdata;
+ struct hwmon_thermal_data *tdata = thermal_zone_device_get_data(tz);
struct hwmon_device *hwdev = to_hwmon_device(tdata->dev);
const struct hwmon_chip_info *chip = hwdev->chip;
const struct hwmon_channel_info **info = chip->info;
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 95e95783972a..159a88af6277 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -1272,7 +1272,7 @@ struct pmbus_thermal_data {

static int pmbus_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct pmbus_thermal_data *tdata = tz->devdata;
+ struct pmbus_thermal_data *tdata = thermal_zone_device_get_data(tz);
struct pmbus_sensor *sensor = tdata->sensor;
struct pmbus_data *pmbus_data = tdata->pmbus_data;
struct i2c_client *client = to_i2c_client(pmbus_data->dev);
diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
index e192f0c67146..7951b6026f48 100644
--- a/drivers/hwmon/scmi-hwmon.c
+++ b/drivers/hwmon/scmi-hwmon.c
@@ -141,7 +141,7 @@ static int scmi_hwmon_thermal_get_temp(struct thermal_zone_device *tz,
{
int ret;
long value;
- struct scmi_thermal_sensor *th_sensor = tz->devdata;
+ struct scmi_thermal_sensor *th_sensor = thermal_zone_device_get_data(tz);

ret = scmi_hwmon_read_scaled_value(th_sensor->ph, th_sensor->info,
&value);
diff --git a/drivers/hwmon/scpi-hwmon.c b/drivers/hwmon/scpi-hwmon.c
index 4d75385f7d5e..efe0ddbc5293 100644
--- a/drivers/hwmon/scpi-hwmon.c
+++ b/drivers/hwmon/scpi-hwmon.c
@@ -64,7 +64,7 @@ static void scpi_scale_reading(u64 *value, struct sensor_data *sensor)

static int scpi_read_temp(struct thermal_zone_device *tz, int *temp)
{
- struct scpi_thermal_zone *zone = tz->devdata;
+ struct scpi_thermal_zone *zone = thermal_zone_device_get_data(tz);
struct scpi_sensors *scpi_sensors = zone->scpi_sensors;
struct scpi_ops *scpi_ops = scpi_sensors->scpi_ops;
struct sensor_data *sensor = &scpi_sensors->data[zone->sensor_id];
diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c
index a6ade70dedf8..e24ac3ee8a35 100644
--- a/drivers/iio/adc/sun4i-gpadc-iio.c
+++ b/drivers/iio/adc/sun4i-gpadc-iio.c
@@ -414,7 +414,7 @@ static int sun4i_gpadc_runtime_resume(struct device *dev)

static int sun4i_gpadc_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct sun4i_gpadc_iio *info = tz->devdata;
+ struct sun4i_gpadc_iio *info = thermal_zone_device_get_data(tz);
int val, scale, offset;

if (sun4i_gpadc_temp_read(info->indio_dev, &val))
diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
index 73eb8f80be6e..5e5434ffe397 100644
--- a/drivers/input/touchscreen/sun4i-ts.c
+++ b/drivers/input/touchscreen/sun4i-ts.c
@@ -194,7 +194,7 @@ static int sun4i_get_temp(const struct sun4i_ts_data *ts, int *temp)

static int sun4i_get_tz_temp(struct thermal_zone_device *tz, int *temp)
{
- return sun4i_get_temp(tz->devdata, temp);
+ return sun4i_get_temp(thermal_zone_device_get_data(tz), temp);
}

static const struct thermal_zone_device_ops sun4i_ts_tz_ops = {
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c
index 95e1b415ba13..8b0d318feef4 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c
@@ -12,7 +12,7 @@
static int cxgb4_thermal_get_temp(struct thermal_zone_device *tzdev,
int *temp)
{
- struct adapter *adap = tzdev->devdata;
+ struct adapter *adap = thermal_zone_device_get_data(tzdev);
u32 param, val;
int ret;

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
index c5240d38c9db..228b6ffaef98 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
@@ -201,7 +201,7 @@ mlxsw_thermal_module_trips_update(struct device *dev, struct mlxsw_core *core,
static int mlxsw_thermal_bind(struct thermal_zone_device *tzdev,
struct thermal_cooling_device *cdev)
{
- struct mlxsw_thermal *thermal = tzdev->devdata;
+ struct mlxsw_thermal *thermal = thermal_zone_device_get_data(tzdev);
struct device *dev = thermal->bus_info->dev;
int i, err;

@@ -227,7 +227,7 @@ static int mlxsw_thermal_bind(struct thermal_zone_device *tzdev,
static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev,
struct thermal_cooling_device *cdev)
{
- struct mlxsw_thermal *thermal = tzdev->devdata;
+ struct mlxsw_thermal *thermal = thermal_zone_device_get_data(tzdev);
struct device *dev = thermal->bus_info->dev;
int i;
int err;
@@ -249,7 +249,7 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev,
static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev,
int *p_temp)
{
- struct mlxsw_thermal *thermal = tzdev->devdata;
+ struct mlxsw_thermal *thermal = thermal_zone_device_get_data(tzdev);
struct device *dev = thermal->bus_info->dev;
char mtmp_pl[MLXSW_REG_MTMP_LEN];
int temp;
@@ -281,7 +281,7 @@ static struct thermal_zone_device_ops mlxsw_thermal_ops = {
static int mlxsw_thermal_module_bind(struct thermal_zone_device *tzdev,
struct thermal_cooling_device *cdev)
{
- struct mlxsw_thermal_module *tz = tzdev->devdata;
+ struct mlxsw_thermal_module *tz = thermal_zone_device_get_data(tzdev);
struct mlxsw_thermal *thermal = tz->parent;
int i, j, err;

@@ -310,7 +310,7 @@ static int mlxsw_thermal_module_bind(struct thermal_zone_device *tzdev,
static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev,
struct thermal_cooling_device *cdev)
{
- struct mlxsw_thermal_module *tz = tzdev->devdata;
+ struct mlxsw_thermal_module *tz = thermal_zone_device_get_data(tzdev);
struct mlxsw_thermal *thermal = tz->parent;
int i;
int err;
@@ -356,7 +356,7 @@ mlxsw_thermal_module_temp_and_thresholds_get(struct mlxsw_core *core,
static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev,
int *p_temp)
{
- struct mlxsw_thermal_module *tz = tzdev->devdata;
+ struct mlxsw_thermal_module *tz = thermal_zone_device_get_data(tzdev);
struct mlxsw_thermal *thermal = tz->parent;
int temp, crit_temp, emerg_temp;
struct device *dev;
@@ -391,7 +391,7 @@ static struct thermal_zone_device_ops mlxsw_thermal_module_ops = {
static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev,
int *p_temp)
{
- struct mlxsw_thermal_module *tz = tzdev->devdata;
+ struct mlxsw_thermal_module *tz = thermal_zone_device_get_data(tzdev);
struct mlxsw_thermal *thermal = tz->parent;
char mtmp_pl[MLXSW_REG_MTMP_LEN];
u16 index;
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c
index 232c200af38f..ee8fee29107f 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c
@@ -615,7 +615,7 @@ int iwl_mvm_send_temp_report_ths_cmd(struct iwl_mvm *mvm)
static int iwl_mvm_tzone_get_temp(struct thermal_zone_device *device,
int *temperature)
{
- struct iwl_mvm *mvm = (struct iwl_mvm *)device->devdata;
+ struct iwl_mvm *mvm = thermal_zone_device_get_data(device);
int ret;
int temp;

@@ -641,7 +641,7 @@ static int iwl_mvm_tzone_get_temp(struct thermal_zone_device *device,
static int iwl_mvm_tzone_set_trip_temp(struct thermal_zone_device *device,
int trip, int temp)
{
- struct iwl_mvm *mvm = (struct iwl_mvm *)device->devdata;
+ struct iwl_mvm *mvm = thermal_zone_device_get_data(device);
struct iwl_mvm_thermal_device *tzone;
int ret;

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 7c790c41e2fe..166f0aacc797 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -1142,7 +1142,7 @@ static int power_supply_read_temp(struct thermal_zone_device *tzd,
int ret;

WARN_ON(tzd == NULL);
- psy = tzd->devdata;
+ psy = thermal_zone_device_get_data(tzd);
ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_TEMP, &val);
if (ret)
return ret;
diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
index 7e00a45db26a..ccacba66d367 100644
--- a/drivers/regulator/max8973-regulator.c
+++ b/drivers/regulator/max8973-regulator.c
@@ -436,7 +436,7 @@ static int max8973_init_dcdc(struct max8973_chip *max,

static int max8973_thermal_read_temp(struct thermal_zone_device *tz, int *temp)
{
- struct max8973_chip *mchip = tz->devdata;
+ struct max8973_chip *mchip = thermal_zone_device_get_data(tz);
unsigned int val;
int ret;

diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c
index 2efc222a379b..82d3e15d51f6 100644
--- a/drivers/thermal/armada_thermal.c
+++ b/drivers/thermal/armada_thermal.c
@@ -398,7 +398,7 @@ static int armada_read_sensor(struct armada_thermal_priv *priv, int *temp)
static int armada_get_temp_legacy(struct thermal_zone_device *thermal,
int *temp)
{
- struct armada_thermal_priv *priv = thermal->devdata;
+ struct armada_thermal_priv *priv = thermal_zone_device_get_data(thermal);
int ret;

/* Valid check */
@@ -420,7 +420,7 @@ static struct thermal_zone_device_ops legacy_ops = {

static int armada_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct armada_thermal_sensor *sensor = tz->devdata;
+ struct armada_thermal_sensor *sensor = thermal_zone_device_get_data(tz);
struct armada_thermal_priv *priv = sensor->priv;
int ret;

diff --git a/drivers/thermal/broadcom/bcm2711_thermal.c b/drivers/thermal/broadcom/bcm2711_thermal.c
index 1f8651d15160..18b1a4d9ecc7 100644
--- a/drivers/thermal/broadcom/bcm2711_thermal.c
+++ b/drivers/thermal/broadcom/bcm2711_thermal.c
@@ -33,7 +33,7 @@ struct bcm2711_thermal_priv {

static int bcm2711_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct bcm2711_thermal_priv *priv = tz->devdata;
+ struct bcm2711_thermal_priv *priv = thermal_zone_device_get_data(tz);
int slope = thermal_zone_get_slope(tz);
int offset = thermal_zone_get_offset(tz);
u32 val;
diff --git a/drivers/thermal/broadcom/bcm2835_thermal.c b/drivers/thermal/broadcom/bcm2835_thermal.c
index 23918bb76ae6..de2f573863da 100644
--- a/drivers/thermal/broadcom/bcm2835_thermal.c
+++ b/drivers/thermal/broadcom/bcm2835_thermal.c
@@ -90,7 +90,7 @@ static int bcm2835_thermal_temp2adc(int temp, int offset, int slope)

static int bcm2835_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct bcm2835_thermal_data *data = tz->devdata;
+ struct bcm2835_thermal_data *data = thermal_zone_device_get_data(tz);
u32 val = readl(data->regs + BCM2835_TS_TSENSSTAT);

if (!(val & BCM2835_TS_TSENSSTAT_VALID))
diff --git a/drivers/thermal/broadcom/brcmstb_thermal.c b/drivers/thermal/broadcom/brcmstb_thermal.c
index 4d02c28331e3..668cdc16b108 100644
--- a/drivers/thermal/broadcom/brcmstb_thermal.c
+++ b/drivers/thermal/broadcom/brcmstb_thermal.c
@@ -152,7 +152,7 @@ static inline u32 avs_tmon_temp_to_code(struct brcmstb_thermal_priv *priv,

static int brcmstb_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct brcmstb_thermal_priv *priv = tz->devdata;
+ struct brcmstb_thermal_priv *priv = thermal_zone_device_get_data(tz);
u32 val;
long t;

@@ -262,7 +262,7 @@ static irqreturn_t brcmstb_tmon_irq_thread(int irq, void *data)

static int brcmstb_set_trips(struct thermal_zone_device *tz, int low, int high)
{
- struct brcmstb_thermal_priv *priv = tz->devdata;
+ struct brcmstb_thermal_priv *priv = thermal_zone_device_get_data(tz);

dev_dbg(priv->dev, "set trips %d <--> %d\n", low, high);

diff --git a/drivers/thermal/broadcom/ns-thermal.c b/drivers/thermal/broadcom/ns-thermal.c
index 07a8a3f49bd0..98296019ad4c 100644
--- a/drivers/thermal/broadcom/ns-thermal.c
+++ b/drivers/thermal/broadcom/ns-thermal.c
@@ -16,7 +16,7 @@

static int ns_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
- void __iomem *pvtmon = tz->devdata;
+ void __iomem *pvtmon = thermal_zone_device_get_data(tz);
int offset = thermal_zone_get_offset(tz);
int slope = thermal_zone_get_slope(tz);
u32 val;
diff --git a/drivers/thermal/broadcom/sr-thermal.c b/drivers/thermal/broadcom/sr-thermal.c
index 2b93502543ff..42b46125f409 100644
--- a/drivers/thermal/broadcom/sr-thermal.c
+++ b/drivers/thermal/broadcom/sr-thermal.c
@@ -32,7 +32,7 @@ struct sr_thermal {

static int sr_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct sr_tmon *tmon = tz->devdata;
+ struct sr_tmon *tmon = thermal_zone_device_get_data(tz);
struct sr_thermal *sr_thermal = tmon->priv;

*temp = readl(sr_thermal->regs + SR_TMON_TEMP_BASE(tmon->tmon_id));
diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c
index a805a6666c44..3d937f701e0b 100644
--- a/drivers/thermal/da9062-thermal.c
+++ b/drivers/thermal/da9062-thermal.c
@@ -123,7 +123,7 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data)
static int da9062_thermal_get_temp(struct thermal_zone_device *z,
int *temp)
{
- struct da9062_thermal *thermal = z->devdata;
+ struct da9062_thermal *thermal = thermal_zone_device_get_data(z);

mutex_lock(&thermal->lock);
*temp = thermal->temperature;
diff --git a/drivers/thermal/dove_thermal.c b/drivers/thermal/dove_thermal.c
index 056622a58d00..ed7d1173d9fd 100644
--- a/drivers/thermal/dove_thermal.c
+++ b/drivers/thermal/dove_thermal.c
@@ -87,7 +87,7 @@ static int dove_get_temp(struct thermal_zone_device *thermal,
int *temp)
{
unsigned long reg;
- struct dove_thermal_priv *priv = thermal->devdata;
+ struct dove_thermal_priv *priv = thermal_zone_device_get_data(thermal);

/* Valid check */
reg = readl_relaxed(priv->control + PMU_TEMP_DIOD_CTRL1_REG);
diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c
index 32a7c3cf073d..043751e6a31d 100644
--- a/drivers/thermal/hisi_thermal.c
+++ b/drivers/thermal/hisi_thermal.c
@@ -431,7 +431,7 @@ static int hi3660_thermal_probe(struct hisi_thermal_data *data)

static int hisi_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct hisi_thermal_sensor *sensor = tz->devdata;
+ struct hisi_thermal_sensor *sensor = thermal_zone_device_get_data(tz);
struct hisi_thermal_data *data = sensor->data;

*temp = data->ops->get_temp(sensor);
diff --git a/drivers/thermal/imx8mm_thermal.c b/drivers/thermal/imx8mm_thermal.c
index 72b5d6f319c1..750240f4fa32 100644
--- a/drivers/thermal/imx8mm_thermal.c
+++ b/drivers/thermal/imx8mm_thermal.c
@@ -141,7 +141,7 @@ static int imx8mp_tmu_get_temp(void *data, int *temp)

static int tmu_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct tmu_sensor *sensor = tz->devdata;
+ struct tmu_sensor *sensor = thermal_zone_device_get_data(tz);
struct imx8mm_tmu *tmu = sensor->priv;

return tmu->socdata->get_temp(sensor, temp);
diff --git a/drivers/thermal/imx_sc_thermal.c b/drivers/thermal/imx_sc_thermal.c
index f32e59e74623..ca10d6a68f0f 100644
--- a/drivers/thermal/imx_sc_thermal.c
+++ b/drivers/thermal/imx_sc_thermal.c
@@ -46,7 +46,7 @@ static int imx_sc_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
struct imx_sc_msg_misc_get_temp msg;
struct imx_sc_rpc_msg *hdr = &msg.hdr;
- struct imx_sc_sensor *sensor = tz->devdata;
+ struct imx_sc_sensor *sensor = thermal_zone_device_get_data(tz);
int ret;

msg.data.req.resource_id = sensor->resource_id;
diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index fb0d5cab70af..c3c14cd26aee 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -252,7 +252,7 @@ static void imx_set_alarm_temp(struct imx_thermal_data *data,

static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct imx_thermal_data *data = tz->devdata;
+ struct imx_thermal_data *data = thermal_zone_device_get_data(tz);
const struct thermal_soc_data *soc_data = data->socdata;
struct regmap *map = data->tempmon;
unsigned int n_meas;
@@ -311,7 +311,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
static int imx_change_mode(struct thermal_zone_device *tz,
enum thermal_device_mode mode)
{
- struct imx_thermal_data *data = tz->devdata;
+ struct imx_thermal_data *data = thermal_zone_device_get_data(tz);

if (mode == THERMAL_DEVICE_ENABLED) {
pm_runtime_get(data->dev);
@@ -342,7 +342,7 @@ static int imx_get_crit_temp(struct thermal_zone_device *tz, int *temp)
static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip,
int temp)
{
- struct imx_thermal_data *data = tz->devdata;
+ struct imx_thermal_data *data = thermal_zone_device_get_data(tz);
int ret;

ret = pm_runtime_resume_and_get(data->dev);
diff --git a/drivers/thermal/intel/intel_pch_thermal.c b/drivers/thermal/intel/intel_pch_thermal.c
index b855d031a855..e53f8a8c06e5 100644
--- a/drivers/thermal/intel/intel_pch_thermal.c
+++ b/drivers/thermal/intel/intel_pch_thermal.c
@@ -119,7 +119,7 @@ static int pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, int trip)

static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp)
{
- struct pch_thermal_device *ptd = tzd->devdata;
+ struct pch_thermal_device *ptd = thermal_zone_device_get_data(tzd);

*temp = GET_WPT_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TEMP));
return 0;
diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c
index 8c26f7b2316b..f7d995722e04 100644
--- a/drivers/thermal/intel/intel_soc_dts_iosf.c
+++ b/drivers/thermal/intel/intel_soc_dts_iosf.c
@@ -54,7 +54,7 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd, int trip,
struct intel_soc_dts_sensor_entry *dts;
struct intel_soc_dts_sensors *sensors;

- dts = tzd->devdata;
+ dts = thermal_zone_device_get_data(tzd);
sensors = dts->sensors;
mutex_lock(&sensors->dts_update_lock);
status = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ,
@@ -168,7 +168,7 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts,
static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
int temp)
{
- struct intel_soc_dts_sensor_entry *dts = tzd->devdata;
+ struct intel_soc_dts_sensor_entry *dts = thermal_zone_device_get_data(tzd);
struct intel_soc_dts_sensors *sensors = dts->sensors;
int status;

@@ -176,7 +176,7 @@ static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
return -EINVAL;

mutex_lock(&sensors->dts_update_lock);
- status = update_trip_temp(tzd->devdata, trip, temp,
+ status = update_trip_temp(dts, trip, temp,
dts->trip_types[trip]);
mutex_unlock(&sensors->dts_update_lock);

@@ -186,9 +186,7 @@ static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
static int sys_get_trip_type(struct thermal_zone_device *tzd,
int trip, enum thermal_trip_type *type)
{
- struct intel_soc_dts_sensor_entry *dts;
-
- dts = tzd->devdata;
+ struct intel_soc_dts_sensor_entry *dts = thermal_zone_device_get_data(tzd);

*type = dts->trip_types[trip];

@@ -200,11 +198,10 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd,
{
int status;
u32 out;
- struct intel_soc_dts_sensor_entry *dts;
+ struct intel_soc_dts_sensor_entry *dts = thermal_zone_device_get_data(tzd);
struct intel_soc_dts_sensors *sensors;
unsigned long raw;

- dts = tzd->devdata;
sensors = dts->sensors;
status = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ,
SOC_DTS_OFFSET_TEMP, &out);
diff --git a/drivers/thermal/intel/x86_pkg_temp_thermal.c b/drivers/thermal/intel/x86_pkg_temp_thermal.c
index 1c2de84742df..22f0f206d8f2 100644
--- a/drivers/thermal/intel/x86_pkg_temp_thermal.c
+++ b/drivers/thermal/intel/x86_pkg_temp_thermal.c
@@ -107,7 +107,7 @@ static struct zone_device *pkg_temp_thermal_get_dev(unsigned int cpu)

static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
{
- struct zone_device *zonedev = tzd->devdata;
+ struct zone_device *zonedev = thermal_zone_device_get_data(tzd);
int val;

val = intel_tcc_get_temp(zonedev->cpu, true);
@@ -122,7 +122,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
static int
sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
{
- struct zone_device *zonedev = tzd->devdata;
+ struct zone_device *zonedev = thermal_zone_device_get_data(tzd);
u32 l, h, mask, shift, intr;
int tj_max, ret;

diff --git a/drivers/thermal/k3_bandgap.c b/drivers/thermal/k3_bandgap.c
index 22c9bcb899c3..8cbd7361b492 100644
--- a/drivers/thermal/k3_bandgap.c
+++ b/drivers/thermal/k3_bandgap.c
@@ -141,7 +141,7 @@ static int k3_bgp_read_temp(struct k3_thermal_data *devdata,

static int k3_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct k3_thermal_data *data = tz->devdata;
+ struct k3_thermal_data *data = thermal_zone_device_get_data(tz);
int ret = 0;

ret = k3_bgp_read_temp(data, temp);
diff --git a/drivers/thermal/k3_j72xx_bandgap.c b/drivers/thermal/k3_j72xx_bandgap.c
index 031ea1091909..300a3f985776 100644
--- a/drivers/thermal/k3_j72xx_bandgap.c
+++ b/drivers/thermal/k3_j72xx_bandgap.c
@@ -248,7 +248,7 @@ static inline int k3_bgp_read_temp(struct k3_thermal_data *devdata,
/* Get temperature callback function for thermal zone */
static int k3_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
- return k3_bgp_read_temp(tz->devdata, temp);
+ return k3_bgp_read_temp(thermal_zone_device_get_data(tz), temp);
}

static const struct thermal_zone_device_ops k3_of_thermal_ops = {
diff --git a/drivers/thermal/kirkwood_thermal.c b/drivers/thermal/kirkwood_thermal.c
index bec7ec20e79d..8e39c875ba58 100644
--- a/drivers/thermal/kirkwood_thermal.c
+++ b/drivers/thermal/kirkwood_thermal.c
@@ -27,7 +27,7 @@ static int kirkwood_get_temp(struct thermal_zone_device *thermal,
int *temp)
{
unsigned long reg;
- struct kirkwood_thermal_priv *priv = thermal->devdata;
+ struct kirkwood_thermal_priv *priv = thermal_zone_device_get_data(thermal);

reg = readl_relaxed(priv->sensor);

diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c
index 6451a55eb582..05b6e9a2a283 100644
--- a/drivers/thermal/max77620_thermal.c
+++ b/drivers/thermal/max77620_thermal.c
@@ -46,7 +46,7 @@ struct max77620_therm_info {

static int max77620_thermal_read_temp(struct thermal_zone_device *tz, int *temp)
{
- struct max77620_therm_info *mtherm = tz->devdata;
+ struct max77620_therm_info *mtherm = thermal_zone_device_get_data(tz);
unsigned int val;
int ret;

diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c
index ab730f9552d0..d7bf725d224b 100644
--- a/drivers/thermal/mediatek/auxadc_thermal.c
+++ b/drivers/thermal/mediatek/auxadc_thermal.c
@@ -763,7 +763,7 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)

static int mtk_read_temp(struct thermal_zone_device *tz, int *temperature)
{
- struct mtk_thermal *mt = tz->devdata;
+ struct mtk_thermal *mt = thermal_zone_device_get_data(tz);
int i;
int tempmax = INT_MIN;

diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index 84ba65a27acf..86d280187c83 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -252,7 +252,7 @@ static u32 lvts_temp_to_raw(int temperature)

static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct lvts_sensor *lvts_sensor = tz->devdata;
+ struct lvts_sensor *lvts_sensor = thermal_zone_device_get_data(tz);
void __iomem *msr = lvts_sensor->msr;
u32 value;

@@ -290,7 +290,7 @@ static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)

static int lvts_set_trips(struct thermal_zone_device *tz, int low, int high)
{
- struct lvts_sensor *lvts_sensor = tz->devdata;
+ struct lvts_sensor *lvts_sensor = thermal_zone_device_get_data(tz);
void __iomem *base = lvts_sensor->base;
u32 raw_low = lvts_temp_to_raw(low);
u32 raw_high = lvts_temp_to_raw(high);
diff --git a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
index 31164ade2dd1..b0269daf128a 100644
--- a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
+++ b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
@@ -360,7 +360,7 @@ static irqreturn_t adc_tm5_gen2_isr(int irq, void *data)

static int adc_tm5_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct adc_tm5_channel *channel = tz->devdata;
+ struct adc_tm5_channel *channel = thermal_zone_device_get_data(tz);
int ret;

if (!channel || !channel->iio)
@@ -642,7 +642,7 @@ static int adc_tm5_gen2_configure(struct adc_tm5_channel *channel, int low, int

static int adc_tm5_set_trips(struct thermal_zone_device *tz, int low, int high)
{
- struct adc_tm5_channel *channel = tz->devdata;
+ struct adc_tm5_channel *channel = thermal_zone_device_get_data(tz);
struct adc_tm5_chip *chip;
int ret;

diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
index 101c75d0e13f..c817b03deb00 100644
--- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
+++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
@@ -187,7 +187,7 @@ static int qpnp_tm_update_temp_no_adc(struct qpnp_tm_chip *chip)

static int qpnp_tm_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct qpnp_tm_chip *chip = tz->devdata;
+ struct qpnp_tm_chip *chip = thermal_zone_device_get_data(tz);
int ret, mili_celsius;

if (!temp)
@@ -265,7 +265,7 @@ static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip,

static int qpnp_tm_set_trip_temp(struct thermal_zone_device *tz, int trip_id, int temp)
{
- struct qpnp_tm_chip *chip = tz->devdata;
+ struct qpnp_tm_chip *chip = thermal_zone_device_get_data(tz);
struct thermal_trip trip;
int ret;

diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index 431c29c0898a..8b6fe0c9ade2 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -83,7 +83,7 @@ static struct qoriq_tmu_data *qoriq_sensor_to_data(struct qoriq_sensor *s)

static int tmu_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct qoriq_sensor *qsensor = tz->devdata;
+ struct qoriq_sensor *qsensor = thermal_zone_device_get_data(tz);
struct qoriq_tmu_data *qdata = qoriq_sensor_to_data(qsensor);
u32 val;
/*
diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c
index d6b5b59c5c53..8ad713cb4bf7 100644
--- a/drivers/thermal/rcar_gen3_thermal.c
+++ b/drivers/thermal/rcar_gen3_thermal.c
@@ -167,7 +167,7 @@ static int rcar_gen3_thermal_round(int temp)

static int rcar_gen3_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct rcar_gen3_thermal_tsc *tsc = tz->devdata;
+ struct rcar_gen3_thermal_tsc *tsc = thermal_zone_device_get_data(tz);
int mcelsius, val;
int reg;

@@ -206,7 +206,7 @@ static int rcar_gen3_thermal_mcelsius_to_temp(struct rcar_gen3_thermal_tsc *tsc,

static int rcar_gen3_thermal_set_trips(struct thermal_zone_device *tz, int low, int high)
{
- struct rcar_gen3_thermal_tsc *tsc = tz->devdata;
+ struct rcar_gen3_thermal_tsc *tsc = thermal_zone_device_get_data(tz);
u32 irqmsk = 0;

if (low != -INT_MAX) {
diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
index 436f5f9cf729..538ed6731589 100644
--- a/drivers/thermal/rcar_thermal.c
+++ b/drivers/thermal/rcar_thermal.c
@@ -101,7 +101,6 @@ struct rcar_thermal_priv {
list_for_each_entry(pos, &common->head, list)

#define MCELSIUS(temp) ((temp) * 1000)
-#define rcar_zone_to_priv(zone) ((zone)->devdata)
#define rcar_priv_to_dev(priv) ((priv)->common->dev)
#define rcar_has_irq_support(priv) ((priv)->common->base)
#define rcar_id_to_shift(priv) ((priv)->id * 8)
@@ -273,7 +272,7 @@ static int rcar_thermal_get_current_temp(struct rcar_thermal_priv *priv,

static int rcar_thermal_get_temp(struct thermal_zone_device *zone, int *temp)
{
- struct rcar_thermal_priv *priv = rcar_zone_to_priv(zone);
+ struct rcar_thermal_priv *priv = thermal_zone_device_get_data(zone);

return rcar_thermal_get_current_temp(priv, temp);
}
diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c
index 4b7c43f34d1a..dafbdbb7c0c0 100644
--- a/drivers/thermal/rockchip_thermal.c
+++ b/drivers/thermal/rockchip_thermal.c
@@ -1213,7 +1213,7 @@ static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev)

static int rockchip_thermal_set_trips(struct thermal_zone_device *tz, int low, int high)
{
- struct rockchip_thermal_sensor *sensor = tz->devdata;
+ struct rockchip_thermal_sensor *sensor = thermal_zone_device_get_data(tz);
struct rockchip_thermal_data *thermal = sensor->thermal;
const struct rockchip_tsadc_chip *tsadc = thermal->chip;

@@ -1226,7 +1226,7 @@ static int rockchip_thermal_set_trips(struct thermal_zone_device *tz, int low, i

static int rockchip_thermal_get_temp(struct thermal_zone_device *tz, int *out_temp)
{
- struct rockchip_thermal_sensor *sensor = tz->devdata;
+ struct rockchip_thermal_sensor *sensor = thermal_zone_device_get_data(tz);
struct rockchip_thermal_data *thermal = sensor->thermal;
const struct rockchip_tsadc_chip *tsadc = sensor->thermal->chip;
int retval;
diff --git a/drivers/thermal/rzg2l_thermal.c b/drivers/thermal/rzg2l_thermal.c
index 2e0649f38506..d3ba2a74e42d 100644
--- a/drivers/thermal/rzg2l_thermal.c
+++ b/drivers/thermal/rzg2l_thermal.c
@@ -75,7 +75,7 @@ static inline void rzg2l_thermal_write(struct rzg2l_thermal_priv *priv, u32 reg,

static int rzg2l_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct rzg2l_thermal_priv *priv = tz->devdata;
+ struct rzg2l_thermal_priv *priv = thermal_zone_device_get_data(tz);
u32 result = 0, dsensor, ts_code_ave;
int val, i;

diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
index 527d1eb0663a..a2301e235a2b 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -645,7 +645,7 @@ static void exynos7_tmu_control(struct platform_device *pdev, bool on)

static int exynos_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct exynos_tmu_data *data = tz->devdata;
+ struct exynos_tmu_data *data = thermal_zone_device_get_data(tz);
int value, ret = 0;

if (!data || !data->tmu_read)
@@ -723,7 +723,7 @@ static void exynos4412_tmu_set_emulation(struct exynos_tmu_data *data,

static int exynos_tmu_set_emulation(struct thermal_zone_device *tz, int temp)
{
- struct exynos_tmu_data *data = tz->devdata;
+ struct exynos_tmu_data *data = thermal_zone_device_get_data(tz);
int ret = -EINVAL;

if (data->soc == SOC_ARCH_EXYNOS4210)
diff --git a/drivers/thermal/spear_thermal.c b/drivers/thermal/spear_thermal.c
index 6a722b10d738..62cd9305eb9c 100644
--- a/drivers/thermal/spear_thermal.c
+++ b/drivers/thermal/spear_thermal.c
@@ -31,7 +31,7 @@ struct spear_thermal_dev {
static inline int thermal_get_temp(struct thermal_zone_device *thermal,
int *temp)
{
- struct spear_thermal_dev *stdev = thermal->devdata;
+ struct spear_thermal_dev *stdev = thermal_zone_device_get_data(thermal);

/*
* Data are ready to be read after 628 usec from POWERDOWN signal
@@ -48,7 +48,7 @@ static struct thermal_zone_device_ops ops = {
static int __maybe_unused spear_thermal_suspend(struct device *dev)
{
struct thermal_zone_device *spear_thermal = dev_get_drvdata(dev);
- struct spear_thermal_dev *stdev = spear_thermal->devdata;
+ struct spear_thermal_dev *stdev = thermal_zone_device_get_data(spear_thermal);
unsigned int actual_mask = 0;

/* Disable SPEAr Thermal Sensor */
@@ -64,7 +64,7 @@ static int __maybe_unused spear_thermal_suspend(struct device *dev)
static int __maybe_unused spear_thermal_resume(struct device *dev)
{
struct thermal_zone_device *spear_thermal = dev_get_drvdata(dev);
- struct spear_thermal_dev *stdev = spear_thermal->devdata;
+ struct spear_thermal_dev *stdev = thermal_zone_device_get_data(spear_thermal);
unsigned int actual_mask = 0;
int ret = 0;

@@ -154,7 +154,7 @@ static int spear_thermal_exit(struct platform_device *pdev)
{
unsigned int actual_mask = 0;
struct thermal_zone_device *spear_thermal = platform_get_drvdata(pdev);
- struct spear_thermal_dev *stdev = spear_thermal->devdata;
+ struct spear_thermal_dev *stdev = thermal_zone_device_get_data(spear_thermal);

thermal_zone_device_unregister(spear_thermal);

diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c
index ac884514f116..69078a55dc0c 100644
--- a/drivers/thermal/sprd_thermal.c
+++ b/drivers/thermal/sprd_thermal.c
@@ -206,7 +206,7 @@ static int sprd_thm_temp_to_rawdata(int temp, struct sprd_thermal_sensor *sen)

static int sprd_thm_read_temp(struct thermal_zone_device *tz, int *temp)
{
- struct sprd_thermal_sensor *sen = tz->devdata;
+ struct sprd_thermal_sensor *sen = thermal_zone_device_get_data(tz);
u32 data;

data = readl(sen->data->base + SPRD_THM_TEMP(sen->id)) &
diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c
index 497beac63e5d..085b7b0b7c72 100644
--- a/drivers/thermal/sun8i_thermal.c
+++ b/drivers/thermal/sun8i_thermal.c
@@ -110,7 +110,7 @@ static int sun50i_h5_calc_temp(struct ths_device *tmdev,

static int sun8i_ths_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct tsensor *s = tz->devdata;
+ struct tsensor *s = thermal_zone_device_get_data(tz);
struct ths_device *tmdev = s->tmdev;
int val = 0;

diff --git a/drivers/thermal/tegra/tegra-bpmp-thermal.c b/drivers/thermal/tegra/tegra-bpmp-thermal.c
index 0b7a1a1948cb..31a660b009fc 100644
--- a/drivers/thermal/tegra/tegra-bpmp-thermal.c
+++ b/drivers/thermal/tegra/tegra-bpmp-thermal.c
@@ -62,12 +62,14 @@ static int __tegra_bpmp_thermal_get_temp(struct tegra_bpmp_thermal_zone *zone,

static int tegra_bpmp_thermal_get_temp(struct thermal_zone_device *tz, int *out_temp)
{
- return __tegra_bpmp_thermal_get_temp(tz->devdata, out_temp);
+ struct tegra_bpmp_thermal_zone *zone = thermal_zone_device_get_data(tz);
+
+ return __tegra_bpmp_thermal_get_temp(zone, out_temp);
}

static int tegra_bpmp_thermal_set_trips(struct thermal_zone_device *tz, int low, int high)
{
- struct tegra_bpmp_thermal_zone *zone = tz->devdata;
+ struct tegra_bpmp_thermal_zone *zone = thermal_zone_device_get_data(tz);
struct mrq_thermal_host_to_bpmp_request req;
struct tegra_bpmp_message msg;
int err;
diff --git a/drivers/thermal/tegra/tegra30-tsensor.c b/drivers/thermal/tegra/tegra30-tsensor.c
index b3218b71b6d9..537413acc6d2 100644
--- a/drivers/thermal/tegra/tegra30-tsensor.c
+++ b/drivers/thermal/tegra/tegra30-tsensor.c
@@ -160,7 +160,7 @@ static void devm_tegra_tsensor_hw_disable(void *data)

static int tegra_tsensor_get_temp(struct thermal_zone_device *tz, int *temp)
{
- const struct tegra_tsensor_channel *tsc = tz->devdata;
+ const struct tegra_tsensor_channel *tsc = thermal_zone_device_get_data(tz);
const struct tegra_tsensor *ts = tsc->ts;
int err, c1, c2, c3, c4, counter;
u32 val;
@@ -218,7 +218,7 @@ static int tegra_tsensor_temp_to_counter(const struct tegra_tsensor *ts, int tem

static int tegra_tsensor_set_trips(struct thermal_zone_device *tz, int low, int high)
{
- const struct tegra_tsensor_channel *tsc = tz->devdata;
+ const struct tegra_tsensor_channel *tsc = thermal_zone_device_get_data(tz);
const struct tegra_tsensor *ts = tsc->ts;
u32 val;

diff --git a/drivers/thermal/thermal-generic-adc.c b/drivers/thermal/thermal-generic-adc.c
index 323e273e3298..8e2ff0df7e64 100644
--- a/drivers/thermal/thermal-generic-adc.c
+++ b/drivers/thermal/thermal-generic-adc.c
@@ -54,7 +54,7 @@ static int gadc_thermal_adc_to_temp(struct gadc_thermal_info *gti, int val)

static int gadc_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
- struct gadc_thermal_info *gti = tz->devdata;
+ struct gadc_thermal_info *gti = thermal_zone_device_get_data(tz);
int val;
int ret;

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 0675df54c8e6..05e5a6bda695 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1378,6 +1378,12 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, int n
}
EXPORT_SYMBOL_GPL(thermal_zone_device_register);

+void *thermal_zone_device_get_data(struct thermal_zone_device *tzd)
+{
+ return tzd->devdata;
+}
+EXPORT_SYMBOL_GPL(thermal_zone_device_get_data);
+
/**
* thermal_zone_device_unregister - removes the registered thermal zone device
* @tz: the thermal zone device to remove
diff --git a/drivers/thermal/thermal_mmio.c b/drivers/thermal/thermal_mmio.c
index ea616731066c..05a70205f86f 100644
--- a/drivers/thermal/thermal_mmio.c
+++ b/drivers/thermal/thermal_mmio.c
@@ -23,7 +23,7 @@ static u32 thermal_mmio_readb(void __iomem *mmio_base)
static int thermal_mmio_get_temperature(struct thermal_zone_device *tz, int *temp)
{
int t;
- struct thermal_mmio *sensor = tz->devdata;
+ struct thermal_mmio *sensor = thermal_zone_device_get_data(tz);

t = sensor->read_mmio(sensor->mmio_base) & sensor->mask;
t *= sensor->factor;
diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
index 8a9055bd376e..7f6b71d11eed 100644
--- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
+++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
@@ -68,7 +68,7 @@ static inline int ti_thermal_hotspot_temperature(int t, int s, int c)
static inline int __ti_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
struct thermal_zone_device *pcb_tz = NULL;
- struct ti_thermal_data *data = tz->devdata;
+ struct ti_thermal_data *data = thermal_zone_device_get_data(tz);
struct ti_bandgap *bgp;
const struct ti_temp_sensor *s;
int ret, tmp, slope, constant;
@@ -109,7 +109,7 @@ static inline int __ti_thermal_get_temp(struct thermal_zone_device *tz, int *tem

static int __ti_thermal_get_trend(struct thermal_zone_device *tz, int trip, enum thermal_trend *trend)
{
- struct ti_thermal_data *data = tz->devdata;
+ struct ti_thermal_data *data = thermal_zone_device_get_data(tz);
struct ti_bandgap *bgp;
int id, tr, ret = 0;

diff --git a/drivers/thermal/uniphier_thermal.c b/drivers/thermal/uniphier_thermal.c
index 47801841b3f5..25247de7780c 100644
--- a/drivers/thermal/uniphier_thermal.c
+++ b/drivers/thermal/uniphier_thermal.c
@@ -187,7 +187,7 @@ static void uniphier_tm_disable_sensor(struct uniphier_tm_dev *tdev)

static int uniphier_tm_get_temp(struct thermal_zone_device *tz, int *out_temp)
{
- struct uniphier_tm_dev *tdev = tz->devdata;
+ struct uniphier_tm_dev *tdev = thermal_zone_device_get_data(tz);
struct regmap *map = tdev->regmap;
int ret;
u32 temp;
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 2bb4bf33f4f3..724b95662da9 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -365,6 +365,8 @@ thermal_zone_device_register_with_trips(const char *, struct thermal_trip *, int
void *, struct thermal_zone_device_ops *,
struct thermal_zone_params *, int, int);

+void *thermal_zone_device_get_data(struct thermal_zone_device *tzd);
+
int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
struct thermal_cooling_device *,
unsigned long, unsigned long,
--
2.34.1


2023-02-19 14:39:35

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 06/17] thermal: Don't use 'device' internal thermal zone structure field

Some drivers are directly using the thermal zone's 'device' structure
field.

Use the driver device pointer instead of the thermal zone device when
it is available.

Remove the traces when they are duplicate with the traces in the core
code.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/thermal/imx_thermal.c | 37 ++++---------------
drivers/thermal/mediatek/lvts_thermal.c | 4 +-
drivers/thermal/thermal_hwmon.c | 4 +-
.../ti-soc-thermal/ti-thermal-common.c | 2 +-
4 files changed, 13 insertions(+), 34 deletions(-)

diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index f621b778b0f0..ae411477d3db 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -285,13 +285,13 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
if (data->alarm_temp == trips[IMX_TRIP_CRITICAL].temperature &&
*temp < trips[IMX_TRIP_PASSIVE].temperature) {
imx_set_alarm_temp(data, trips[IMX_TRIP_PASSIVE].temperature);
- dev_dbg(&tz->device, "thermal alarm off: T < %d\n",
+ dev_dbg(data->dev, "thermal alarm off: T < %d\n",
data->alarm_temp / 1000);
}
}

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

@@ -367,36 +367,16 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip,
static int imx_bind(struct thermal_zone_device *tz,
struct thermal_cooling_device *cdev)
{
- int ret;
-
- ret = thermal_zone_bind_cooling_device(tz, IMX_TRIP_PASSIVE, cdev,
- THERMAL_NO_LIMIT,
- THERMAL_NO_LIMIT,
- THERMAL_WEIGHT_DEFAULT);
- if (ret) {
- dev_err(&tz->device,
- "binding zone %s with cdev %s failed:%d\n",
- tz->type, cdev->type, ret);
- return ret;
- }
-
- return 0;
+ return thermal_zone_bind_cooling_device(tz, IMX_TRIP_PASSIVE, cdev,
+ THERMAL_NO_LIMIT,
+ THERMAL_NO_LIMIT,
+ THERMAL_WEIGHT_DEFAULT);
}

static int imx_unbind(struct thermal_zone_device *tz,
struct thermal_cooling_device *cdev)
{
- int ret;
-
- ret = thermal_zone_unbind_cooling_device(tz, IMX_TRIP_PASSIVE, cdev);
- if (ret) {
- dev_err(&tz->device,
- "unbinding zone %s with cdev %s failed:%d\n",
- tz->type, cdev->type, ret);
- return ret;
- }
-
- return 0;
+ return thermal_zone_unbind_cooling_device(tz, IMX_TRIP_PASSIVE, cdev);
}

static struct thermal_zone_device_ops imx_tz_ops = {
@@ -558,8 +538,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 > %d\n",
- data->alarm_temp / 1000);
+ dev_dbg(data->dev, "THERMAL ALARM: T > %d\n", data->alarm_temp / 1000);

thermal_zone_device_update(data->tz, THERMAL_EVENT_UNSPECIFIED);

diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index 86d280187c83..a65a81114cc5 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -305,7 +305,7 @@ static int lvts_set_trips(struct thermal_zone_device *tz, int low, int high)
* 14-0 : Raw temperature for threshold
*/
if (low != -INT_MAX) {
- dev_dbg(&tz->device, "Setting low limit temperature interrupt: %d\n", low);
+ pr_debug("%s: Setting low limit temperature interrupt: %d\n", tz->type, low);
writel(raw_low, LVTS_H2NTHRE(base));
}

@@ -318,7 +318,7 @@ static int lvts_set_trips(struct thermal_zone_device *tz, int low, int high)
*
* 14-0 : Raw temperature for threshold
*/
- dev_dbg(&tz->device, "Setting high limit temperature interrupt: %d\n", high);
+ pr_debug("%s: Setting high limit temperature interrupt: %d\n", tz->type, high);
writel(raw_high, LVTS_HTHRE(base));

return 0;
diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
index 964db7941e31..bc02095b314c 100644
--- a/drivers/thermal/thermal_hwmon.c
+++ b/drivers/thermal/thermal_hwmon.c
@@ -228,14 +228,14 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
hwmon = thermal_hwmon_lookup_by_type(tz);
if (unlikely(!hwmon)) {
/* Should never happen... */
- dev_dbg(&tz->device, "hwmon device lookup failed!\n");
+ dev_dbg(hwmon->device, "hwmon device lookup failed!\n");
return;
}

temp = thermal_hwmon_lookup_temp(hwmon, tz);
if (unlikely(!temp)) {
/* Should never happen... */
- dev_dbg(&tz->device, "temperature input lookup failed!\n");
+ dev_dbg(hwmon->device, "temperature input lookup failed!\n");
return;
}

diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
index 9fb1ca5e39f6..8586cfe92df6 100644
--- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
+++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
@@ -43,7 +43,7 @@ static void ti_thermal_work(struct work_struct *work)

thermal_zone_device_update(data->ti_thermal, THERMAL_EVENT_UNSPECIFIED);

- dev_dbg(&data->ti_thermal->device, "updated thermal zone %s\n",
+ dev_dbg(data->bgp->dev, "updated thermal zone %s\n",
data->ti_thermal->type);
}

--
2.34.1


2023-02-19 14:39:36

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 09/17] thermal: Add a thermal zone id accessor

In order to get the thermal zone id but without directly accessing the
thermal zone device structure, add an accessor.

Use the accessor from the hwmon_scmi

No functional change intented.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/hwmon/scmi-hwmon.c | 2 +-
drivers/thermal/thermal_core.c | 6 ++++++
include/linux/thermal.h | 2 ++
3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
index 7951b6026f48..036b56a535c1 100644
--- a/drivers/hwmon/scmi-hwmon.c
+++ b/drivers/hwmon/scmi-hwmon.c
@@ -220,7 +220,7 @@ static int scmi_thermal_sensor_register(struct device *dev,
sensor->name);
} else {
dev_dbg(dev, "Sensor '%s' attached to thermal zone ID:%d\n",
- sensor->name, tzd->id);
+ sensor->name, thermal_zone_device_get_id(tzd));
}

return 0;
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 05e5a6bda695..e06c76b38c04 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1384,6 +1384,12 @@ void *thermal_zone_device_get_data(struct thermal_zone_device *tzd)
}
EXPORT_SYMBOL_GPL(thermal_zone_device_get_data);

+int thermal_zone_device_get_id(struct thermal_zone_device *tzd)
+{
+ return tzd->id;
+}
+EXPORT_SYMBOL_GPL(thermal_zone_device_get_id);
+
/**
* thermal_zone_device_unregister - removes the registered thermal zone device
* @tz: the thermal zone device to remove
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 724b95662da9..9e5c7f2f7b05 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -367,6 +367,8 @@ thermal_zone_device_register_with_trips(const char *, struct thermal_trip *, int

void *thermal_zone_device_get_data(struct thermal_zone_device *tzd);

+int thermal_zone_device_get_id(struct thermal_zone_device *tzd);
+
int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
struct thermal_cooling_device *,
unsigned long, unsigned long,
--
2.34.1


2023-02-19 14:39:37

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 11/17] thermal/drivers/da9062: Don't access the thermal zone device fields

The driver is reading the passive polling rate in the thermal zone
structure. We want to prevent the drivers to rummage around in the
thermal zone structure.

On the other side, the delay is what the driver passed to the
thermal_zone_device_register() function, so it has already the
information.

Reuse the information we have instead of reading the information we
set.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/thermal/da9062-thermal.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c
index 3d937f701e0b..2294938bb496 100644
--- a/drivers/thermal/da9062-thermal.c
+++ b/drivers/thermal/da9062-thermal.c
@@ -41,6 +41,8 @@

#define DA9062_MILLI_CELSIUS(t) ((t) * 1000)

+static unsigned int pp_tmp = DA9062_DEFAULT_POLLING_MS_PERIOD;
+
struct da9062_thermal_config {
const char *name;
};
@@ -95,7 +97,10 @@ static void da9062_thermal_poll_on(struct work_struct *work)
thermal_zone_device_update(thermal->zone,
THERMAL_EVENT_UNSPECIFIED);

- delay = thermal->zone->passive_delay_jiffies;
+ /*
+ * pp_tmp is between 1s and 10s, so we can round the jiffies
+ */
+ delay = round_jiffies(msecs_to_jiffies(pp_tmp));
queue_delayed_work(system_freezable_wq, &thermal->work, delay);
return;
}
@@ -155,7 +160,6 @@ static int da9062_thermal_probe(struct platform_device *pdev)
{
struct da9062 *chip = dev_get_drvdata(pdev->dev.parent);
struct da9062_thermal *thermal;
- unsigned int pp_tmp = DA9062_DEFAULT_POLLING_MS_PERIOD;
const struct of_device_id *match;
int ret = 0;

@@ -208,8 +212,7 @@ static int da9062_thermal_probe(struct platform_device *pdev)
}

dev_dbg(&pdev->dev,
- "TJUNC temperature polling period set at %d ms\n",
- jiffies_to_msecs(thermal->zone->passive_delay_jiffies));
+ "TJUNC temperature polling period set at %d ms\n", pp_tmp);

ret = platform_get_irq_byname(pdev, "THERMAL");
if (ret < 0)
--
2.34.1


2023-02-19 14:39:37

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 12/17] thermal/hwmon: Use the thermal_core.h header

The thermal_hwmon is playing with the thermal core code
internals. Changing the code would be too invasive for now.

We can consider the thermal_hwmon.c is part of the thermal core code
as it provides a glue to tie the hwmon and the thermal zones.

Let's include the thermal_core.h header.

No functional change intended.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/thermal/thermal_hwmon.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
index 15158715b967..e1b9e95deade 100644
--- a/drivers/thermal/thermal_hwmon.c
+++ b/drivers/thermal/thermal_hwmon.c
@@ -17,6 +17,7 @@
#include <linux/thermal.h>

#include "thermal_hwmon.h"
+#include "thermal_core.h"

/* hwmon sys I/F */
/* thermal zone devices with the same type share one hwmon device */
--
2.34.1


2023-02-19 14:39:37

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 10/17] thermal: Do not access 'type' field, use the tz id instead

The 'type' field is used as a name in the message. However we can have
multiple thermal zone with the same type. The information is not
accurate.

Moreover, the thermal zone device structure is directly accessed while
we want to improve the self-encapsulation of the code.

Replace the 'type' in the message by the thermal zone id.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/acpi/thermal.c | 2 +-
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 4 ++--
drivers/thermal/mediatek/lvts_thermal.c | 5 +----
drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 4 ++--
4 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 69d0da6456d5..4b5afaf843e2 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -842,7 +842,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
goto acpi_bus_detach;

dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
- tz->thermal_zone->id);
+ thermal_zone_device_get_id(tz->thermal_zone));

return 0;

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
index 228b6ffaef98..8dbb1c15b842 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
@@ -176,8 +176,8 @@ mlxsw_thermal_module_trips_update(struct device *dev, struct mlxsw_core *core,
}

if (crit_temp > emerg_temp) {
- dev_warn(dev, "%s : Critical threshold %d is above emergency threshold %d\n",
- tz->tzdev->type, crit_temp, emerg_temp);
+ dev_warn(dev, "tz id %d: Critical threshold %d is above emergency threshold %d\n",
+ thermal_zone_device_get_id(tz->tzdev), crit_temp, emerg_temp);
return 0;
}

diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index a65a81114cc5..90aab92a4185 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -304,10 +304,8 @@ static int lvts_set_trips(struct thermal_zone_device *tz, int low, int high)
*
* 14-0 : Raw temperature for threshold
*/
- if (low != -INT_MAX) {
- pr_debug("%s: Setting low limit temperature interrupt: %d\n", tz->type, low);
+ if (low != -INT_MAX)
writel(raw_low, LVTS_H2NTHRE(base));
- }

/*
* Hot temperature threshold
@@ -318,7 +316,6 @@ static int lvts_set_trips(struct thermal_zone_device *tz, int low, int high)
*
* 14-0 : Raw temperature for threshold
*/
- pr_debug("%s: Setting high limit temperature interrupt: %d\n", tz->type, high);
writel(raw_high, LVTS_HTHRE(base));

return 0;
diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
index 8586cfe92df6..eda6d3af7b67 100644
--- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
+++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
@@ -43,8 +43,8 @@ static void ti_thermal_work(struct work_struct *work)

thermal_zone_device_update(data->ti_thermal, THERMAL_EVENT_UNSPECIFIED);

- dev_dbg(data->bgp->dev, "updated thermal zone %s\n",
- data->ti_thermal->type);
+ dev_dbg(data->bgp->dev, "updated thermal zone id %d\n",
+ thermal_zone_device_get_id(data->ti_thermal));
}

/**
--
2.34.1


2023-02-19 14:39:37

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 07/17] thermal/hwmon: Use the thermal API instead tampering the internals

In this function, there is a guarantee the thermal zone is registered.

The sysfs hwmon unregistering will be blocked until we exit the
function. The thermal zone is unregistered after the sysfs hwmon is
unregistered.

When we are in this function, the thermal zone is registered.

We can call the thermal_zone_get_crit_temp() function safely and let
the function use the lock which is private the thermal core code.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/thermal/thermal_hwmon.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
index bc02095b314c..15158715b967 100644
--- a/drivers/thermal/thermal_hwmon.c
+++ b/drivers/thermal/thermal_hwmon.c
@@ -77,15 +77,7 @@ temp_crit_show(struct device *dev, struct device_attribute *attr, char *buf)
int temperature;
int ret;

- mutex_lock(&tz->lock);
-
- if (device_is_registered(&tz->device))
- ret = tz->ops->get_crit_temp(tz, &temperature);
- else
- ret = -ENODEV;
-
- mutex_unlock(&tz->lock);
-
+ ret = thermal_zone_get_crit_temp(tz, &temperature);
if (ret)
return ret;

--
2.34.1


2023-02-19 14:39:37

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 13/17] thermal/drivers/tegra: Remove unneeded lock when setting a trip point

The function tegra_tsensor_enable_hw_channel() takes the thermal zone
lock to prevent "a potential" race with a call to set_trips()
callback.

The driver must not play with the thermal framework core code
internals.

The tegra_tsensor_enable_hw_channel() is called by:

- the suspend / resume callbacks
- the probe function after the thermal zones are registered

The thermal zone lock taken in this function is supposed to protect
from a call to the set_trips() callback which writes in the same
register.

The potential race is when suspend / resume are called at the same
time as set_trips. This one is called only in
thermal_zone_device_update().

- At suspend time, the 'in_suspend' is set, thus the
thermal_zone_device_update() bails out immediately and set_trips is
not called during this moment.

- At resume time, the thermal zone is updated at PM_POST_SUSPEND,
thus the driver has already set the TH2 temperature.

- At probe time, we register the thermal zone and then we set the
TH2. The only scenario I can see so far is the interrupt fires, the
thermal_zone_update() is called exactly at the moment
tegra_tsensor_enable_hw_channel() a few lines after registering it.

Disable the interrupt before setting up the hw channels and then
enable it. We close the potential race window without using the
thermal zone's lock.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/thermal/tegra/tegra30-tsensor.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/thermal/tegra/tegra30-tsensor.c b/drivers/thermal/tegra/tegra30-tsensor.c
index ceb5b1b338a9..9cf74208673f 100644
--- a/drivers/thermal/tegra/tegra30-tsensor.c
+++ b/drivers/thermal/tegra/tegra30-tsensor.c
@@ -359,9 +359,6 @@ static int tegra_tsensor_enable_hw_channel(const struct tegra_tsensor *ts,

tegra_tsensor_get_hw_channel_trips(tzd, &hot_trip, &crit_trip);

- /* prevent potential racing with tegra_tsensor_set_trips() */
- mutex_lock(&tzd->lock);
-
dev_info_once(ts->dev, "ch%u: PMC emergency shutdown trip set to %dC\n",
id, DIV_ROUND_CLOSEST(crit_trip, 1000));

@@ -404,8 +401,6 @@ static int tegra_tsensor_enable_hw_channel(const struct tegra_tsensor *ts,
val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG0_INTR_THERMAL_RST_EN, 1);
writel_relaxed(val, tsc->regs + TSENSOR_SENSOR0_CONFIG0);

- mutex_unlock(&tzd->lock);
-
err = thermal_zone_device_enable(tzd);
if (err) {
dev_err(ts->dev, "ch%u: failed to enable zone: %d\n", id, err);
@@ -592,12 +587,24 @@ static int tegra_tsensor_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, err,
"failed to request interrupt\n");

+ /*
+ * Disable the interrupt so set_trips() can not be called
+ * while we are setting up the register
+ * TSENSOR_SENSOR0_CONFIG1. With this we close a potential
+ * race window where we are setting up the TH2 and the
+ * temperature hits TH1 resulting to an update of the
+ * TSENSOR_SENSOR0_CONFIG1 register in the ISR.
+ */
+ disable_irq(irq);
+
for (i = 0; i < ARRAY_SIZE(ts->ch); i++) {
err = tegra_tsensor_enable_hw_channel(ts, i);
if (err)
return err;
}

+ enable_irq(irq);
+
return 0;
}

--
2.34.1


2023-02-19 14:39:37

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 08/17] thermal/drivers/spear: Don't use tz->device but pdev->dev

Use the spear associated device instead of the thermal zone device
which belongs to the thermal framework internals.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/thermal/spear_thermal.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/thermal/spear_thermal.c b/drivers/thermal/spear_thermal.c
index 62cd9305eb9c..4598dedb82ec 100644
--- a/drivers/thermal/spear_thermal.c
+++ b/drivers/thermal/spear_thermal.c
@@ -137,7 +137,7 @@ static int spear_thermal_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, spear_thermal);

- dev_info(&spear_thermal->device, "Thermal Sensor Loaded at: 0x%p.\n",
+ dev_info(&pdev->dev, "Thermal Sensor Loaded at: 0x%p.\n",
stdev->thermal_base);

return 0;
--
2.34.1


2023-02-19 14:40:06

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 14/17] thermal/tegra: Do not enable the thermal zone, it is already enabled

The code enables the thermal zone after setting it up. But the thermal
zone is already enabled by thermal_of_zone_register() function.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/thermal/tegra/tegra30-tsensor.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/thermal/tegra/tegra30-tsensor.c b/drivers/thermal/tegra/tegra30-tsensor.c
index 9cf74208673f..5b87b83a00aa 100644
--- a/drivers/thermal/tegra/tegra30-tsensor.c
+++ b/drivers/thermal/tegra/tegra30-tsensor.c
@@ -346,7 +346,7 @@ static int tegra_tsensor_enable_hw_channel(const struct tegra_tsensor *ts,
{
const struct tegra_tsensor_channel *tsc = &ts->ch[id];
struct thermal_zone_device *tzd = tsc->tzd;
- int err, hot_trip = 0, crit_trip = 0;
+ int hot_trip = 0, crit_trip = 0;
u32 val;

if (!tzd) {
@@ -401,12 +401,6 @@ static int tegra_tsensor_enable_hw_channel(const struct tegra_tsensor *ts,
val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG0_INTR_THERMAL_RST_EN, 1);
writel_relaxed(val, tsc->regs + TSENSOR_SENSOR0_CONFIG0);

- err = thermal_zone_device_enable(tzd);
- if (err) {
- dev_err(ts->dev, "ch%u: failed to enable zone: %d\n", id, err);
- return err;
- }
-
return 0;
}

--
2.34.1


2023-02-19 14:40:06

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 17/17] thermal/traces: Replace the thermal zone structure parameter with the field value

In the work of the thermal zone device self-encapsulation, let's pass
the field value instead of dereferencing them in the traces which
force us to export publicly the thermal_zone_device structure.

No fonctionnal change intended.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/thermal/gov_fair_share.c | 2 +-
drivers/thermal/gov_power_allocator.c | 4 ++--
drivers/thermal/gov_step_wise.c | 2 +-
drivers/thermal/thermal_core.c | 5 ++--
include/trace/events/thermal.h | 24 +++++++++----------
.../trace/events/thermal_power_allocator.h | 12 +++++-----
6 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/drivers/thermal/gov_fair_share.c b/drivers/thermal/gov_fair_share.c
index aad7d5fe3a14..e6c21abaaa80 100644
--- a/drivers/thermal/gov_fair_share.c
+++ b/drivers/thermal/gov_fair_share.c
@@ -35,7 +35,7 @@ static int get_trip_level(struct thermal_zone_device *tz)
* point, in which case, trip_point = count - 1
*/
if (count > 0)
- trace_thermal_zone_trip(tz, count - 1, trip.type);
+ trace_thermal_zone_trip(tz->type, tz->id, count - 1, trip.type);

return count;
}
diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c
index 0eaf1527d3e3..aaa8b57434ef 100644
--- a/drivers/thermal/gov_power_allocator.c
+++ b/drivers/thermal/gov_power_allocator.c
@@ -266,7 +266,7 @@ static u32 pid_controller(struct thermal_zone_device *tz,

power_range = clamp(power_range, (s64)0, (s64)max_allocatable_power);

- trace_thermal_power_allocator_pid(tz, frac_to_int(err),
+ trace_thermal_power_allocator_pid(tz->id, frac_to_int(err),
frac_to_int(params->err_integral),
frac_to_int(p), frac_to_int(i),
frac_to_int(d), power_range);
@@ -481,7 +481,7 @@ static int allocate_power(struct thermal_zone_device *tz,
i++;
}

- trace_thermal_power_allocator(tz, req_power, total_req_power,
+ trace_thermal_power_allocator(tz->id, req_power, total_req_power,
granted_power, total_granted_power,
num_actors, power_range,
max_allocatable_power, tz->temperature,
diff --git a/drivers/thermal/gov_step_wise.c b/drivers/thermal/gov_step_wise.c
index 31235e169c5a..f469e04770fe 100644
--- a/drivers/thermal/gov_step_wise.c
+++ b/drivers/thermal/gov_step_wise.c
@@ -109,7 +109,7 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id

if (tz->temperature >= trip.temperature) {
throttle = true;
- trace_thermal_zone_trip(tz, trip_id, trip.type);
+ trace_thermal_zone_trip(tz->type, tz->id, trip_id, trip.type);
}

dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n",
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index e06c76b38c04..0f6af8ab2f41 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -336,7 +336,7 @@ static void handle_critical_trips(struct thermal_zone_device *tz,
if (trip_temp <= 0 || tz->temperature < trip_temp)
return;

- trace_thermal_zone_trip(tz, trip, trip_type);
+ trace_thermal_zone_trip(tz->type, tz->id, trip, trip_type);

if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot)
tz->ops->hot(tz);
@@ -387,7 +387,8 @@ static void update_temperature(struct thermal_zone_device *tz)
tz->last_temperature = tz->temperature;
tz->temperature = temp;

- trace_thermal_temperature(tz);
+ trace_thermal_temperature(tz->type, tz->id,
+ tz->last_temperature, tz->temperature);

thermal_genl_sampling_temp(tz->id, temp);
}
diff --git a/include/trace/events/thermal.h b/include/trace/events/thermal.h
index e58bf3072f32..50c7d2e1526d 100644
--- a/include/trace/events/thermal.h
+++ b/include/trace/events/thermal.h
@@ -23,22 +23,22 @@ TRACE_DEFINE_ENUM(THERMAL_TRIP_ACTIVE);

TRACE_EVENT(thermal_temperature,

- TP_PROTO(struct thermal_zone_device *tz),
+ TP_PROTO(const char *type, int id, int temp_prev, int temp),

- TP_ARGS(tz),
+ TP_ARGS(type, id, temp_prev, temp),

TP_STRUCT__entry(
- __string(thermal_zone, tz->type)
+ __string(thermal_zone, type)
__field(int, id)
__field(int, temp_prev)
__field(int, temp)
),

TP_fast_assign(
- __assign_str(thermal_zone, tz->type);
- __entry->id = tz->id;
- __entry->temp_prev = tz->last_temperature;
- __entry->temp = tz->temperature;
+ __assign_str(thermal_zone, type);
+ __entry->id = id;
+ __entry->temp_prev = temp_prev;
+ __entry->temp = temp;
),

TP_printk("thermal_zone=%s id=%d temp_prev=%d temp=%d",
@@ -67,21 +67,21 @@ TRACE_EVENT(cdev_update,

TRACE_EVENT(thermal_zone_trip,

- TP_PROTO(struct thermal_zone_device *tz, int trip,
+ TP_PROTO(const char *type, int id, int trip,
enum thermal_trip_type trip_type),

- TP_ARGS(tz, trip, trip_type),
+ TP_ARGS(type, id, trip, trip_type),

TP_STRUCT__entry(
- __string(thermal_zone, tz->type)
+ __string(thermal_zone, type)
__field(int, id)
__field(int, trip)
__field(enum thermal_trip_type, trip_type)
),

TP_fast_assign(
- __assign_str(thermal_zone, tz->type);
- __entry->id = tz->id;
+ __assign_str(thermal_zone, type);
+ __entry->id = id;
__entry->trip = trip;
__entry->trip_type = trip_type;
),
diff --git a/include/trace/events/thermal_power_allocator.h b/include/trace/events/thermal_power_allocator.h
index 1c8fb95544f9..7ac049e7e3cf 100644
--- a/include/trace/events/thermal_power_allocator.h
+++ b/include/trace/events/thermal_power_allocator.h
@@ -8,12 +8,12 @@
#include <linux/tracepoint.h>

TRACE_EVENT(thermal_power_allocator,
- TP_PROTO(struct thermal_zone_device *tz, u32 *req_power,
+ TP_PROTO(int id, u32 *req_power,
u32 total_req_power, u32 *granted_power,
u32 total_granted_power, size_t num_actors,
u32 power_range, u32 max_allocatable_power,
int current_temp, s32 delta_temp),
- TP_ARGS(tz, req_power, total_req_power, granted_power,
+ TP_ARGS(id, req_power, total_req_power, granted_power,
total_granted_power, num_actors, power_range,
max_allocatable_power, current_temp, delta_temp),
TP_STRUCT__entry(
@@ -29,7 +29,7 @@ TRACE_EVENT(thermal_power_allocator,
__field(s32, delta_temp )
),
TP_fast_assign(
- __entry->tz_id = tz->id;
+ __entry->tz_id = id;
memcpy(__get_dynamic_array(req_power), req_power,
num_actors * sizeof(*req_power));
__entry->total_req_power = total_req_power;
@@ -56,9 +56,9 @@ TRACE_EVENT(thermal_power_allocator,
);

TRACE_EVENT(thermal_power_allocator_pid,
- TP_PROTO(struct thermal_zone_device *tz, s32 err, s32 err_integral,
+ TP_PROTO(int id, s32 err, s32 err_integral,
s64 p, s64 i, s64 d, s32 output),
- TP_ARGS(tz, err, err_integral, p, i, d, output),
+ TP_ARGS(id, err, err_integral, p, i, d, output),
TP_STRUCT__entry(
__field(int, tz_id )
__field(s32, err )
@@ -69,7 +69,7 @@ TRACE_EVENT(thermal_power_allocator_pid,
__field(s32, output )
),
TP_fast_assign(
- __entry->tz_id = tz->id;
+ __entry->tz_id = id;
__entry->err = err;
__entry->err_integral = err_integral;
__entry->p = p;
--
2.34.1


2023-02-19 14:40:06

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 16/17] thermal/drivers/acerhdf: Remove pointless governor test

The thermal zone parameter specifies the bang-bang governor.

The Kconfig selects the bang-bang governor. So it is pointless to test
if the governor was set for the thermal zone assuming it may not have
been compiled-in.

Remove the test and prevent another access into the thermal internals.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/platform/x86/acerhdf.c | 7 -------
1 file changed, 7 deletions(-)

diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c
index 61f1c3090867..71b9c1f922d9 100644
--- a/drivers/platform/x86/acerhdf.c
+++ b/drivers/platform/x86/acerhdf.c
@@ -697,13 +697,6 @@ static int __init acerhdf_register_thermal(void)
if (ret)
return ret;

- if (strcmp(thz_dev->governor->name,
- acerhdf_zone_params.governor_name)) {
- pr_err("Didn't get thermal governor %s, perhaps not compiled into thermal subsystem.\n",
- acerhdf_zone_params.governor_name);
- return -EINVAL;
- }
-
return 0;
}

--
2.34.1


2023-02-19 14:40:06

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v1 15/17] thermal/drivers/acerhdf: Make interval setting only at module load time

The thermal zone device structure is in the process of being private
to the thermal framework core code. This driver is directly accessing
and changing the monitoring polling rate.

After discussing with the maintainers of this driver, having the
polling interval at module loading time is enough for their purpose.

Change the code to take into account the interval when the module is
loaded but restrict the permissions so the value can not be changed
afterwards.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/platform/x86/acerhdf.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c
index 1956469c3457..61f1c3090867 100644
--- a/drivers/platform/x86/acerhdf.c
+++ b/drivers/platform/x86/acerhdf.c
@@ -79,7 +79,6 @@ static unsigned int list_supported;
static unsigned int fanstate = ACERHDF_FAN_AUTO;
static char force_bios[16];
static char force_product[16];
-static unsigned int prev_interval;
static struct thermal_zone_device *thz_dev;
static struct thermal_cooling_device *cl_dev;
static struct platform_device *acerhdf_dev;
@@ -346,20 +345,15 @@ static void acerhdf_check_param(struct thermal_zone_device *thermal)
trips[0].temperature = fanon;
trips[0].hysteresis = fanon - fanoff;

- if (kernelmode && prev_interval != interval) {
+ if (kernelmode) {
if (interval > ACERHDF_MAX_INTERVAL) {
pr_err("interval too high, set to %d\n",
ACERHDF_MAX_INTERVAL);
interval = ACERHDF_MAX_INTERVAL;
}
+
if (verbose)
pr_notice("interval changed to: %d\n", interval);
-
- if (thermal)
- thermal->polling_delay_jiffies =
- round_jiffies(msecs_to_jiffies(interval * 1000));
-
- prev_interval = interval;
}
}

@@ -807,5 +801,5 @@ static const struct kernel_param_ops interval_ops = {
.get = param_get_uint,
};

-module_param_cb(interval, &interval_ops, &interval, 0600);
+module_param_cb(interval, &interval_ops, &interval, 0000);
MODULE_PARM_DESC(interval, "Polling interval of temperature check");
--
2.34.1


2023-02-19 14:55:37

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v1 09/17] thermal: Add a thermal zone id accessor

On Sun, Feb 19, 2023 at 03:36:49PM +0100, Daniel Lezcano wrote:
> In order to get the thermal zone id but without directly accessing the
> thermal zone device structure, add an accessor.
>
> Use the accessor from the hwmon_scmi
>
> No functional change intented.
>
> Signed-off-by: Daniel Lezcano <[email protected]>

Acked-by: Guenter Roeck <[email protected]>

> ---
> drivers/hwmon/scmi-hwmon.c | 2 +-
> drivers/thermal/thermal_core.c | 6 ++++++
> include/linux/thermal.h | 2 ++
> 3 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
> index 7951b6026f48..036b56a535c1 100644
> --- a/drivers/hwmon/scmi-hwmon.c
> +++ b/drivers/hwmon/scmi-hwmon.c
> @@ -220,7 +220,7 @@ static int scmi_thermal_sensor_register(struct device *dev,
> sensor->name);
> } else {
> dev_dbg(dev, "Sensor '%s' attached to thermal zone ID:%d\n",
> - sensor->name, tzd->id);
> + sensor->name, thermal_zone_device_get_id(tzd));
> }
>
> return 0;
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 05e5a6bda695..e06c76b38c04 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -1384,6 +1384,12 @@ void *thermal_zone_device_get_data(struct thermal_zone_device *tzd)
> }
> EXPORT_SYMBOL_GPL(thermal_zone_device_get_data);
>
> +int thermal_zone_device_get_id(struct thermal_zone_device *tzd)
> +{
> + return tzd->id;
> +}
> +EXPORT_SYMBOL_GPL(thermal_zone_device_get_id);
> +
> /**
> * thermal_zone_device_unregister - removes the registered thermal zone device
> * @tz: the thermal zone device to remove
> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index 724b95662da9..9e5c7f2f7b05 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -367,6 +367,8 @@ thermal_zone_device_register_with_trips(const char *, struct thermal_trip *, int
>
> void *thermal_zone_device_get_data(struct thermal_zone_device *tzd);
>
> +int thermal_zone_device_get_id(struct thermal_zone_device *tzd);
> +
> int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
> struct thermal_cooling_device *,
> unsigned long, unsigned long,
> --
> 2.34.1
>

2023-02-19 14:56:47

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

On Sun, Feb 19, 2023 at 03:36:41PM +0100, Daniel Lezcano wrote:
> The thermal zone device structure is exposed to the different drivers
> and obviously they access the internals while that should be
> restricted to the core thermal code.
>
> In order to self-encapsulate the thermal core code, we need to prevent
> the drivers accessing directly the thermal zone structure and provide
> accessor functions to deal with.
>
> Provide an accessor to the 'devdata' structure and make use of it in
> the different drivers.
>
> No functional changes intended.
>
> Signed-off-by: Daniel Lezcano <[email protected]>
> ---
...
> drivers/hwmon/hwmon.c | 4 ++--
> drivers/hwmon/pmbus/pmbus_core.c | 2 +-
> drivers/hwmon/scmi-hwmon.c | 2 +-
> drivers/hwmon/scpi-hwmon.c | 2 +-

For hwmon:

Acked-by: Guenter Roeck <[email protected]>

Guenter

2023-02-19 15:07:35

by Niklas Söderlund

[permalink] [raw]
Subject: Re: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

Hi Daniel,

Thanks for your work.

On 2023-02-19 15:36:41 +0100, Daniel Lezcano wrote:
> The thermal zone device structure is exposed to the different drivers
> and obviously they access the internals while that should be
> restricted to the core thermal code.
>
> In order to self-encapsulate the thermal core code, we need to prevent
> the drivers accessing directly the thermal zone structure and provide
> accessor functions to deal with.
>
> Provide an accessor to the 'devdata' structure and make use of it in
> the different drivers.
>
> No functional changes intended.
>
> Signed-off-by: Daniel Lezcano <[email protected]>
> ---

...

> drivers/thermal/rcar_gen3_thermal.c | 4 ++--
> drivers/thermal/rcar_thermal.c | 3 +--

For R-Car,

Reviewed-by: Niklas Söderlund <[email protected]>

...


> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index 2bb4bf33f4f3..724b95662da9 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -365,6 +365,8 @@ thermal_zone_device_register_with_trips(const char *, struct thermal_trip *, int
> void *, struct thermal_zone_device_ops *,
> struct thermal_zone_params *, int, int);
>
> +void *thermal_zone_device_get_data(struct thermal_zone_device *tzd);
> +

bikeshedding:

Would it make sens to name this thermal_zone_device_get_priv_data(),
thermal_zone_device_get_priv() or something like that? To make it more
explicitly when reading the driver code this fetches the drivers private
data, and not some data belonging to the zone itself.

> int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
> struct thermal_cooling_device *,

--
Kind Regards,
Niklas Söderlund

2023-02-19 15:09:04

by Niklas Söderlund

[permalink] [raw]
Subject: Re: [PATCH v1 04/17] thermal/hwmon: Do not set no_hwmon before calling thermal_add_hwmon_sysfs()

Hi Daniel,

Thanks for your work.

On 2023-02-19 15:36:44 +0100, Daniel Lezcano wrote:
> The thermal->tzp->no_hwmon parameter is only used when calling
> thermal_zone_device_register().
>
> Setting it to 'false' before calling thermal_add_hwmon_sysfs() has no
> effect.
>
> Remove the call and again prevent the drivers to access the thermal
> internals.
>
> Signed-off-by: Daniel Lezcano <[email protected]>
> ---
> drivers/thermal/broadcom/bcm2711_thermal.c | 1 -
> drivers/thermal/broadcom/bcm2835_thermal.c | 1 -
> drivers/thermal/rcar_gen3_thermal.c | 1 -
> drivers/thermal/rcar_thermal.c | 5 -----

For R-Car,

Reviewed-by: Niklas Söderlund <[email protected]>

> drivers/thermal/rockchip_thermal.c | 1 -
> drivers/thermal/rzg2l_thermal.c | 1 -
> 6 files changed, 10 deletions(-)
>
> diff --git a/drivers/thermal/broadcom/bcm2711_thermal.c b/drivers/thermal/broadcom/bcm2711_thermal.c
> index 18b1a4d9ecc7..0a499435431c 100644
> --- a/drivers/thermal/broadcom/bcm2711_thermal.c
> +++ b/drivers/thermal/broadcom/bcm2711_thermal.c
> @@ -98,7 +98,6 @@ static int bcm2711_thermal_probe(struct platform_device *pdev)
>
> priv->thermal = thermal;
>
> - thermal->tzp->no_hwmon = false;
> return thermal_add_hwmon_sysfs(thermal);
> }
>
> diff --git a/drivers/thermal/broadcom/bcm2835_thermal.c b/drivers/thermal/broadcom/bcm2835_thermal.c
> index de2f573863da..8ed7a80122a0 100644
> --- a/drivers/thermal/broadcom/bcm2835_thermal.c
> +++ b/drivers/thermal/broadcom/bcm2835_thermal.c
> @@ -267,7 +267,6 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)
> * Thermal_zone doesn't enable hwmon as default,
> * enable it here
> */
> - tz->tzp->no_hwmon = false;
> err = thermal_add_hwmon_sysfs(tz);
> if (err)
> goto err_tz;
> diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c
> index 8ad713cb4bf7..4ea9d4bd8e6f 100644
> --- a/drivers/thermal/rcar_gen3_thermal.c
> +++ b/drivers/thermal/rcar_gen3_thermal.c
> @@ -527,7 +527,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
> }
> tsc->zone = zone;
>
> - tsc->zone->tzp->no_hwmon = false;
> ret = thermal_add_hwmon_sysfs(tsc->zone);
> if (ret)
> goto error_unregister;
> diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
> index 538ed6731589..919f0e32d3c5 100644
> --- a/drivers/thermal/rcar_thermal.c
> +++ b/drivers/thermal/rcar_thermal.c
> @@ -509,11 +509,6 @@ static int rcar_thermal_probe(struct platform_device *pdev)
> }
>
> if (chip->use_of_thermal) {
> - /*
> - * thermal_zone doesn't enable hwmon as default,
> - * but, enable it here to keep compatible
> - */
> - priv->zone->tzp->no_hwmon = false;
> ret = thermal_add_hwmon_sysfs(priv->zone);
> if (ret)
> goto error_unregister;
> diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c
> index bd593ec712ee..3211b70c85b9 100644
> --- a/drivers/thermal/rockchip_thermal.c
> +++ b/drivers/thermal/rockchip_thermal.c
> @@ -1451,7 +1451,6 @@ static int rockchip_thermal_probe(struct platform_device *pdev)
>
> for (i = 0; i < thermal->chip->chn_num; i++) {
> rockchip_thermal_toggle_sensor(&thermal->sensors[i], true);
> - thermal->sensors[i].tzd->tzp->no_hwmon = false;
> error = thermal_add_hwmon_sysfs(thermal->sensors[i].tzd);
> if (error)
> dev_warn(&pdev->dev,
> diff --git a/drivers/thermal/rzg2l_thermal.c b/drivers/thermal/rzg2l_thermal.c
> index d3ba2a74e42d..a2f21c941cfe 100644
> --- a/drivers/thermal/rzg2l_thermal.c
> +++ b/drivers/thermal/rzg2l_thermal.c
> @@ -216,7 +216,6 @@ static int rzg2l_thermal_probe(struct platform_device *pdev)
> }
>
> priv->zone = zone;
> - priv->zone->tzp->no_hwmon = false;
> ret = thermal_add_hwmon_sysfs(priv->zone);
> if (ret)
> goto err;
> --
> 2.34.1
>

--
Kind Regards,
Niklas Söderlund

2023-02-19 16:48:43

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

Hi Daniel,

I love your patch! Yet something to improve:

[auto build test ERROR on rafael-pm/thermal]
[also build test ERROR on next-20230217]
[cannot apply to groeck-staging/hwmon-next tegra/for-next linus/master v6.2-rc8]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Daniel-Lezcano/thermal-core-Add-a-thermal-zone-devdata-accessor/20230219-224155
base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git thermal
patch link: https://lore.kernel.org/r/20230219143657.241542-2-daniel.lezcano%40linaro.org
patch subject: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor
config: sparc64-randconfig-r015-20230219 (https://download.01.org/0day-ci/archive/20230220/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/4ae519499a90b8b0388e5e80c5d85c6dbf292242
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Daniel-Lezcano/thermal-core-Add-a-thermal-zone-devdata-accessor/20230219-224155
git checkout 4ae519499a90b8b0388e5e80c5d85c6dbf292242
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc64 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc64 SHELL=/bin/bash drivers/ata/ drivers/hwmon/pmbus/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

drivers/ata/ahci_imx.c: In function 'sata_ahci_read_temperature':
>> drivers/ata/ahci_imx.c:421:45: error: implicit declaration of function 'thermal_zone_device_get_data'; did you mean 'thermal_zone_device_enable'? [-Werror=implicit-function-declaration]
421 | return __sata_ahci_read_temperature(thermal_zone_device_get_data(tz), temp);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
| thermal_zone_device_enable
>> drivers/ata/ahci_imx.c:421:45: warning: passing argument 1 of '__sata_ahci_read_temperature' makes pointer from integer without a cast [-Wint-conversion]
421 | return __sata_ahci_read_temperature(thermal_zone_device_get_data(tz), temp);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| int
drivers/ata/ahci_imx.c:330:47: note: expected 'void *' but argument is of type 'int'
330 | static int __sata_ahci_read_temperature(void *dev, int *temp)
| ~~~~~~^~~
cc1: some warnings being treated as errors
--
drivers/hwmon/pmbus/pmbus_core.c: In function 'pmbus_thermal_get_temp':
>> drivers/hwmon/pmbus/pmbus_core.c:1275:44: error: implicit declaration of function 'thermal_zone_device_get_data'; did you mean 'thermal_zone_device_enable'? [-Werror=implicit-function-declaration]
1275 | struct pmbus_thermal_data *tdata = thermal_zone_device_get_data(tz);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
| thermal_zone_device_enable
>> drivers/hwmon/pmbus/pmbus_core.c:1275:44: warning: initialization of 'struct pmbus_thermal_data *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
cc1: some warnings being treated as errors


vim +421 drivers/ata/ahci_imx.c

418
419 static int sata_ahci_read_temperature(struct thermal_zone_device *tz, int *temp)
420 {
> 421 return __sata_ahci_read_temperature(thermal_zone_device_get_data(tz), temp);
422 }
423

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

2023-02-19 17:07:49

by Daniel Lezcano

[permalink] [raw]
Subject: Re: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

On 19/02/2023 16:07, Niklas Söderlund wrote:
> Hi Daniel,
>
> Thanks for your work.
>
> On 2023-02-19 15:36:41 +0100, Daniel Lezcano wrote:
>> The thermal zone device structure is exposed to the different drivers
>> and obviously they access the internals while that should be
>> restricted to the core thermal code.
>>
>> In order to self-encapsulate the thermal core code, we need to prevent
>> the drivers accessing directly the thermal zone structure and provide
>> accessor functions to deal with.
>>
>> Provide an accessor to the 'devdata' structure and make use of it in
>> the different drivers.
>>
>> No functional changes intended.
>>
>> Signed-off-by: Daniel Lezcano <[email protected]>
>> ---
>
> ...
>
>> drivers/thermal/rcar_gen3_thermal.c | 4 ++--
>> drivers/thermal/rcar_thermal.c | 3 +--
>
> For R-Car,
>
> Reviewed-by: Niklas Söderlund <[email protected]>
>
> ...
>
>
>> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
>> index 2bb4bf33f4f3..724b95662da9 100644
>> --- a/include/linux/thermal.h
>> +++ b/include/linux/thermal.h
>> @@ -365,6 +365,8 @@ thermal_zone_device_register_with_trips(const char *, struct thermal_trip *, int
>> void *, struct thermal_zone_device_ops *,
>> struct thermal_zone_params *, int, int);
>>
>> +void *thermal_zone_device_get_data(struct thermal_zone_device *tzd);
>> +
>
> bikeshedding:
>
> Would it make sens to name this thermal_zone_device_get_priv_data(),
> thermal_zone_device_get_priv() or something like that? To make it more
> explicitly when reading the driver code this fetches the drivers private
> data, and not some data belonging to the zone itself.

In the headers files, there are more occurrences with _name_priv():

# _name_priv()
git grep priv include/linux/ | grep "priv(" | grep -v get | wc -l
52

# _name_private()
git grep priv include/linux/ | grep "private(" | grep -v get | wc -l
33

# _name_get_private()
git grep priv include/linux/ | grep "private(" | grep get | wc -l
12

# _name_get_priv()
git grep priv include/linux/ | grep "priv(" | grep get | wc -l
4


What about thermal_zone_device_priv() ?






--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


2023-02-19 17:15:49

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v1 09/17] thermal: Add a thermal zone id accessor

Hi Daniel,

I love your patch! Yet something to improve:

[auto build test ERROR on rafael-pm/thermal]
[also build test ERROR on next-20230217]
[cannot apply to groeck-staging/hwmon-next tegra/for-next linus/master v6.2-rc8]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Daniel-Lezcano/thermal-core-Add-a-thermal-zone-devdata-accessor/20230219-224155
base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git thermal
patch link: https://lore.kernel.org/r/20230219143657.241542-10-daniel.lezcano%40linaro.org
patch subject: [PATCH v1 09/17] thermal: Add a thermal zone id accessor
config: csky-randconfig-r005-20230219 (https://download.01.org/0day-ci/archive/20230220/[email protected]/config)
compiler: csky-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/37b2cf4cee949fd910b54e281577cb71b2df8842
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Daniel-Lezcano/thermal-core-Add-a-thermal-zone-devdata-accessor/20230219-224155
git checkout 37b2cf4cee949fd910b54e281577cb71b2df8842
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=csky olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=csky SHELL=/bin/bash drivers/hwmon/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/hwmon/scmi-hwmon.c: In function 'scmi_hwmon_thermal_get_temp':
drivers/hwmon/scmi-hwmon.c:144:49: error: implicit declaration of function 'thermal_zone_device_get_data'; did you mean 'thermal_zone_device_enable'? [-Werror=implicit-function-declaration]
144 | struct scmi_thermal_sensor *th_sensor = thermal_zone_device_get_data(tz);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
| thermal_zone_device_enable
drivers/hwmon/scmi-hwmon.c:144:49: warning: initialization of 'struct scmi_thermal_sensor *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
In file included from include/linux/device.h:15,
from include/linux/scmi_protocol.h:12,
from drivers/hwmon/scmi-hwmon.c:11:
drivers/hwmon/scmi-hwmon.c: In function 'scmi_thermal_sensor_register':
>> drivers/hwmon/scmi-hwmon.c:223:39: error: implicit declaration of function 'thermal_zone_device_get_id'; did you mean 'thermal_zone_device_enable'? [-Werror=implicit-function-declaration]
223 | sensor->name, thermal_zone_device_get_id(tzd));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/dev_printk.h:129:48: note: in definition of macro 'dev_printk'
129 | _dev_printk(level, dev, fmt, ##__VA_ARGS__); \
| ^~~~~~~~~~~
drivers/hwmon/scmi-hwmon.c:222:17: note: in expansion of macro 'dev_dbg'
222 | dev_dbg(dev, "Sensor '%s' attached to thermal zone ID:%d\n",
| ^~~~~~~
cc1: some warnings being treated as errors


vim +223 drivers/hwmon/scmi-hwmon.c

138
139 static int scmi_hwmon_thermal_get_temp(struct thermal_zone_device *tz,
140 int *temp)
141 {
142 int ret;
143 long value;
> 144 struct scmi_thermal_sensor *th_sensor = thermal_zone_device_get_data(tz);
145
146 ret = scmi_hwmon_read_scaled_value(th_sensor->ph, th_sensor->info,
147 &value);
148 if (!ret)
149 *temp = value;
150
151 return ret;
152 }
153
154 static const struct thermal_zone_device_ops scmi_hwmon_thermal_ops = {
155 .get_temp = scmi_hwmon_thermal_get_temp,
156 };
157
158 static int scmi_hwmon_add_chan_info(struct hwmon_channel_info *scmi_hwmon_chan,
159 struct device *dev, int num,
160 enum hwmon_sensor_types type, u32 config)
161 {
162 int i;
163 u32 *cfg = devm_kcalloc(dev, num + 1, sizeof(*cfg), GFP_KERNEL);
164
165 if (!cfg)
166 return -ENOMEM;
167
168 scmi_hwmon_chan->type = type;
169 scmi_hwmon_chan->config = cfg;
170 for (i = 0; i < num; i++, cfg++)
171 *cfg = config;
172
173 return 0;
174 }
175
176 static enum hwmon_sensor_types scmi_types[] = {
177 [TEMPERATURE_C] = hwmon_temp,
178 [VOLTAGE] = hwmon_in,
179 [CURRENT] = hwmon_curr,
180 [POWER] = hwmon_power,
181 [ENERGY] = hwmon_energy,
182 };
183
184 static u32 hwmon_attributes[hwmon_max] = {
185 [hwmon_temp] = HWMON_T_INPUT | HWMON_T_LABEL,
186 [hwmon_in] = HWMON_I_INPUT | HWMON_I_LABEL,
187 [hwmon_curr] = HWMON_C_INPUT | HWMON_C_LABEL,
188 [hwmon_power] = HWMON_P_INPUT | HWMON_P_LABEL,
189 [hwmon_energy] = HWMON_E_INPUT | HWMON_E_LABEL,
190 };
191
192 static int scmi_thermal_sensor_register(struct device *dev,
193 const struct scmi_protocol_handle *ph,
194 const struct scmi_sensor_info *sensor)
195 {
196 struct scmi_thermal_sensor *th_sensor;
197 struct thermal_zone_device *tzd;
198
199 th_sensor = devm_kzalloc(dev, sizeof(*th_sensor), GFP_KERNEL);
200 if (!th_sensor)
201 return -ENOMEM;
202
203 th_sensor->ph = ph;
204 th_sensor->info = sensor;
205
206 /*
207 * Try to register a temperature sensor with the Thermal Framework:
208 * skip sensors not defined as part of any thermal zone (-ENODEV) but
209 * report any other errors related to misconfigured zones/sensors.
210 */
211 tzd = devm_thermal_of_zone_register(dev, th_sensor->info->id, th_sensor,
212 &scmi_hwmon_thermal_ops);
213 if (IS_ERR(tzd)) {
214 devm_kfree(dev, th_sensor);
215
216 if (PTR_ERR(tzd) != -ENODEV)
217 return PTR_ERR(tzd);
218
219 dev_dbg(dev, "Sensor '%s' not attached to any thermal zone.\n",
220 sensor->name);
221 } else {
222 dev_dbg(dev, "Sensor '%s' attached to thermal zone ID:%d\n",
> 223 sensor->name, thermal_zone_device_get_id(tzd));
224 }
225
226 return 0;
227 }
228

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

2023-02-19 17:26:42

by Martin Blumenstingl

[permalink] [raw]
Subject: Re: [PATCH v1 05/17] thermal/hwmon: Use the right device for devm_thermal_add_hwmon_sysfs()

On Sun, Feb 19, 2023 at 3:38 PM Daniel Lezcano
<[email protected]> wrote:
>
> The devres variant of thermal_add_hwmon_sysfs() only takes the thermal
> zone structure pointer as parameter.
>
> Actually, it uses the tz->device to add it in the devres list.
>
> It is preferable to use the device registering the thermal zone
> instead of the thermal zone device itself. That prevents the driver
> accessing the thermal zone structure internals and it is from my POV
> more correct regarding how devm_ is used.
>
> Signed-off-by: Daniel Lezcano <[email protected]>
> ---
> drivers/thermal/amlogic_thermal.c | 2 +-
For amlogic_thermal.c:
Acked-by: Martin Blumenstingl <[email protected]>

2023-02-19 18:23:40

by Niklas Söderlund

[permalink] [raw]
Subject: Re: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

On 2023-02-19 18:07:36 +0100, Daniel Lezcano wrote:
> On 19/02/2023 16:07, Niklas Söderlund wrote:
> > Hi Daniel,
> >
> > Thanks for your work.
> >
> > On 2023-02-19 15:36:41 +0100, Daniel Lezcano wrote:
> > > The thermal zone device structure is exposed to the different drivers
> > > and obviously they access the internals while that should be
> > > restricted to the core thermal code.
> > >
> > > In order to self-encapsulate the thermal core code, we need to prevent
> > > the drivers accessing directly the thermal zone structure and provide
> > > accessor functions to deal with.
> > >
> > > Provide an accessor to the 'devdata' structure and make use of it in
> > > the different drivers.
> > >
> > > No functional changes intended.
> > >
> > > Signed-off-by: Daniel Lezcano <[email protected]>
> > > ---
> >
> > ...
> >
> > > drivers/thermal/rcar_gen3_thermal.c | 4 ++--
> > > drivers/thermal/rcar_thermal.c | 3 +--
> >
> > For R-Car,
> >
> > Reviewed-by: Niklas Söderlund <[email protected]>
> >
> > ...
> >
> >
> > > diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> > > index 2bb4bf33f4f3..724b95662da9 100644
> > > --- a/include/linux/thermal.h
> > > +++ b/include/linux/thermal.h
> > > @@ -365,6 +365,8 @@ thermal_zone_device_register_with_trips(const char *, struct thermal_trip *, int
> > > void *, struct thermal_zone_device_ops *,
> > > struct thermal_zone_params *, int, int);
> > > +void *thermal_zone_device_get_data(struct thermal_zone_device *tzd);
> > > +
> >
> > bikeshedding:
> >
> > Would it make sens to name this thermal_zone_device_get_priv_data(),
> > thermal_zone_device_get_priv() or something like that? To make it more
> > explicitly when reading the driver code this fetches the drivers private
> > data, and not some data belonging to the zone itself.
>
> In the headers files, there are more occurrences with _name_priv():
>
> # _name_priv()
> git grep priv include/linux/ | grep "priv(" | grep -v get | wc -l
> 52
>
> # _name_private()
> git grep priv include/linux/ | grep "private(" | grep -v get | wc -l
> 33
>
> # _name_get_private()
> git grep priv include/linux/ | grep "private(" | grep get | wc -l
> 12
>
> # _name_get_priv()
> git grep priv include/linux/ | grep "priv(" | grep get | wc -l
> 4
>
>
> What about thermal_zone_device_priv() ?

Looks good to me.

>
>
>
>
>
>
> --
> <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
>
> Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
> <http://twitter.com/#!/linaroorg> Twitter |
> <http://www.linaro.org/linaro-blog/> Blog
>

--
Kind Regards,
Niklas Söderlund

2023-02-19 21:38:08

by Peter Kästle

[permalink] [raw]
Subject: Re: [PATCH v1 15/17] thermal/drivers/acerhdf: Make interval setting only at module load time

19. Februar 2023 15:38, "Daniel Lezcano" <[email protected]> schrieb:

> The thermal zone device structure is in the process of being private
> to the thermal framework core code. This driver is directly accessing
> and changing the monitoring polling rate.
>
> After discussing with the maintainers of this driver, having the
> polling interval at module loading time is enough for their purpose.
>
> Change the code to take into account the interval when the module is
> loaded but restrict the permissions so the value can not be changed
> afterwards.
>
> Signed-off-by: Daniel Lezcano <[email protected]>

Acked-by: Peter Kaestle <[email protected]>


> ---
> drivers/platform/x86/acerhdf.c | 12 +++---------
> 1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c
> index 1956469c3457..61f1c3090867 100644
> --- a/drivers/platform/x86/acerhdf.c
> +++ b/drivers/platform/x86/acerhdf.c
> @@ -79,7 +79,6 @@ static unsigned int list_supported;
> static unsigned int fanstate = ACERHDF_FAN_AUTO;
> static char force_bios[16];
> static char force_product[16];
> -static unsigned int prev_interval;
> static struct thermal_zone_device *thz_dev;
> static struct thermal_cooling_device *cl_dev;
> static struct platform_device *acerhdf_dev;
> @@ -346,20 +345,15 @@ static void acerhdf_check_param(struct thermal_zone_device *thermal)
> trips[0].temperature = fanon;
> trips[0].hysteresis = fanon - fanoff;
>
> - if (kernelmode && prev_interval != interval) {
> + if (kernelmode) {
> if (interval > ACERHDF_MAX_INTERVAL) {
> pr_err("interval too high, set to %d\n",
> ACERHDF_MAX_INTERVAL);
> interval = ACERHDF_MAX_INTERVAL;
> }
> +
> if (verbose)
> pr_notice("interval changed to: %d\n", interval);
> -
> - if (thermal)
> - thermal->polling_delay_jiffies =
> - round_jiffies(msecs_to_jiffies(interval * 1000));
> -
> - prev_interval = interval;
> }
> }
>
> @@ -807,5 +801,5 @@ static const struct kernel_param_ops interval_ops = {
> .get = param_get_uint,
> };
>
> -module_param_cb(interval, &interval_ops, &interval, 0600);
> +module_param_cb(interval, &interval_ops, &interval, 0000);
> MODULE_PARM_DESC(interval, "Polling interval of temperature check");
> --
> 2.34.1

2023-02-19 22:14:12

by Peter Kästle

[permalink] [raw]
Subject: Re: [PATCH v1 16/17] thermal/drivers/acerhdf: Remove pointless governor test

19. Februar 2023 15:38, "Daniel Lezcano" <[email protected]> schrieb:

> The thermal zone parameter specifies the bang-bang governor.
>
> The Kconfig selects the bang-bang governor. So it is pointless to test
> if the governor was set for the thermal zone assuming it may not have
> been compiled-in.
>
> Remove the test and prevent another access into the thermal internals.
>
> Signed-off-by: Daniel Lezcano <[email protected]>

Acked-by: Peter Kaestle <[email protected]>


> ---
> drivers/platform/x86/acerhdf.c | 7 -------
> 1 file changed, 7 deletions(-)
>
> diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c
> index 61f1c3090867..71b9c1f922d9 100644
> --- a/drivers/platform/x86/acerhdf.c
> +++ b/drivers/platform/x86/acerhdf.c
> @@ -697,13 +697,6 @@ static int __init acerhdf_register_thermal(void)
> if (ret)
> return ret;
>
> - if (strcmp(thz_dev->governor->name,
> - acerhdf_zone_params.governor_name)) {
> - pr_err("Didn't get thermal governor %s, perhaps not compiled into thermal subsystem.\n",
> - acerhdf_zone_params.governor_name);
> - return -EINVAL;
> - }
> -
> return 0;
> }
>
> --
> 2.34.1

2023-02-19 22:34:43

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

On Sun, Feb 19, 2023 at 03:36:41PM +0100, Daniel Lezcano wrote:
> The thermal zone device structure is exposed to the different drivers
> and obviously they access the internals while that should be
> restricted to the core thermal code.
>
> In order to self-encapsulate the thermal core code, we need to prevent
> the drivers accessing directly the thermal zone structure and provide
> accessor functions to deal with.
>
> Provide an accessor to the 'devdata' structure and make use of it in
> the different drivers.

Acked-by: Mark Brown <[email protected]>


Attachments:
(No filename) (563.00 B)
signature.asc (488.00 B)
Download all attachments

2023-02-20 08:21:17

by Ido Schimmel

[permalink] [raw]
Subject: Re: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

On Sun, Feb 19, 2023 at 03:36:41PM +0100, Daniel Lezcano wrote:
> The thermal zone device structure is exposed to the different drivers
> and obviously they access the internals while that should be
> restricted to the core thermal code.
>
> In order to self-encapsulate the thermal core code, we need to prevent
> the drivers accessing directly the thermal zone structure and provide
> accessor functions to deal with.
>
> Provide an accessor to the 'devdata' structure and make use of it in
> the different drivers.
>
> No functional changes intended.
>
> Signed-off-by: Daniel Lezcano <[email protected]>

For mlxsw:

Reviewed-by: Ido Schimmel <[email protected]>

2023-02-20 08:22:40

by Ido Schimmel

[permalink] [raw]
Subject: Re: [PATCH v1 10/17] thermal: Do not access 'type' field, use the tz id instead

On Sun, Feb 19, 2023 at 03:36:50PM +0100, Daniel Lezcano wrote:
> The 'type' field is used as a name in the message. However we can have
> multiple thermal zone with the same type. The information is not
> accurate.
>
> Moreover, the thermal zone device structure is directly accessed while
> we want to improve the self-encapsulation of the code.
>
> Replace the 'type' in the message by the thermal zone id.
>
> Signed-off-by: Daniel Lezcano <[email protected]>

For mlxsw:

Reviewed-by: Ido Schimmel <[email protected]>

2023-02-20 08:58:49

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH v1 03/17] thermal: Remove debug or error messages in get_temp() ops

Hi Daniel,

[email protected] wrote on Sun, 19 Feb 2023 15:36:43 +0100:

> Some get_temp() ops implementation are showing an error or a debug
> message if the reading of the sensor fails.
>
> The debug message is already displayed from the call site of this
> ops. So we can remove it.
>
> On the other side, the error should not be displayed because in
> production that can raise tons of messages.
>
> Finally, some drivers are showing a debug message with the
> temperature, this is also accessible through the trace from the core
> code in the temperature_update() function.
>
> Another benefit is the dev_* messages are accessing the thermal zone
> device field from the structure, so we encapsulate even more the code
> by preventing these accesses.
>
> Remove those messages.
>
> Signed-off-by: Daniel Lezcano <[email protected]>
> ---
> drivers/thermal/armada_thermal.c | 10 ++--------

For Armada:

Reviewed-by: Miquel Raynal <[email protected]>

Thanks,
Miquèl

Subject: Re: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

Il 19/02/23 15:36, Daniel Lezcano ha scritto:
> The thermal zone device structure is exposed to the different drivers
> and obviously they access the internals while that should be
> restricted to the core thermal code.
>
> In order to self-encapsulate the thermal core code, we need to prevent
> the drivers accessing directly the thermal zone structure and provide
> accessor functions to deal with.
>
> Provide an accessor to the 'devdata' structure and make use of it in
> the different drivers.
>
> No functional changes intended.
>
> Signed-off-by: Daniel Lezcano <[email protected]>
> ---


> drivers/thermal/mediatek/auxadc_thermal.c | 2 +-
> drivers/thermal/mediatek/lvts_thermal.c | 4 ++--

For MediaTek auxadc and lvts:

Reviewed-by: AngeloGioacchino Del Regno <[email protected]>



2023-02-20 10:34:53

by Balsam CHIHI

[permalink] [raw]
Subject: Re: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

On Sun, Feb 19, 2023 at 3:37 PM Daniel Lezcano
<[email protected]> wrote:
>
> The thermal zone device structure is exposed to the different drivers
> and obviously they access the internals while that should be
> restricted to the core thermal code.
>
> In order to self-encapsulate the thermal core code, we need to prevent
> the drivers accessing directly the thermal zone structure and provide
> accessor functions to deal with.
>
> Provide an accessor to the 'devdata' structure and make use of it in
> the different drivers.
>
> No functional changes intended.
>
> Signed-off-by: Daniel Lezcano <[email protected]>
> ---
[...]
> drivers/thermal/mediatek/lvts_thermal.c | 4 ++--
[...]
> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> index 84ba65a27acf..86d280187c83 100644
> --- a/drivers/thermal/mediatek/lvts_thermal.c
> +++ b/drivers/thermal/mediatek/lvts_thermal.c
> @@ -252,7 +252,7 @@ static u32 lvts_temp_to_raw(int temperature)
>
> static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
> {
> - struct lvts_sensor *lvts_sensor = tz->devdata;
> + struct lvts_sensor *lvts_sensor = thermal_zone_device_get_data(tz);
> void __iomem *msr = lvts_sensor->msr;
> u32 value;
>
> @@ -290,7 +290,7 @@ static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
>
> static int lvts_set_trips(struct thermal_zone_device *tz, int low, int high)
> {
> - struct lvts_sensor *lvts_sensor = tz->devdata;
> + struct lvts_sensor *lvts_sensor = thermal_zone_device_get_data(tz);
> void __iomem *base = lvts_sensor->base;
> u32 raw_low = lvts_temp_to_raw(low);
> u32 raw_high = lvts_temp_to_raw(high);

for MediaTek LVTS :

Reviewed-by: Balsam CHIHI <[email protected]>

2023-02-20 10:37:54

by Greenman, Gregory

[permalink] [raw]
Subject: Re: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

On Sun, 2023-02-19 at 15:36 +0100, Daniel Lezcano wrote:
> The thermal zone device structure is exposed to the different drivers
> and obviously they access the internals while that should be
> restricted to the core thermal code.
>
> In order to self-encapsulate the thermal core code, we need to prevent
> the drivers accessing directly the thermal zone structure and provide
> accessor functions to deal with.
>
> Provide an accessor to the 'devdata' structure and make use of it in
> the different drivers.
>
> No functional changes intended.
>
> Signed-off-by: Daniel Lezcano <[email protected]>
> ---
>  drivers/acpi/thermal.c                           | 16 ++++++++--------
>  drivers/ata/ahci_imx.c                           |  2 +-
>  drivers/hwmon/hwmon.c                            |  4 ++--
>  drivers/hwmon/pmbus/pmbus_core.c                 |  2 +-
>  drivers/hwmon/scmi-hwmon.c                       |  2 +-
>  drivers/hwmon/scpi-hwmon.c                       |  2 +-
>  drivers/iio/adc/sun4i-gpadc-iio.c                |  2 +-
>  drivers/input/touchscreen/sun4i-ts.c             |  2 +-
>  .../net/ethernet/chelsio/cxgb4/cxgb4_thermal.c   |  2 +-
>  .../net/ethernet/mellanox/mlxsw/core_thermal.c   | 14 +++++++-------
>  drivers/net/wireless/intel/iwlwifi/mvm/tt.c      |  4 ++--
>  drivers/power/supply/power_supply_core.c         |  2 +-
>  drivers/regulator/max8973-regulator.c            |  2 +-
>  drivers/thermal/armada_thermal.c                 |  4 ++--
>  drivers/thermal/broadcom/bcm2711_thermal.c       |  2 +-
>  drivers/thermal/broadcom/bcm2835_thermal.c       |  2 +-
>  drivers/thermal/broadcom/brcmstb_thermal.c       |  4 ++--
>  drivers/thermal/broadcom/ns-thermal.c            |  2 +-
>  drivers/thermal/broadcom/sr-thermal.c            |  2 +-
>  drivers/thermal/da9062-thermal.c                 |  2 +-
>  drivers/thermal/dove_thermal.c                   |  2 +-
>  drivers/thermal/hisi_thermal.c                   |  2 +-
>  drivers/thermal/imx8mm_thermal.c                 |  2 +-
>  drivers/thermal/imx_sc_thermal.c                 |  2 +-
>  drivers/thermal/imx_thermal.c                    |  6 +++---
>  drivers/thermal/intel/intel_pch_thermal.c        |  2 +-
>  drivers/thermal/intel/intel_soc_dts_iosf.c       | 13 +++++--------
>  drivers/thermal/intel/x86_pkg_temp_thermal.c     |  4 ++--
>  drivers/thermal/k3_bandgap.c                     |  2 +-
>  drivers/thermal/k3_j72xx_bandgap.c               |  2 +-
>  drivers/thermal/kirkwood_thermal.c               |  2 +-
>  drivers/thermal/max77620_thermal.c               |  2 +-
>  drivers/thermal/mediatek/auxadc_thermal.c        |  2 +-
>  drivers/thermal/mediatek/lvts_thermal.c          |  4 ++--
>  drivers/thermal/qcom/qcom-spmi-adc-tm5.c         |  4 ++--
>  drivers/thermal/qcom/qcom-spmi-temp-alarm.c      |  4 ++--
>  drivers/thermal/qoriq_thermal.c                  |  2 +-
>  drivers/thermal/rcar_gen3_thermal.c              |  4 ++--
>  drivers/thermal/rcar_thermal.c                   |  3 +--
>  drivers/thermal/rockchip_thermal.c               |  4 ++--
>  drivers/thermal/rzg2l_thermal.c                  |  2 +-
>  drivers/thermal/samsung/exynos_tmu.c             |  4 ++--
>  drivers/thermal/spear_thermal.c                  |  8 ++++----
>  drivers/thermal/sprd_thermal.c                   |  2 +-
>  drivers/thermal/sun8i_thermal.c                  |  2 +-
>  drivers/thermal/tegra/tegra-bpmp-thermal.c       |  6 ++++--
>  drivers/thermal/tegra/tegra30-tsensor.c          |  4 ++--
>  drivers/thermal/thermal-generic-adc.c            |  2 +-
>  drivers/thermal/thermal_core.c                   |  6 ++++++
>  drivers/thermal/thermal_mmio.c                   |  2 +-
>  .../thermal/ti-soc-thermal/ti-thermal-common.c   |  4 ++--
>  drivers/thermal/uniphier_thermal.c               |  2 +-
>  include/linux/thermal.h                          |  2 ++
>  53 files changed, 97 insertions(+), 91 deletions(-)
>
> diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
> index 0b4b844f9d4c..69d0da6456d5 100644
> --- a/drivers/acpi/thermal.c
> +++ b/drivers/acpi/thermal.c
> @@ -498,7 +498,7 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
>  
>  static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp)
>  {
> -       struct acpi_thermal *tz = thermal->devdata;
> +       struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);
>         int result;
>  
>         if (!tz)
> @@ -516,7 +516,7 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp)
>  static int thermal_get_trip_type(struct thermal_zone_device *thermal,
>                                  int trip, enum thermal_trip_type *type)
>  {
> -       struct acpi_thermal *tz = thermal->devdata;
> +       struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);
>         int i;
>  
>         if (!tz || trip < 0)
> @@ -560,7 +560,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, int *temp)
>  {
> -       struct acpi_thermal *tz = thermal->devdata;
> +       struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);
>         int i;
>  
>         if (!tz || trip < 0)
> @@ -613,7 +613,7 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
>  static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
>                                 int *temperature)
>  {
> -       struct acpi_thermal *tz = thermal->devdata;
> +       struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);
>  
>         if (tz->trips.critical.flags.valid) {
>                 *temperature = deci_kelvin_to_millicelsius_with_offset(
> @@ -628,7 +628,7 @@ static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
>  static int thermal_get_trend(struct thermal_zone_device *thermal,
>                              int trip, enum thermal_trend *trend)
>  {
> -       struct acpi_thermal *tz = thermal->devdata;
> +       struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);
>         enum thermal_trip_type type;
>         int i;
>  
> @@ -670,7 +670,7 @@ static int thermal_get_trend(struct thermal_zone_device *thermal,
>  
>  static void acpi_thermal_zone_device_hot(struct thermal_zone_device *thermal)
>  {
> -       struct acpi_thermal *tz = thermal->devdata;
> +       struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);
>  
>         acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
>                                         dev_name(&tz->device->dev),
> @@ -679,7 +679,7 @@ static void acpi_thermal_zone_device_hot(struct thermal_zone_device *thermal)
>  
>  static void acpi_thermal_zone_device_critical(struct thermal_zone_device *thermal)
>  {
> -       struct acpi_thermal *tz = thermal->devdata;
> +       struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);
>  
>         acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
>                                         dev_name(&tz->device->dev),
> @@ -693,7 +693,7 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
>                                           bool bind)
>  {
>         struct acpi_device *device = cdev->devdata;
> -       struct acpi_thermal *tz = thermal->devdata;
> +       struct acpi_thermal *tz = thermal_zone_device_get_data(thermal);
>         struct acpi_device *dev;
>         acpi_handle handle;
>         int i;
> diff --git a/drivers/ata/ahci_imx.c b/drivers/ata/ahci_imx.c
> index a950767f7948..0ef928528aec 100644
> --- a/drivers/ata/ahci_imx.c
> +++ b/drivers/ata/ahci_imx.c
> @@ -418,7 +418,7 @@ static int __sata_ahci_read_temperature(void *dev, int *temp)
>  
>  static int sata_ahci_read_temperature(struct thermal_zone_device *tz, int *temp)
>  {
> -       return __sata_ahci_read_temperature(tz->devdata, temp);
> +       return __sata_ahci_read_temperature(thermal_zone_device_get_data(tz), temp);
>  }
>  
>  static ssize_t sata_ahci_show_temp(struct device *dev,
> diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
> index 33edb5c02f7d..b33477d04c2b 100644
> --- a/drivers/hwmon/hwmon.c
> +++ b/drivers/hwmon/hwmon.c
> @@ -154,7 +154,7 @@ static DEFINE_IDA(hwmon_ida);
>  #ifdef CONFIG_THERMAL_OF
>  static int hwmon_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct hwmon_thermal_data *tdata = tz->devdata;
> +       struct hwmon_thermal_data *tdata = thermal_zone_device_get_data(tz);
>         struct hwmon_device *hwdev = to_hwmon_device(tdata->dev);
>         int ret;
>         long t;
> @@ -171,7 +171,7 @@ static int hwmon_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>  
>  static int hwmon_thermal_set_trips(struct thermal_zone_device *tz, int low, int high)
>  {
> -       struct hwmon_thermal_data *tdata = tz->devdata;
> +       struct hwmon_thermal_data *tdata = thermal_zone_device_get_data(tz);
>         struct hwmon_device *hwdev = to_hwmon_device(tdata->dev);
>         const struct hwmon_chip_info *chip = hwdev->chip;
>         const struct hwmon_channel_info **info = chip->info;
> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index 95e95783972a..159a88af6277 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -1272,7 +1272,7 @@ struct pmbus_thermal_data {
>  
>  static int pmbus_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct pmbus_thermal_data *tdata = tz->devdata;
> +       struct pmbus_thermal_data *tdata = thermal_zone_device_get_data(tz);
>         struct pmbus_sensor *sensor = tdata->sensor;
>         struct pmbus_data *pmbus_data = tdata->pmbus_data;
>         struct i2c_client *client = to_i2c_client(pmbus_data->dev);
> diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
> index e192f0c67146..7951b6026f48 100644
> --- a/drivers/hwmon/scmi-hwmon.c
> +++ b/drivers/hwmon/scmi-hwmon.c
> @@ -141,7 +141,7 @@ static int scmi_hwmon_thermal_get_temp(struct thermal_zone_device *tz,
>  {
>         int ret;
>         long value;
> -       struct scmi_thermal_sensor *th_sensor = tz->devdata;
> +       struct scmi_thermal_sensor *th_sensor = thermal_zone_device_get_data(tz);
>  
>         ret = scmi_hwmon_read_scaled_value(th_sensor->ph, th_sensor->info,
>                                            &value);
> diff --git a/drivers/hwmon/scpi-hwmon.c b/drivers/hwmon/scpi-hwmon.c
> index 4d75385f7d5e..efe0ddbc5293 100644
> --- a/drivers/hwmon/scpi-hwmon.c
> +++ b/drivers/hwmon/scpi-hwmon.c
> @@ -64,7 +64,7 @@ static void scpi_scale_reading(u64 *value, struct sensor_data *sensor)
>  
>  static int scpi_read_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct scpi_thermal_zone *zone = tz->devdata;
> +       struct scpi_thermal_zone *zone = thermal_zone_device_get_data(tz);
>         struct scpi_sensors *scpi_sensors = zone->scpi_sensors;
>         struct scpi_ops *scpi_ops = scpi_sensors->scpi_ops;
>         struct sensor_data *sensor = &scpi_sensors->data[zone->sensor_id];
> diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c
> index a6ade70dedf8..e24ac3ee8a35 100644
> --- a/drivers/iio/adc/sun4i-gpadc-iio.c
> +++ b/drivers/iio/adc/sun4i-gpadc-iio.c
> @@ -414,7 +414,7 @@ static int sun4i_gpadc_runtime_resume(struct device *dev)
>  
>  static int sun4i_gpadc_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct sun4i_gpadc_iio *info = tz->devdata;
> +       struct sun4i_gpadc_iio *info = thermal_zone_device_get_data(tz);
>         int val, scale, offset;
>  
>         if (sun4i_gpadc_temp_read(info->indio_dev, &val))
> diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
> index 73eb8f80be6e..5e5434ffe397 100644
> --- a/drivers/input/touchscreen/sun4i-ts.c
> +++ b/drivers/input/touchscreen/sun4i-ts.c
> @@ -194,7 +194,7 @@ static int sun4i_get_temp(const struct sun4i_ts_data *ts, int *temp)
>  
>  static int sun4i_get_tz_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       return sun4i_get_temp(tz->devdata, temp);
> +       return sun4i_get_temp(thermal_zone_device_get_data(tz), temp);
>  }
>  
>  static const struct thermal_zone_device_ops sun4i_ts_tz_ops = {
> diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c
> index 95e1b415ba13..8b0d318feef4 100644
> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c
> @@ -12,7 +12,7 @@
>  static int cxgb4_thermal_get_temp(struct thermal_zone_device *tzdev,
>                                   int *temp)
>  {
> -       struct adapter *adap = tzdev->devdata;
> +       struct adapter *adap = thermal_zone_device_get_data(tzdev);
>         u32 param, val;
>         int ret;
>  
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
> index c5240d38c9db..228b6ffaef98 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
> @@ -201,7 +201,7 @@ mlxsw_thermal_module_trips_update(struct device *dev, struct mlxsw_core *core,
>  static int mlxsw_thermal_bind(struct thermal_zone_device *tzdev,
>                               struct thermal_cooling_device *cdev)
>  {
> -       struct mlxsw_thermal *thermal = tzdev->devdata;
> +       struct mlxsw_thermal *thermal = thermal_zone_device_get_data(tzdev);
>         struct device *dev = thermal->bus_info->dev;
>         int i, err;
>  
> @@ -227,7 +227,7 @@ static int mlxsw_thermal_bind(struct thermal_zone_device *tzdev,
>  static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev,
>                                 struct thermal_cooling_device *cdev)
>  {
> -       struct mlxsw_thermal *thermal = tzdev->devdata;
> +       struct mlxsw_thermal *thermal = thermal_zone_device_get_data(tzdev);
>         struct device *dev = thermal->bus_info->dev;
>         int i;
>         int err;
> @@ -249,7 +249,7 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev,
>  static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev,
>                                   int *p_temp)
>  {
> -       struct mlxsw_thermal *thermal = tzdev->devdata;
> +       struct mlxsw_thermal *thermal = thermal_zone_device_get_data(tzdev);
>         struct device *dev = thermal->bus_info->dev;
>         char mtmp_pl[MLXSW_REG_MTMP_LEN];
>         int temp;
> @@ -281,7 +281,7 @@ static struct thermal_zone_device_ops mlxsw_thermal_ops = {
>  static int mlxsw_thermal_module_bind(struct thermal_zone_device *tzdev,
>                                      struct thermal_cooling_device *cdev)
>  {
> -       struct mlxsw_thermal_module *tz = tzdev->devdata;
> +       struct mlxsw_thermal_module *tz = thermal_zone_device_get_data(tzdev);
>         struct mlxsw_thermal *thermal = tz->parent;
>         int i, j, err;
>  
> @@ -310,7 +310,7 @@ static int mlxsw_thermal_module_bind(struct thermal_zone_device *tzdev,
>  static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev,
>                                        struct thermal_cooling_device *cdev)
>  {
> -       struct mlxsw_thermal_module *tz = tzdev->devdata;
> +       struct mlxsw_thermal_module *tz = thermal_zone_device_get_data(tzdev);
>         struct mlxsw_thermal *thermal = tz->parent;
>         int i;
>         int err;
> @@ -356,7 +356,7 @@ mlxsw_thermal_module_temp_and_thresholds_get(struct mlxsw_core *core,
>  static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev,
>                                          int *p_temp)
>  {
> -       struct mlxsw_thermal_module *tz = tzdev->devdata;
> +       struct mlxsw_thermal_module *tz = thermal_zone_device_get_data(tzdev);
>         struct mlxsw_thermal *thermal = tz->parent;
>         int temp, crit_temp, emerg_temp;
>         struct device *dev;
> @@ -391,7 +391,7 @@ static struct thermal_zone_device_ops mlxsw_thermal_module_ops = {
>  static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev,
>                                           int *p_temp)
>  {
> -       struct mlxsw_thermal_module *tz = tzdev->devdata;
> +       struct mlxsw_thermal_module *tz = thermal_zone_device_get_data(tzdev);
>         struct mlxsw_thermal *thermal = tz->parent;
>         char mtmp_pl[MLXSW_REG_MTMP_LEN];
>         u16 index;
> diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c
> index 232c200af38f..ee8fee29107f 100644
> --- a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c
> +++ b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c
> @@ -615,7 +615,7 @@ int iwl_mvm_send_temp_report_ths_cmd(struct iwl_mvm *mvm)
>  static int iwl_mvm_tzone_get_temp(struct thermal_zone_device *device,
>                                   int *temperature)
>  {
> -       struct iwl_mvm *mvm = (struct iwl_mvm *)device->devdata;
> +       struct iwl_mvm *mvm = thermal_zone_device_get_data(device);
>         int ret;
>         int temp;
>  
> @@ -641,7 +641,7 @@ static int iwl_mvm_tzone_get_temp(struct thermal_zone_device *device,
>  static int iwl_mvm_tzone_set_trip_temp(struct thermal_zone_device *device,
>                                        int trip, int temp)
>  {
> -       struct iwl_mvm *mvm = (struct iwl_mvm *)device->devdata;
> +       struct iwl_mvm *mvm = thermal_zone_device_get_data(device);
>         struct iwl_mvm_thermal_device *tzone;
>         int ret;
>  
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index 7c790c41e2fe..166f0aacc797 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -1142,7 +1142,7 @@ static int power_supply_read_temp(struct thermal_zone_device *tzd,
>         int ret;
>  
>         WARN_ON(tzd == NULL);
> -       psy = tzd->devdata;
> +       psy = thermal_zone_device_get_data(tzd);
>         ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_TEMP, &val);
>         if (ret)
>                 return ret;
> diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
> index 7e00a45db26a..ccacba66d367 100644
> --- a/drivers/regulator/max8973-regulator.c
> +++ b/drivers/regulator/max8973-regulator.c
> @@ -436,7 +436,7 @@ static int max8973_init_dcdc(struct max8973_chip *max,
>  
>  static int max8973_thermal_read_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct max8973_chip *mchip = tz->devdata;
> +       struct max8973_chip *mchip = thermal_zone_device_get_data(tz);
>         unsigned int val;
>         int ret;
>  
> diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c
> index 2efc222a379b..82d3e15d51f6 100644
> --- a/drivers/thermal/armada_thermal.c
> +++ b/drivers/thermal/armada_thermal.c
> @@ -398,7 +398,7 @@ static int armada_read_sensor(struct armada_thermal_priv *priv, int *temp)
>  static int armada_get_temp_legacy(struct thermal_zone_device *thermal,
>                                   int *temp)
>  {
> -       struct armada_thermal_priv *priv = thermal->devdata;
> +       struct armada_thermal_priv *priv = thermal_zone_device_get_data(thermal);
>         int ret;
>  
>         /* Valid check */
> @@ -420,7 +420,7 @@ static struct thermal_zone_device_ops legacy_ops = {
>  
>  static int armada_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct armada_thermal_sensor *sensor = tz->devdata;
> +       struct armada_thermal_sensor *sensor = thermal_zone_device_get_data(tz);
>         struct armada_thermal_priv *priv = sensor->priv;
>         int ret;
>  
> diff --git a/drivers/thermal/broadcom/bcm2711_thermal.c b/drivers/thermal/broadcom/bcm2711_thermal.c
> index 1f8651d15160..18b1a4d9ecc7 100644
> --- a/drivers/thermal/broadcom/bcm2711_thermal.c
> +++ b/drivers/thermal/broadcom/bcm2711_thermal.c
> @@ -33,7 +33,7 @@ struct bcm2711_thermal_priv {
>  
>  static int bcm2711_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct bcm2711_thermal_priv *priv = tz->devdata;
> +       struct bcm2711_thermal_priv *priv = thermal_zone_device_get_data(tz);
>         int slope = thermal_zone_get_slope(tz);
>         int offset = thermal_zone_get_offset(tz);
>         u32 val;
> diff --git a/drivers/thermal/broadcom/bcm2835_thermal.c b/drivers/thermal/broadcom/bcm2835_thermal.c
> index 23918bb76ae6..de2f573863da 100644
> --- a/drivers/thermal/broadcom/bcm2835_thermal.c
> +++ b/drivers/thermal/broadcom/bcm2835_thermal.c
> @@ -90,7 +90,7 @@ static int bcm2835_thermal_temp2adc(int temp, int offset, int slope)
>  
>  static int bcm2835_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct bcm2835_thermal_data *data = tz->devdata;
> +       struct bcm2835_thermal_data *data = thermal_zone_device_get_data(tz);
>         u32 val = readl(data->regs + BCM2835_TS_TSENSSTAT);
>  
>         if (!(val & BCM2835_TS_TSENSSTAT_VALID))
> diff --git a/drivers/thermal/broadcom/brcmstb_thermal.c b/drivers/thermal/broadcom/brcmstb_thermal.c
> index 4d02c28331e3..668cdc16b108 100644
> --- a/drivers/thermal/broadcom/brcmstb_thermal.c
> +++ b/drivers/thermal/broadcom/brcmstb_thermal.c
> @@ -152,7 +152,7 @@ static inline u32 avs_tmon_temp_to_code(struct brcmstb_thermal_priv *priv,
>  
>  static int brcmstb_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct brcmstb_thermal_priv *priv = tz->devdata;
> +       struct brcmstb_thermal_priv *priv = thermal_zone_device_get_data(tz);
>         u32 val;
>         long t;
>  
> @@ -262,7 +262,7 @@ static irqreturn_t brcmstb_tmon_irq_thread(int irq, void *data)
>  
>  static int brcmstb_set_trips(struct thermal_zone_device *tz, int low, int high)
>  {
> -       struct brcmstb_thermal_priv *priv = tz->devdata;
> +       struct brcmstb_thermal_priv *priv = thermal_zone_device_get_data(tz);
>  
>         dev_dbg(priv->dev, "set trips %d <--> %d\n", low, high);
>  
> diff --git a/drivers/thermal/broadcom/ns-thermal.c b/drivers/thermal/broadcom/ns-thermal.c
> index 07a8a3f49bd0..98296019ad4c 100644
> --- a/drivers/thermal/broadcom/ns-thermal.c
> +++ b/drivers/thermal/broadcom/ns-thermal.c
> @@ -16,7 +16,7 @@
>  
>  static int ns_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       void __iomem *pvtmon = tz->devdata;
> +       void __iomem *pvtmon = thermal_zone_device_get_data(tz);
>         int offset = thermal_zone_get_offset(tz);
>         int slope = thermal_zone_get_slope(tz);
>         u32 val;
> diff --git a/drivers/thermal/broadcom/sr-thermal.c b/drivers/thermal/broadcom/sr-thermal.c
> index 2b93502543ff..42b46125f409 100644
> --- a/drivers/thermal/broadcom/sr-thermal.c
> +++ b/drivers/thermal/broadcom/sr-thermal.c
> @@ -32,7 +32,7 @@ struct sr_thermal {
>  
>  static int sr_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct sr_tmon *tmon = tz->devdata;
> +       struct sr_tmon *tmon = thermal_zone_device_get_data(tz);
>         struct sr_thermal *sr_thermal = tmon->priv;
>  
>         *temp = readl(sr_thermal->regs + SR_TMON_TEMP_BASE(tmon->tmon_id));
> diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c
> index a805a6666c44..3d937f701e0b 100644
> --- a/drivers/thermal/da9062-thermal.c
> +++ b/drivers/thermal/da9062-thermal.c
> @@ -123,7 +123,7 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data)
>  static int da9062_thermal_get_temp(struct thermal_zone_device *z,
>                                    int *temp)
>  {
> -       struct da9062_thermal *thermal = z->devdata;
> +       struct da9062_thermal *thermal = thermal_zone_device_get_data(z);
>  
>         mutex_lock(&thermal->lock);
>         *temp = thermal->temperature;
> diff --git a/drivers/thermal/dove_thermal.c b/drivers/thermal/dove_thermal.c
> index 056622a58d00..ed7d1173d9fd 100644
> --- a/drivers/thermal/dove_thermal.c
> +++ b/drivers/thermal/dove_thermal.c
> @@ -87,7 +87,7 @@ static int dove_get_temp(struct thermal_zone_device *thermal,
>                           int *temp)
>  {
>         unsigned long reg;
> -       struct dove_thermal_priv *priv = thermal->devdata;
> +       struct dove_thermal_priv *priv = thermal_zone_device_get_data(thermal);
>  
>         /* Valid check */
>         reg = readl_relaxed(priv->control + PMU_TEMP_DIOD_CTRL1_REG);
> diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c
> index 32a7c3cf073d..043751e6a31d 100644
> --- a/drivers/thermal/hisi_thermal.c
> +++ b/drivers/thermal/hisi_thermal.c
> @@ -431,7 +431,7 @@ static int hi3660_thermal_probe(struct hisi_thermal_data *data)
>  
>  static int hisi_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct hisi_thermal_sensor *sensor = tz->devdata;
> +       struct hisi_thermal_sensor *sensor = thermal_zone_device_get_data(tz);
>         struct hisi_thermal_data *data = sensor->data;
>  
>         *temp = data->ops->get_temp(sensor);
> diff --git a/drivers/thermal/imx8mm_thermal.c b/drivers/thermal/imx8mm_thermal.c
> index 72b5d6f319c1..750240f4fa32 100644
> --- a/drivers/thermal/imx8mm_thermal.c
> +++ b/drivers/thermal/imx8mm_thermal.c
> @@ -141,7 +141,7 @@ static int imx8mp_tmu_get_temp(void *data, int *temp)
>  
>  static int tmu_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct tmu_sensor *sensor = tz->devdata;
> +       struct tmu_sensor *sensor = thermal_zone_device_get_data(tz);
>         struct imx8mm_tmu *tmu = sensor->priv;
>  
>         return tmu->socdata->get_temp(sensor, temp);
> diff --git a/drivers/thermal/imx_sc_thermal.c b/drivers/thermal/imx_sc_thermal.c
> index f32e59e74623..ca10d6a68f0f 100644
> --- a/drivers/thermal/imx_sc_thermal.c
> +++ b/drivers/thermal/imx_sc_thermal.c
> @@ -46,7 +46,7 @@ static int imx_sc_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
>         struct imx_sc_msg_misc_get_temp msg;
>         struct imx_sc_rpc_msg *hdr = &msg.hdr;
> -       struct imx_sc_sensor *sensor = tz->devdata;
> +       struct imx_sc_sensor *sensor = thermal_zone_device_get_data(tz);
>         int ret;
>  
>         msg.data.req.resource_id = sensor->resource_id;
> diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
> index fb0d5cab70af..c3c14cd26aee 100644
> --- a/drivers/thermal/imx_thermal.c
> +++ b/drivers/thermal/imx_thermal.c
> @@ -252,7 +252,7 @@ static void imx_set_alarm_temp(struct imx_thermal_data *data,
>  
>  static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct imx_thermal_data *data = tz->devdata;
> +       struct imx_thermal_data *data = thermal_zone_device_get_data(tz);
>         const struct thermal_soc_data *soc_data = data->socdata;
>         struct regmap *map = data->tempmon;
>         unsigned int n_meas;
> @@ -311,7 +311,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
>  static int imx_change_mode(struct thermal_zone_device *tz,
>                            enum thermal_device_mode mode)
>  {
> -       struct imx_thermal_data *data = tz->devdata;
> +       struct imx_thermal_data *data = thermal_zone_device_get_data(tz);
>  
>         if (mode == THERMAL_DEVICE_ENABLED) {
>                 pm_runtime_get(data->dev);
> @@ -342,7 +342,7 @@ static int imx_get_crit_temp(struct thermal_zone_device *tz, int *temp)
>  static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip,
>                              int temp)
>  {
> -       struct imx_thermal_data *data = tz->devdata;
> +       struct imx_thermal_data *data = thermal_zone_device_get_data(tz);
>         int ret;
>  
>         ret = pm_runtime_resume_and_get(data->dev);
> diff --git a/drivers/thermal/intel/intel_pch_thermal.c b/drivers/thermal/intel/intel_pch_thermal.c
> index b855d031a855..e53f8a8c06e5 100644
> --- a/drivers/thermal/intel/intel_pch_thermal.c
> +++ b/drivers/thermal/intel/intel_pch_thermal.c
> @@ -119,7 +119,7 @@ static int pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, int trip)
>  
>  static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp)
>  {
> -       struct pch_thermal_device *ptd = tzd->devdata;
> +       struct pch_thermal_device *ptd = thermal_zone_device_get_data(tzd);
>  
>         *temp = GET_WPT_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TEMP));
>         return 0;
> diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c
> index 8c26f7b2316b..f7d995722e04 100644
> --- a/drivers/thermal/intel/intel_soc_dts_iosf.c
> +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c
> @@ -54,7 +54,7 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd, int trip,
>         struct intel_soc_dts_sensor_entry *dts;
>         struct intel_soc_dts_sensors *sensors;
>  
> -       dts = tzd->devdata;
> +       dts = thermal_zone_device_get_data(tzd);
>         sensors = dts->sensors;
>         mutex_lock(&sensors->dts_update_lock);
>         status = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ,
> @@ -168,7 +168,7 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts,
>  static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
>                              int temp)
>  {
> -       struct intel_soc_dts_sensor_entry *dts = tzd->devdata;
> +       struct intel_soc_dts_sensor_entry *dts = thermal_zone_device_get_data(tzd);
>         struct intel_soc_dts_sensors *sensors = dts->sensors;
>         int status;
>  
> @@ -176,7 +176,7 @@ static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
>                 return -EINVAL;
>  
>         mutex_lock(&sensors->dts_update_lock);
> -       status = update_trip_temp(tzd->devdata, trip, temp,
> +       status = update_trip_temp(dts, trip, temp,
>                                   dts->trip_types[trip]);
>         mutex_unlock(&sensors->dts_update_lock);
>  
> @@ -186,9 +186,7 @@ static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
>  static int sys_get_trip_type(struct thermal_zone_device *tzd,
>                              int trip, enum thermal_trip_type *type)
>  {
> -       struct intel_soc_dts_sensor_entry *dts;
> -
> -       dts = tzd->devdata;
> +       struct intel_soc_dts_sensor_entry *dts = thermal_zone_device_get_data(tzd);
>  
>         *type = dts->trip_types[trip];
>  
> @@ -200,11 +198,10 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd,
>  {
>         int status;
>         u32 out;
> -       struct intel_soc_dts_sensor_entry *dts;
> +       struct intel_soc_dts_sensor_entry *dts = thermal_zone_device_get_data(tzd);
>         struct intel_soc_dts_sensors *sensors;
>         unsigned long raw;
>  
> -       dts = tzd->devdata;
>         sensors = dts->sensors;
>         status = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ,
>                                SOC_DTS_OFFSET_TEMP, &out);
> diff --git a/drivers/thermal/intel/x86_pkg_temp_thermal.c b/drivers/thermal/intel/x86_pkg_temp_thermal.c
> index 1c2de84742df..22f0f206d8f2 100644
> --- a/drivers/thermal/intel/x86_pkg_temp_thermal.c
> +++ b/drivers/thermal/intel/x86_pkg_temp_thermal.c
> @@ -107,7 +107,7 @@ static struct zone_device *pkg_temp_thermal_get_dev(unsigned int cpu)
>  
>  static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
>  {
> -       struct zone_device *zonedev = tzd->devdata;
> +       struct zone_device *zonedev = thermal_zone_device_get_data(tzd);
>         int val;
>  
>         val = intel_tcc_get_temp(zonedev->cpu, true);
> @@ -122,7 +122,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
>  static int
>  sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
>  {
> -       struct zone_device *zonedev = tzd->devdata;
> +       struct zone_device *zonedev = thermal_zone_device_get_data(tzd);
>         u32 l, h, mask, shift, intr;
>         int tj_max, ret;
>  
> diff --git a/drivers/thermal/k3_bandgap.c b/drivers/thermal/k3_bandgap.c
> index 22c9bcb899c3..8cbd7361b492 100644
> --- a/drivers/thermal/k3_bandgap.c
> +++ b/drivers/thermal/k3_bandgap.c
> @@ -141,7 +141,7 @@ static int k3_bgp_read_temp(struct k3_thermal_data *devdata,
>  
>  static int k3_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct k3_thermal_data *data = tz->devdata;
> +       struct k3_thermal_data *data = thermal_zone_device_get_data(tz);
>         int ret = 0;
>  
>         ret = k3_bgp_read_temp(data, temp);
> diff --git a/drivers/thermal/k3_j72xx_bandgap.c b/drivers/thermal/k3_j72xx_bandgap.c
> index 031ea1091909..300a3f985776 100644
> --- a/drivers/thermal/k3_j72xx_bandgap.c
> +++ b/drivers/thermal/k3_j72xx_bandgap.c
> @@ -248,7 +248,7 @@ static inline int k3_bgp_read_temp(struct k3_thermal_data *devdata,
>  /* Get temperature callback function for thermal zone */
>  static int k3_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       return k3_bgp_read_temp(tz->devdata, temp);
> +       return k3_bgp_read_temp(thermal_zone_device_get_data(tz), temp);
>  }
>  
>  static const struct thermal_zone_device_ops k3_of_thermal_ops = {
> diff --git a/drivers/thermal/kirkwood_thermal.c b/drivers/thermal/kirkwood_thermal.c
> index bec7ec20e79d..8e39c875ba58 100644
> --- a/drivers/thermal/kirkwood_thermal.c
> +++ b/drivers/thermal/kirkwood_thermal.c
> @@ -27,7 +27,7 @@ static int kirkwood_get_temp(struct thermal_zone_device *thermal,
>                           int *temp)
>  {
>         unsigned long reg;
> -       struct kirkwood_thermal_priv *priv = thermal->devdata;
> +       struct kirkwood_thermal_priv *priv = thermal_zone_device_get_data(thermal);
>  
>         reg = readl_relaxed(priv->sensor);
>  
> diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c
> index 6451a55eb582..05b6e9a2a283 100644
> --- a/drivers/thermal/max77620_thermal.c
> +++ b/drivers/thermal/max77620_thermal.c
> @@ -46,7 +46,7 @@ struct max77620_therm_info {
>  
>  static int max77620_thermal_read_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct max77620_therm_info *mtherm = tz->devdata;
> +       struct max77620_therm_info *mtherm = thermal_zone_device_get_data(tz);
>         unsigned int val;
>         int ret;
>  
> diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c
> index ab730f9552d0..d7bf725d224b 100644
> --- a/drivers/thermal/mediatek/auxadc_thermal.c
> +++ b/drivers/thermal/mediatek/auxadc_thermal.c
> @@ -763,7 +763,7 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
>  
>  static int mtk_read_temp(struct thermal_zone_device *tz, int *temperature)
>  {
> -       struct mtk_thermal *mt = tz->devdata;
> +       struct mtk_thermal *mt = thermal_zone_device_get_data(tz);
>         int i;
>         int tempmax = INT_MIN;
>  
> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> index 84ba65a27acf..86d280187c83 100644
> --- a/drivers/thermal/mediatek/lvts_thermal.c
> +++ b/drivers/thermal/mediatek/lvts_thermal.c
> @@ -252,7 +252,7 @@ static u32 lvts_temp_to_raw(int temperature)
>  
>  static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct lvts_sensor *lvts_sensor = tz->devdata;
> +       struct lvts_sensor *lvts_sensor = thermal_zone_device_get_data(tz);
>         void __iomem *msr = lvts_sensor->msr;
>         u32 value;
>  
> @@ -290,7 +290,7 @@ static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
>  
>  static int lvts_set_trips(struct thermal_zone_device *tz, int low, int high)
>  {
> -       struct lvts_sensor *lvts_sensor = tz->devdata;
> +       struct lvts_sensor *lvts_sensor = thermal_zone_device_get_data(tz);
>         void __iomem *base = lvts_sensor->base;
>         u32 raw_low = lvts_temp_to_raw(low);
>         u32 raw_high = lvts_temp_to_raw(high);
> diff --git a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
> index 31164ade2dd1..b0269daf128a 100644
> --- a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
> +++ b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
> @@ -360,7 +360,7 @@ static irqreturn_t adc_tm5_gen2_isr(int irq, void *data)
>  
>  static int adc_tm5_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct adc_tm5_channel *channel = tz->devdata;
> +       struct adc_tm5_channel *channel = thermal_zone_device_get_data(tz);
>         int ret;
>  
>         if (!channel || !channel->iio)
> @@ -642,7 +642,7 @@ static int adc_tm5_gen2_configure(struct adc_tm5_channel *channel, int low, int
>  
>  static int adc_tm5_set_trips(struct thermal_zone_device *tz, int low, int high)
>  {
> -       struct adc_tm5_channel *channel = tz->devdata;
> +       struct adc_tm5_channel *channel = thermal_zone_device_get_data(tz);
>         struct adc_tm5_chip *chip;
>         int ret;
>  
> diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
> index 101c75d0e13f..c817b03deb00 100644
> --- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
> +++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
> @@ -187,7 +187,7 @@ static int qpnp_tm_update_temp_no_adc(struct qpnp_tm_chip *chip)
>  
>  static int qpnp_tm_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct qpnp_tm_chip *chip = tz->devdata;
> +       struct qpnp_tm_chip *chip = thermal_zone_device_get_data(tz);
>         int ret, mili_celsius;
>  
>         if (!temp)
> @@ -265,7 +265,7 @@ static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip,
>  
>  static int qpnp_tm_set_trip_temp(struct thermal_zone_device *tz, int trip_id, int temp)
>  {
> -       struct qpnp_tm_chip *chip = tz->devdata;
> +       struct qpnp_tm_chip *chip = thermal_zone_device_get_data(tz);
>         struct thermal_trip trip;
>         int ret;
>  
> diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
> index 431c29c0898a..8b6fe0c9ade2 100644
> --- a/drivers/thermal/qoriq_thermal.c
> +++ b/drivers/thermal/qoriq_thermal.c
> @@ -83,7 +83,7 @@ static struct qoriq_tmu_data *qoriq_sensor_to_data(struct qoriq_sensor *s)
>  
>  static int tmu_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct qoriq_sensor *qsensor = tz->devdata;
> +       struct qoriq_sensor *qsensor = thermal_zone_device_get_data(tz);
>         struct qoriq_tmu_data *qdata = qoriq_sensor_to_data(qsensor);
>         u32 val;
>         /*
> diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c
> index d6b5b59c5c53..8ad713cb4bf7 100644
> --- a/drivers/thermal/rcar_gen3_thermal.c
> +++ b/drivers/thermal/rcar_gen3_thermal.c
> @@ -167,7 +167,7 @@ static int rcar_gen3_thermal_round(int temp)
>  
>  static int rcar_gen3_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct rcar_gen3_thermal_tsc *tsc = tz->devdata;
> +       struct rcar_gen3_thermal_tsc *tsc = thermal_zone_device_get_data(tz);
>         int mcelsius, val;
>         int reg;
>  
> @@ -206,7 +206,7 @@ static int rcar_gen3_thermal_mcelsius_to_temp(struct rcar_gen3_thermal_tsc *tsc,
>  
>  static int rcar_gen3_thermal_set_trips(struct thermal_zone_device *tz, int low, int high)
>  {
> -       struct rcar_gen3_thermal_tsc *tsc = tz->devdata;
> +       struct rcar_gen3_thermal_tsc *tsc = thermal_zone_device_get_data(tz);
>         u32 irqmsk = 0;
>  
>         if (low != -INT_MAX) {
> diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
> index 436f5f9cf729..538ed6731589 100644
> --- a/drivers/thermal/rcar_thermal.c
> +++ b/drivers/thermal/rcar_thermal.c
> @@ -101,7 +101,6 @@ struct rcar_thermal_priv {
>         list_for_each_entry(pos, &common->head, list)
>  
>  #define MCELSIUS(temp)                 ((temp) * 1000)
> -#define rcar_zone_to_priv(zone)                ((zone)->devdata)
>  #define rcar_priv_to_dev(priv)         ((priv)->common->dev)
>  #define rcar_has_irq_support(priv)     ((priv)->common->base)
>  #define rcar_id_to_shift(priv)         ((priv)->id * 8)
> @@ -273,7 +272,7 @@ static int rcar_thermal_get_current_temp(struct rcar_thermal_priv *priv,
>  
>  static int rcar_thermal_get_temp(struct thermal_zone_device *zone, int *temp)
>  {
> -       struct rcar_thermal_priv *priv = rcar_zone_to_priv(zone);
> +       struct rcar_thermal_priv *priv = thermal_zone_device_get_data(zone);
>  
>         return rcar_thermal_get_current_temp(priv, temp);
>  }
> diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c
> index 4b7c43f34d1a..dafbdbb7c0c0 100644
> --- a/drivers/thermal/rockchip_thermal.c
> +++ b/drivers/thermal/rockchip_thermal.c
> @@ -1213,7 +1213,7 @@ static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev)
>  
>  static int rockchip_thermal_set_trips(struct thermal_zone_device *tz, int low, int high)
>  {
> -       struct rockchip_thermal_sensor *sensor = tz->devdata;
> +       struct rockchip_thermal_sensor *sensor = thermal_zone_device_get_data(tz);
>         struct rockchip_thermal_data *thermal = sensor->thermal;
>         const struct rockchip_tsadc_chip *tsadc = thermal->chip;
>  
> @@ -1226,7 +1226,7 @@ static int rockchip_thermal_set_trips(struct thermal_zone_device *tz, int low, i
>  
>  static int rockchip_thermal_get_temp(struct thermal_zone_device *tz, int *out_temp)
>  {
> -       struct rockchip_thermal_sensor *sensor = tz->devdata;
> +       struct rockchip_thermal_sensor *sensor = thermal_zone_device_get_data(tz);
>         struct rockchip_thermal_data *thermal = sensor->thermal;
>         const struct rockchip_tsadc_chip *tsadc = sensor->thermal->chip;
>         int retval;
> diff --git a/drivers/thermal/rzg2l_thermal.c b/drivers/thermal/rzg2l_thermal.c
> index 2e0649f38506..d3ba2a74e42d 100644
> --- a/drivers/thermal/rzg2l_thermal.c
> +++ b/drivers/thermal/rzg2l_thermal.c
> @@ -75,7 +75,7 @@ static inline void rzg2l_thermal_write(struct rzg2l_thermal_priv *priv, u32 reg,
>  
>  static int rzg2l_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct rzg2l_thermal_priv *priv = tz->devdata;
> +       struct rzg2l_thermal_priv *priv = thermal_zone_device_get_data(tz);
>         u32 result = 0, dsensor, ts_code_ave;
>         int val, i;
>  
> diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
> index 527d1eb0663a..a2301e235a2b 100644
> --- a/drivers/thermal/samsung/exynos_tmu.c
> +++ b/drivers/thermal/samsung/exynos_tmu.c
> @@ -645,7 +645,7 @@ static void exynos7_tmu_control(struct platform_device *pdev, bool on)
>  
>  static int exynos_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct exynos_tmu_data *data = tz->devdata;
> +       struct exynos_tmu_data *data = thermal_zone_device_get_data(tz);
>         int value, ret = 0;
>  
>         if (!data || !data->tmu_read)
> @@ -723,7 +723,7 @@ static void exynos4412_tmu_set_emulation(struct exynos_tmu_data *data,
>  
>  static int exynos_tmu_set_emulation(struct thermal_zone_device *tz, int temp)
>  {
> -       struct exynos_tmu_data *data = tz->devdata;
> +       struct exynos_tmu_data *data = thermal_zone_device_get_data(tz);
>         int ret = -EINVAL;
>  
>         if (data->soc == SOC_ARCH_EXYNOS4210)
> diff --git a/drivers/thermal/spear_thermal.c b/drivers/thermal/spear_thermal.c
> index 6a722b10d738..62cd9305eb9c 100644
> --- a/drivers/thermal/spear_thermal.c
> +++ b/drivers/thermal/spear_thermal.c
> @@ -31,7 +31,7 @@ struct spear_thermal_dev {
>  static inline int thermal_get_temp(struct thermal_zone_device *thermal,
>                                 int *temp)
>  {
> -       struct spear_thermal_dev *stdev = thermal->devdata;
> +       struct spear_thermal_dev *stdev = thermal_zone_device_get_data(thermal);
>  
>         /*
>          * Data are ready to be read after 628 usec from POWERDOWN signal
> @@ -48,7 +48,7 @@ static struct thermal_zone_device_ops ops = {
>  static int __maybe_unused spear_thermal_suspend(struct device *dev)
>  {
>         struct thermal_zone_device *spear_thermal = dev_get_drvdata(dev);
> -       struct spear_thermal_dev *stdev = spear_thermal->devdata;
> +       struct spear_thermal_dev *stdev = thermal_zone_device_get_data(spear_thermal);
>         unsigned int actual_mask = 0;
>  
>         /* Disable SPEAr Thermal Sensor */
> @@ -64,7 +64,7 @@ static int __maybe_unused spear_thermal_suspend(struct device *dev)
>  static int __maybe_unused spear_thermal_resume(struct device *dev)
>  {
>         struct thermal_zone_device *spear_thermal = dev_get_drvdata(dev);
> -       struct spear_thermal_dev *stdev = spear_thermal->devdata;
> +       struct spear_thermal_dev *stdev = thermal_zone_device_get_data(spear_thermal);
>         unsigned int actual_mask = 0;
>         int ret = 0;
>  
> @@ -154,7 +154,7 @@ static int spear_thermal_exit(struct platform_device *pdev)
>  {
>         unsigned int actual_mask = 0;
>         struct thermal_zone_device *spear_thermal = platform_get_drvdata(pdev);
> -       struct spear_thermal_dev *stdev = spear_thermal->devdata;
> +       struct spear_thermal_dev *stdev = thermal_zone_device_get_data(spear_thermal);
>  
>         thermal_zone_device_unregister(spear_thermal);
>  
> diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c
> index ac884514f116..69078a55dc0c 100644
> --- a/drivers/thermal/sprd_thermal.c
> +++ b/drivers/thermal/sprd_thermal.c
> @@ -206,7 +206,7 @@ static int sprd_thm_temp_to_rawdata(int temp, struct sprd_thermal_sensor *sen)
>  
>  static int sprd_thm_read_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct sprd_thermal_sensor *sen = tz->devdata;
> +       struct sprd_thermal_sensor *sen = thermal_zone_device_get_data(tz);
>         u32 data;
>  
>         data = readl(sen->data->base + SPRD_THM_TEMP(sen->id)) &
> diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c
> index 497beac63e5d..085b7b0b7c72 100644
> --- a/drivers/thermal/sun8i_thermal.c
> +++ b/drivers/thermal/sun8i_thermal.c
> @@ -110,7 +110,7 @@ static int sun50i_h5_calc_temp(struct ths_device *tmdev,
>  
>  static int sun8i_ths_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct tsensor *s = tz->devdata;
> +       struct tsensor *s = thermal_zone_device_get_data(tz);
>         struct ths_device *tmdev = s->tmdev;
>         int val = 0;
>  
> diff --git a/drivers/thermal/tegra/tegra-bpmp-thermal.c b/drivers/thermal/tegra/tegra-bpmp-thermal.c
> index 0b7a1a1948cb..31a660b009fc 100644
> --- a/drivers/thermal/tegra/tegra-bpmp-thermal.c
> +++ b/drivers/thermal/tegra/tegra-bpmp-thermal.c
> @@ -62,12 +62,14 @@ static int __tegra_bpmp_thermal_get_temp(struct tegra_bpmp_thermal_zone *zone,
>  
>  static int tegra_bpmp_thermal_get_temp(struct thermal_zone_device *tz, int *out_temp)
>  {
> -       return __tegra_bpmp_thermal_get_temp(tz->devdata, out_temp);
> +       struct tegra_bpmp_thermal_zone *zone = thermal_zone_device_get_data(tz);
> +       
> +       return __tegra_bpmp_thermal_get_temp(zone, out_temp);
>  }
>  
>  static int tegra_bpmp_thermal_set_trips(struct thermal_zone_device *tz, int low, int high)
>  {
> -       struct tegra_bpmp_thermal_zone *zone = tz->devdata;
> +       struct tegra_bpmp_thermal_zone *zone = thermal_zone_device_get_data(tz);
>         struct mrq_thermal_host_to_bpmp_request req;
>         struct tegra_bpmp_message msg;
>         int err;
> diff --git a/drivers/thermal/tegra/tegra30-tsensor.c b/drivers/thermal/tegra/tegra30-tsensor.c
> index b3218b71b6d9..537413acc6d2 100644
> --- a/drivers/thermal/tegra/tegra30-tsensor.c
> +++ b/drivers/thermal/tegra/tegra30-tsensor.c
> @@ -160,7 +160,7 @@ static void devm_tegra_tsensor_hw_disable(void *data)
>  
>  static int tegra_tsensor_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       const struct tegra_tsensor_channel *tsc = tz->devdata;
> +       const struct tegra_tsensor_channel *tsc = thermal_zone_device_get_data(tz);
>         const struct tegra_tsensor *ts = tsc->ts;
>         int err, c1, c2, c3, c4, counter;
>         u32 val;
> @@ -218,7 +218,7 @@ static int tegra_tsensor_temp_to_counter(const struct tegra_tsensor *ts, int tem
>  
>  static int tegra_tsensor_set_trips(struct thermal_zone_device *tz, int low, int high)
>  {
> -       const struct tegra_tsensor_channel *tsc = tz->devdata;
> +       const struct tegra_tsensor_channel *tsc = thermal_zone_device_get_data(tz);
>         const struct tegra_tsensor *ts = tsc->ts;
>         u32 val;
>  
> diff --git a/drivers/thermal/thermal-generic-adc.c b/drivers/thermal/thermal-generic-adc.c
> index 323e273e3298..8e2ff0df7e64 100644
> --- a/drivers/thermal/thermal-generic-adc.c
> +++ b/drivers/thermal/thermal-generic-adc.c
> @@ -54,7 +54,7 @@ static int gadc_thermal_adc_to_temp(struct gadc_thermal_info *gti, int val)
>  
>  static int gadc_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
> -       struct gadc_thermal_info *gti = tz->devdata;
> +       struct gadc_thermal_info *gti = thermal_zone_device_get_data(tz);
>         int val;
>         int ret;
>  
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 0675df54c8e6..05e5a6bda695 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -1378,6 +1378,12 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, int n
>  }
>  EXPORT_SYMBOL_GPL(thermal_zone_device_register);
>  
> +void *thermal_zone_device_get_data(struct thermal_zone_device *tzd)
> +{
> +       return tzd->devdata;
> +}
> +EXPORT_SYMBOL_GPL(thermal_zone_device_get_data);
> +
>  /**
>   * thermal_zone_device_unregister - removes the registered thermal zone device
>   * @tz: the thermal zone device to remove
> diff --git a/drivers/thermal/thermal_mmio.c b/drivers/thermal/thermal_mmio.c
> index ea616731066c..05a70205f86f 100644
> --- a/drivers/thermal/thermal_mmio.c
> +++ b/drivers/thermal/thermal_mmio.c
> @@ -23,7 +23,7 @@ static u32 thermal_mmio_readb(void __iomem *mmio_base)
>  static int thermal_mmio_get_temperature(struct thermal_zone_device *tz, int *temp)
>  {
>         int t;
> -       struct thermal_mmio *sensor = tz->devdata;
> +       struct thermal_mmio *sensor = thermal_zone_device_get_data(tz);
>  
>         t = sensor->read_mmio(sensor->mmio_base) & sensor->mask;
>         t *= sensor->factor;
> diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
> index 8a9055bd376e..7f6b71d11eed 100644
> --- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
> +++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
> @@ -68,7 +68,7 @@ static inline int ti_thermal_hotspot_temperature(int t, int s, int c)
>  static inline int __ti_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
>         struct thermal_zone_device *pcb_tz = NULL;
> -       struct ti_thermal_data *data = tz->devdata;
> +       struct ti_thermal_data *data = thermal_zone_device_get_data(tz);
>         struct ti_bandgap *bgp;
>         const struct ti_temp_sensor *s;
>         int ret, tmp, slope, constant;
> @@ -109,7 +109,7 @@ static inline int __ti_thermal_get_temp(struct thermal_zone_device *tz, int *tem
>  
>  static int __ti_thermal_get_trend(struct thermal_zone_device *tz, int trip, enum thermal_trend *trend)
>  {
> -       struct ti_thermal_data *data = tz->devdata;
> +       struct ti_thermal_data *data = thermal_zone_device_get_data(tz);
>         struct ti_bandgap *bgp;
>         int id, tr, ret = 0;
>  
> diff --git a/drivers/thermal/uniphier_thermal.c b/drivers/thermal/uniphier_thermal.c
> index 47801841b3f5..25247de7780c 100644
> --- a/drivers/thermal/uniphier_thermal.c
> +++ b/drivers/thermal/uniphier_thermal.c
> @@ -187,7 +187,7 @@ static void uniphier_tm_disable_sensor(struct uniphier_tm_dev *tdev)
>  
>  static int uniphier_tm_get_temp(struct thermal_zone_device *tz, int *out_temp)
>  {
> -       struct uniphier_tm_dev *tdev = tz->devdata;
> +       struct uniphier_tm_dev *tdev = thermal_zone_device_get_data(tz);
>         struct regmap *map = tdev->regmap;
>         int ret;
>         u32 temp;
> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index 2bb4bf33f4f3..724b95662da9 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -365,6 +365,8 @@ thermal_zone_device_register_with_trips(const char *, struct thermal_trip *, int
>                                         void *, struct thermal_zone_device_ops *,
>                                         struct thermal_zone_params *, int, int);
>  
> +void *thermal_zone_device_get_data(struct thermal_zone_device *tzd);
> +
>  int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
>                                      struct thermal_cooling_device *,
>                                      unsigned long, unsigned long,

For iwlwifi:

Acked-by: Gregory Greenman <[email protected]>

Gregory

2023-02-20 10:50:54

by Balsam CHIHI

[permalink] [raw]
Subject: Re: [PATCH v1 06/17] thermal: Don't use 'device' internal thermal zone structure field

On Sun, Feb 19, 2023 at 3:38 PM Daniel Lezcano
<[email protected]> wrote:
>
> Some drivers are directly using the thermal zone's 'device' structure
> field.
>
> Use the driver device pointer instead of the thermal zone device when
> it is available.
>
> Remove the traces when they are duplicate with the traces in the core
> code.
>
> Signed-off-by: Daniel Lezcano <[email protected]>
> ---

> drivers/thermal/mediatek/lvts_thermal.c | 4 +-

> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> index 86d280187c83..a65a81114cc5 100644
> --- a/drivers/thermal/mediatek/lvts_thermal.c
> +++ b/drivers/thermal/mediatek/lvts_thermal.c
> @@ -305,7 +305,7 @@ static int lvts_set_trips(struct thermal_zone_device *tz, int low, int high)
> * 14-0 : Raw temperature for threshold
> */
> if (low != -INT_MAX) {
> - dev_dbg(&tz->device, "Setting low limit temperature interrupt: %d\n", low);
> + pr_debug("%s: Setting low limit temperature interrupt: %d\n", tz->type, low);
> writel(raw_low, LVTS_H2NTHRE(base));
> }
>
> @@ -318,7 +318,7 @@ static int lvts_set_trips(struct thermal_zone_device *tz, int low, int high)
> *
> * 14-0 : Raw temperature for threshold
> */
> - dev_dbg(&tz->device, "Setting high limit temperature interrupt: %d\n", high);
> + pr_debug("%s: Setting high limit temperature interrupt: %d\n", tz->type, high);
> writel(raw_high, LVTS_HTHRE(base));
>
> return 0;

for MediaTek LVTS :

Reviewed-by: Balsam CHIHI <[email protected]>

2023-02-20 11:03:40

by DLG Adam Ward

[permalink] [raw]
Subject: RE: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

On 19/02/23 14:37, Daniel Lezcano wrote:
>The thermal zone device structure is exposed to the different drivers and obviously they access the internals while that should be restricted to the core thermal code.
>
>In order to self-encapsulate the thermal core code, we need to prevent the drivers accessing directly the thermal zone structure and provide accessor functions to deal with.
>
>Provide an accessor to the 'devdata' structure and make use of it in the different drivers.
>No functional changes intended.
>
>Signed-off-by: Daniel Lezcano <[email protected]>
>---

>drivers/thermal/da9062-thermal.c | 2 +-

For da9062:

Reviewed-by: Adam Ward <[email protected]>


2023-02-20 11:14:06

by Baolin Wang

[permalink] [raw]
Subject: Re: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor



On 2/19/2023 10:36 PM, Daniel Lezcano wrote:
> The thermal zone device structure is exposed to the different drivers
> and obviously they access the internals while that should be
> restricted to the core thermal code.
>
> In order to self-encapsulate the thermal core code, we need to prevent
> the drivers accessing directly the thermal zone structure and provide
> accessor functions to deal with.
>
> Provide an accessor to the 'devdata' structure and make use of it in
> the different drivers.
>
> No functional changes intended.
>
> Signed-off-by: Daniel Lezcano <[email protected]>
> ---
[...]
> drivers/thermal/sprd_thermal.c | 2 +-

For sprd:
Reviewed-by: Baolin Wang <[email protected]>

2023-02-20 12:19:51

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

Hi Adam,

On Mon, Feb 20, 2023 at 12:14 PM DLG Adam Ward
<[email protected]> wrote:
> On 19/02/23 14:37, Daniel Lezcano wrote:
> >The thermal zone device structure is exposed to the different drivers and obviously they access the internals while that should be restricted to the core thermal code.
> >
> >In order to self-encapsulate the thermal core code, we need to prevent the drivers accessing directly the thermal zone structure and provide accessor functions to deal with.
> >
> >Provide an accessor to the 'devdata' structure and make use of it in the different drivers.
> >No functional changes intended.
> >
> >Signed-off-by: Daniel Lezcano <[email protected]>
> >---
>
> >drivers/thermal/da9062-thermal.c | 2 +-
>
> For da9062:
>
> Reviewed-by: Adam Ward <[email protected]>

Looks like Daniel has found the new Dialog maintainer he was looking
for? Time to update MAINTAINERS?

Thanks!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2023-02-20 13:24:05

by Sebastian Reichel

[permalink] [raw]
Subject: Re: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

Hi,

On Sun, Feb 19, 2023 at 03:36:41PM +0100, Daniel Lezcano wrote:
> The thermal zone device structure is exposed to the different drivers
> and obviously they access the internals while that should be
> restricted to the core thermal code.
>
> In order to self-encapsulate the thermal core code, we need to prevent
> the drivers accessing directly the thermal zone structure and provide
> accessor functions to deal with.
>
> Provide an accessor to the 'devdata' structure and make use of it in
> the different drivers.
>
> No functional changes intended.
>
> Signed-off-by: Daniel Lezcano <[email protected]>
> ---

...

> drivers/power/supply/power_supply_core.c | 2 +-

...

> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index 7c790c41e2fe..166f0aacc797 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -1142,7 +1142,7 @@ static int power_supply_read_temp(struct thermal_zone_device *tzd,
> int ret;
>
> WARN_ON(tzd == NULL);
> - psy = tzd->devdata;
> + psy = thermal_zone_device_get_data(tzd);
> ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_TEMP, &val);
> if (ret)
> return ret;

Acked-by: Sebastian Reichel <[email protected]>

-- Sebastian


Attachments:
(No filename) (1.29 kB)
signature.asc (833.00 B)
Download all attachments

2023-02-20 13:34:19

by Daniel Lezcano

[permalink] [raw]
Subject: Re: [PATCH v1 07/17] thermal/hwmon: Use the thermal API instead tampering the internals

Hi Guenter,

my script should have Cc'ed you but it didn't, so just a heads up this
patch ;)

On 19/02/2023 15:36, Daniel Lezcano wrote:
> In this function, there is a guarantee the thermal zone is registered.
>
> The sysfs hwmon unregistering will be blocked until we exit the
> function. The thermal zone is unregistered after the sysfs hwmon is
> unregistered.
>
> When we are in this function, the thermal zone is registered.
>
> We can call the thermal_zone_get_crit_temp() function safely and let
> the function use the lock which is private the thermal core code.
>
> Signed-off-by: Daniel Lezcano <[email protected]>
> ---
> drivers/thermal/thermal_hwmon.c | 10 +---------
> 1 file changed, 1 insertion(+), 9 deletions(-)
>
> diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
> index bc02095b314c..15158715b967 100644
> --- a/drivers/thermal/thermal_hwmon.c
> +++ b/drivers/thermal/thermal_hwmon.c
> @@ -77,15 +77,7 @@ temp_crit_show(struct device *dev, struct device_attribute *attr, char *buf)
> int temperature;
> int ret;
>
> - mutex_lock(&tz->lock);
> -
> - if (device_is_registered(&tz->device))
> - ret = tz->ops->get_crit_temp(tz, &temperature);
> - else
> - ret = -ENODEV;
> -
> - mutex_unlock(&tz->lock);
> -
> + ret = thermal_zone_get_crit_temp(tz, &temperature);
> if (ret)
> return ret;
>

--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


2023-02-20 14:13:00

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v1 07/17] thermal/hwmon: Use the thermal API instead tampering the internals

On Mon, Feb 20, 2023 at 02:34:08PM +0100, Daniel Lezcano wrote:
> Hi Guenter,
>
> my script should have Cc'ed you but it didn't, so just a heads up this patch
> ;)
>
> On 19/02/2023 15:36, Daniel Lezcano wrote:
> > In this function, there is a guarantee the thermal zone is registered.
> >
> > The sysfs hwmon unregistering will be blocked until we exit the
> > function. The thermal zone is unregistered after the sysfs hwmon is
> > unregistered.
> >
> > When we are in this function, the thermal zone is registered.
> >
> > We can call the thermal_zone_get_crit_temp() function safely and let
> > the function use the lock which is private the thermal core code.
> >

Hmm, if you say so. That very same call used to cause a crash in
Chromebooks, which is why I had added the locking.

Guenter

> > Signed-off-by: Daniel Lezcano <[email protected]>
> > ---
> > drivers/thermal/thermal_hwmon.c | 10 +---------
> > 1 file changed, 1 insertion(+), 9 deletions(-)
> >
> > diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
> > index bc02095b314c..15158715b967 100644
> > --- a/drivers/thermal/thermal_hwmon.c
> > +++ b/drivers/thermal/thermal_hwmon.c
> > @@ -77,15 +77,7 @@ temp_crit_show(struct device *dev, struct device_attribute *attr, char *buf)
> > int temperature;
> > int ret;
> > - mutex_lock(&tz->lock);
> > -
> > - if (device_is_registered(&tz->device))
> > - ret = tz->ops->get_crit_temp(tz, &temperature);
> > - else
> > - ret = -ENODEV;
> > -
> > - mutex_unlock(&tz->lock);
> > -
> > + ret = thermal_zone_get_crit_temp(tz, &temperature);
> > if (ret)
> > return ret;
>
> --
> <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
>
> Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
> <http://twitter.com/#!/linaroorg> Twitter |
> <http://www.linaro.org/linaro-blog/> Blog
>

2023-02-20 14:48:58

by DLG Adam Ward

[permalink] [raw]
Subject: RE: [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor

On 20/02/2023 12:19, Geert Uytterhoeven wrote:

>Looks like Daniel has found the new Dialog maintainer he was looking for?

Not quite; I'm just filling in for a while, alongside other duties.

>Time to update MAINTAINERS?

Well, in our defence, an attempt was made - but pragmatism lost out to idealism:
https://lkml.org/lkml/2022/8/1/264
Fortunately, the original mailing list was sustained thus far...

Changes are settling down now, so yes, a patch to split support by device, and provide names in addition to the new mailing list, is indeed pending.

Regards,
Adam

2023-02-20 15:39:55

by Daniel Lezcano

[permalink] [raw]
Subject: Re: [PATCH v1 07/17] thermal/hwmon: Use the thermal API instead tampering the internals

On 20/02/2023 15:11, Guenter Roeck wrote:
> On Mon, Feb 20, 2023 at 02:34:08PM +0100, Daniel Lezcano wrote:
>> Hi Guenter,
>>
>> my script should have Cc'ed you but it didn't, so just a heads up this patch
>> ;)
>>
>> On 19/02/2023 15:36, Daniel Lezcano wrote:
>>> In this function, there is a guarantee the thermal zone is registered.
>>>
>>> The sysfs hwmon unregistering will be blocked until we exit the
>>> function. The thermal zone is unregistered after the sysfs hwmon is
>>> unregistered.
>>>
>>> When we are in this function, the thermal zone is registered.
>>>
>>> We can call the thermal_zone_get_crit_temp() function safely and let
>>> the function use the lock which is private the thermal core code.
>>>
>
> Hmm, if you say so. That very same call used to cause a crash in
> Chromebooks, which is why I had added the locking.

Mmh, I see. I guess we can assume thermal_hwmon is part of the core code
and remove this change.


--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


2023-02-20 17:12:17

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v1 07/17] thermal/hwmon: Use the thermal API instead tampering the internals

On Mon, Feb 20, 2023 at 04:39:48PM +0100, Daniel Lezcano wrote:
> On 20/02/2023 15:11, Guenter Roeck wrote:
> > On Mon, Feb 20, 2023 at 02:34:08PM +0100, Daniel Lezcano wrote:
> > > Hi Guenter,
> > >
> > > my script should have Cc'ed you but it didn't, so just a heads up this patch
> > > ;)
> > >
> > > On 19/02/2023 15:36, Daniel Lezcano wrote:
> > > > In this function, there is a guarantee the thermal zone is registered.
> > > >
> > > > The sysfs hwmon unregistering will be blocked until we exit the
> > > > function. The thermal zone is unregistered after the sysfs hwmon is
> > > > unregistered.
> > > >
> > > > When we are in this function, the thermal zone is registered.
> > > >
> > > > We can call the thermal_zone_get_crit_temp() function safely and let
> > > > the function use the lock which is private the thermal core code.
> > > >
> >
> > Hmm, if you say so. That very same call used to cause a crash in
> > Chromebooks, which is why I had added the locking.
>
> Mmh, I see. I guess we can assume thermal_hwmon is part of the core code and
> remove this change.
>

Yes. Anyway, the sequence of events was roughly as follows.

- thermal zone is device is registered
- hwmon device is registered
- userspace is triggered and starts reading device attributes
- while userspace has a hwmon attribute open, thermal device is unregistered
- hwmon device is unregistered (sysfs attribute is still open)
- hwmon device attribute function is called
- Since thermal device ops have been released after the thermal device
was unregistered, trying to call an ops callback fails.

That doesn't normally happen, but the Intel wireless driver has the habit
of registering a thermal zone early in its probe function, only to unregister
it immediately afterwards if the probe function fails. If some userspace
activity is triggered by the hwmon device registration, the thermal and
hwmon device removal may be timed such that the hwmon devive is removed
while one (or more) of its attribute files are still open. Normally that
doesn't matter, but it is fatal here since the ops callbacks are not owned
by the hwmon device but by the thermal device.

Essentially every ops callback has this problem.
thermal_zone_get_temp() had it as well, also associated with
a hwmon sysfs attribute read operation. See commit 1c6b30060777
("thermal/core: Ensure that thermal device is registered in
thermal_zone_get_temp").

If you don't want non-thermal code to access ->ops directly, the thermal
code would have to provide protected accessor functions, similar to
thermal_zone_get_temp().

Thanks,
Guenter

>
> --
> <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
>
> Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
> <http://twitter.com/#!/linaroorg> Twitter |
> <http://www.linaro.org/linaro-blog/> Blog
>

2023-02-21 16:08:09

by Daniel Lezcano

[permalink] [raw]
Subject: Re: [PATCH v1 07/17] thermal/hwmon: Use the thermal API instead tampering the internals

On 20/02/2023 18:12, Guenter Roeck wrote:
> On Mon, Feb 20, 2023 at 04:39:48PM +0100, Daniel Lezcano wrote:
>> On 20/02/2023 15:11, Guenter Roeck wrote:
>>> On Mon, Feb 20, 2023 at 02:34:08PM +0100, Daniel Lezcano wrote:
>>>> Hi Guenter,
>>>>
>>>> my script should have Cc'ed you but it didn't, so just a heads up this patch
>>>> ;)
>>>>
>>>> On 19/02/2023 15:36, Daniel Lezcano wrote:
>>>>> In this function, there is a guarantee the thermal zone is registered.
>>>>>
>>>>> The sysfs hwmon unregistering will be blocked until we exit the
>>>>> function. The thermal zone is unregistered after the sysfs hwmon is
>>>>> unregistered.
>>>>>
>>>>> When we are in this function, the thermal zone is registered.
>>>>>
>>>>> We can call the thermal_zone_get_crit_temp() function safely and let
>>>>> the function use the lock which is private the thermal core code.
>>>>>
>>>
>>> Hmm, if you say so. That very same call used to cause a crash in
>>> Chromebooks, which is why I had added the locking.
>>
>> Mmh, I see. I guess we can assume thermal_hwmon is part of the core code and
>> remove this change.
>>
>
> Yes. Anyway, the sequence of events was roughly as follows.
>
> - thermal zone is device is registered
> - hwmon device is registered
> - userspace is triggered and starts reading device attributes
> - while userspace has a hwmon attribute open, thermal device is unregistered
> - hwmon device is unregistered (sysfs attribute is still open)
> - hwmon device attribute function is called
> - Since thermal device ops have been released after the thermal device
> was unregistered, trying to call an ops callback fails.
>
> That doesn't normally happen, but the Intel wireless driver has the habit
> of registering a thermal zone early in its probe function, only to unregister
> it immediately afterwards if the probe function fails. If some userspace
> activity is triggered by the hwmon device registration, the thermal and
> hwmon device removal may be timed such that the hwmon devive is removed
> while one (or more) of its attribute files are still open. Normally that
> doesn't matter, but it is fatal here since the ops callbacks are not owned
> by the hwmon device but by the thermal device.
>
> Essentially every ops callback has this problem.
> thermal_zone_get_temp() had it as well, also associated with
> a hwmon sysfs attribute read operation. See commit 1c6b30060777
> ("thermal/core: Ensure that thermal device is registered in
> thermal_zone_get_temp").
>
> If you don't want non-thermal code to access ->ops directly, the thermal
> code would have to provide protected accessor functions, similar to
> thermal_zone_get_temp().

Hopefully we are getting rid of most of the ops soon ... :/



--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog