Support cooling device with ID in the OF
Subsystems (19)
cover Support cooling device with ID in the OF
A cooling device can be a single cooling device or a cooling device controller with multiple cooling devices attached to it.
The thermal framework builds a connection between a cooling device and a thermal zone when there is a trip point to be mitigated by the cooling device. In the Linux kernel thermal semantic, the action of connecting the cooling device and the thermal zone is called a binding.
The description of the aforementioned connection depends on the firmware definition and in our case it is through the device tree. The cooling map describes this connection.
How is it done ?
For a single cooling device, the DT describes:
* A cooling device:
mycooling_device {
...
};* A cooling map in a thermal zone
mythermal_zone {
...
cooling-maps {
map0 {
...
cooling-device = <&mycooling_device min max>;
...
};
}
...};
For a cooling device controller with multiple cooling devices attached, the DT describes:
* A cooling device controller:
mycooling_device_ctrl {
mycooling_device1 {
...
};
mycooling_device2 {
...
};
...
mycooling_deviceN {
...
};};
* A cooling map in a thermal zone
mythermal_zone {
...
cooling-maps {
map0 {
...
cooling-device = <&mycooling_device1 min max>;
...
};
}
...};
When the cooling device "mycooling_device" is registered, then the binding function will browse all the cooling maps and matches the node device pointer to do the association (the pĥandle in the cooling map vs the cooling device node).
That is how the connection between the cooling device and the thermal zone is done.
DT maintainers consider the above description with child nodes is incorrect if a child node doesn't have its own bindings as explained in the documentation [1].
Gaurav Kohli posted a series to support the QMI TMD (Qualcomm Messaging Interface based Thermal Mitigation Devices) [2]. This device is a dedicated, centralized cooling device controller managing a set of cooling devices.
Because of the above restrictions with child nodes there is no DT bindings allowing to do the connection between the cooling device inside the cooling device controller and a thermal zone.
A QMI TMD is not a standalone cooling device neither a multiple cooling devices with their own DT description.
For this reason, the proposed changes with child nodes has been rejected [3].
As a solution, it has been proposed to fold all these child nodes into an array and add an id in the cooling maps to identify the cooling device entry in the controller node [4].
Given the thermal zone has the same mechanism [5], that is a phandle to a sensor node and an sensor specifier. The proposed approach makes sense as it is consistent with the thermal zone description.
This series provides a cleanup around the usage of the OF code which is interleaved with non-OF code. The OF and the non-OF code are separated and remain self-encapsulated.
Then the function to register a cooling device is renamed to reflect the legacy usage and a new function is introduced with the id parameter.
Finally, the DT bindings is updated with the new format and the thermal OF is changed to handle the new DT bindings.
Given the trivial changes impacting the files outside of the thermal framework, this series is designed to have all changes going through the thermal tree.
Thanks!
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/writing-bindings.rst
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/
[5] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/thermal/thermal-zones.yaml#n99
Daniel Lezcano (13):
thermal/of: Move OF code where it belongs to thermal/driver/tegra/soctherm: Use devm_ variant when registering a
cooling device
thermal/core: Make thermal_cooling_device_init_complete() non static thermal/of: Move the node pointer assignation in the OF code file thermal/core: Remove node pointer parameter parameter when registering
a tz
thermal/core: Register cooling device non-OF drivers hwmon:: Use non-OF thermal cooling device register function thermal/core: Move OF functions def in the CONFIG_OF section in
thermal.h
thermal/core: Put of_node field cooling device structure under Kconfig
option
thermal/of: Rename the devm_thermal_of_cooling_device_register()
function
thermal/of: Introduce cooling device of_index
thermal/of: Pass the of_index and add a function to register with an
index
thermal/of: Process cooling device index in cooling-spec
Gaurav Kohli (1):
dt-bindings: thermal: cooling-devices: Update support for 3 cells
cooling device
.../thermal/thermal-cooling-devices.yaml | 8 +- .../bindings/thermal/thermal-zones.yaml | 3 +- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 2 +- drivers/hwmon/amc6821.c | 2 +- drivers/hwmon/aspeed-pwm-tacho.c | 5 +- drivers/hwmon/cros_ec_hwmon.c | 4 +- drivers/hwmon/dell-smm-hwmon.c | 4 +- drivers/hwmon/emc2305.c | 6 +- drivers/hwmon/gpio-fan.c | 6 +- drivers/hwmon/max6650.c | 6 +- drivers/hwmon/mlxreg-fan.c | 4 +- drivers/hwmon/npcm750-pwm-fan.c | 6 +- drivers/hwmon/pwm-fan.c | 5 +- drivers/hwmon/qnap-mcu-hwmon.c | 6 +- drivers/hwmon/tc654.c | 5 +- drivers/memory/tegra/tegra210-emc-core.c | 4 +- drivers/soc/qcom/qcom_aoss.c | 2 +- drivers/thermal/cpufreq_cooling.c | 2 +- drivers/thermal/cpuidle_cooling.c | 2 +- drivers/thermal/devfreq_cooling.c | 2 +- drivers/thermal/khadas_mcu_fan.c | 7 +- drivers/thermal/tegra/soctherm.c | 6 +- drivers/thermal/thermal_core.c | 60 ++------ drivers/thermal/thermal_core.h | 6 + drivers/thermal/thermal_of.c | 139 +++++++++++++++++- include/linux/thermal.h | 71 ++++++--- 26 files changed, 267 insertions(+), 106 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/14 thermal/of: Move OF code where it belongs to
The functions:
- thermal_of_cooling_device_register()
- devm_thermal_of_cooling_device_register()
are related to thermal-of but they are implemented in thermal-core. Move these functions to the right file.
Pure move patch.
No functional change intended.
--- drivers/thermal/thermal_core.c | 75 +--------------------------------- drivers/thermal/thermal_core.h | 5 +++ drivers/thermal/thermal_of.c | 72 ++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 74 deletions(-)
drivers/thermal/thermal_core.c +1 -74
@@ -1056,7 +1056,7 @@ static void thermal_cooling_device_init_complete(struct thermal_cooling_device ** Return: a pointer to the created struct thermal_cooling_device or an * ERR_PTR. Caller must check return value with IS_ERR*() helpers. */ -static struct thermal_cooling_device * +struct thermal_cooling_device *__thermal_cooling_device_register (struct device_node *np,const char *type,void *devdata,const struct thermal_cooling_device_ops *ops)
@@ -1163,79 +1163,6 @@ thermal_cooling_device_register(const char *type, void *devdata, }EXPORT_SYMBOL_GPL (thermal_cooling_device_register); -/** -* thermal_of_cooling_device_register() - register an OF thermal cooling device -* @np: a pointer to a device tree node. -* @type: the thermal cooling device type. -* @devdata: device private data. -* @ops: standard thermal cooling devices callbacks. -* -* This function will register a cooling device with device tree node reference. -* This interface function adds a new thermal cooling device (fan/processor/...) -* to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself -* to all the thermal zone devices registered at the same time. -* -* Return: a pointer to the created struct thermal_cooling_device or an -* ERR_PTR. Caller must check return value with IS_ERR*() helpers. -*/ -struct thermal_cooling_device * -thermal_of_cooling_device_register (struct device_node *np, -const char *type,void *devdata, -const struct thermal_cooling_device_ops *ops) -{ -return __thermal_cooling_device_register (np, type, devdata, ops); -} -EXPORT_SYMBOL_GPL (thermal_of_cooling_device_register); - -static void thermal_cooling_device_release (struct device *dev,void *res) -{ -thermal_cooling_device_unregister ( - *(struct thermal_cooling_device **)res); -} - -/** -* devm_thermal_of_cooling_device_register() - register an OF thermal cooling -* device -* @dev: a valid struct device pointer of a sensor device. -* @np: a pointer to a device tree node. -* @type: the thermal cooling device type. -* @devdata: device private data. -* @ops: standard thermal cooling devices callbacks. -* -* This function will register a cooling device with device tree node reference. -* This interface function adds a new thermal cooling device (fan/processor/...) -* to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself -* to all the thermal zone devices registered at the same time. -* -* Return: a pointer to the created struct thermal_cooling_device or an -* ERR_PTR. Caller must check return value with IS_ERR*() helpers. -*/ -struct thermal_cooling_device * -devm_thermal_of_cooling_device_register (struct device *dev, -struct device_node *np, -const char *type,void *devdata, -const struct thermal_cooling_device_ops *ops) -{ -struct thermal_cooling_device **ptr, *tcd; - - ptr =devres_alloc (thermal_cooling_device_release,sizeof (*ptr), -GFP_KERNEL ); -if (!ptr) -return ERR_PTR (-ENOMEM ); - - tcd =__thermal_cooling_device_register (np, type, devdata, ops); -if (IS_ERR (tcd)) { -devres_free (ptr); -return tcd; - } - - *ptr = tcd; -devres_add (dev, ptr); - -return tcd; -} -EXPORT_SYMBOL_GPL (devm_thermal_of_cooling_device_register); -static bool thermal_cooling_device_present (struct thermal_cooling_device *cdev) {struct thermal_cooling_device *pos =NULL ;
drivers/thermal/thermal_core.h +5 -0
@@ -269,6 +269,11 @@ void thermal_zone_device_critical_shutdown(struct thermal_zone_device *tz);void thermal_governor_update_tz (struct thermal_zone_device *tz,enum thermal_notify_event reason); +struct thermal_cooling_device * +__thermal_cooling_device_register (struct device_node *np, +const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops); +/* Helpers */ #define for_each_trip_desc (__tz, __td) \ for (__td = __tz->trips; __td - __tz->trips < __tz->num_trips; __td++)
drivers/thermal/thermal_of.c +72 -0
75 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 2/14 thermal/driver/tegra/soctherm: Use devm_ variant when registering a cooling device
In reply to Daniel LezcanoThe driver invokes thermal_of_cooling_device_register() at probe time but without unregistering it at remove time.
As we have a devm_ variant, use it and the cooling device should be automatically removed.
Compiled-tested only.
--- drivers/thermal/tegra/soctherm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/thermal/tegra/soctherm.c +3 -3
@@ -1700,9 +1700,9 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev) stc->init = true; }else { - tcd =thermal_of_cooling_device_register (np_stcc, - (char *)name, ts, - &throt_cooling_ops); + tcd =devm_thermal_of_cooling_device_register (dev, np_stcc, + (char *)name, ts, + &throt_cooling_ops);if (IS_ERR_OR_NULL (tcd)) { dev_err(dev, "throttle-cfg: %s: failed to register cooling device\n",
Signature · 1 line
2.43.0
PATCH 3/14 thermal/core: Make thermal_cooling_device_init_complete() non static
In reply to Daniel LezcanoIn the process of separating clearly the OF code and the thermal core code, let's split and export the thermal_cooling_device_init_complete() function so it can be used by an implementation inside the thermal OF code.
--- drivers/thermal/thermal_core.c | 12 ++++++++---- drivers/thermal/thermal_core.h | 2 ++ drivers/thermal/thermal_of.c | 10 +++++++++- 3 files changed, 19 insertions(+), 5 deletions(-)
drivers/thermal/thermal_core.c +8 -4
@@ -1028,7 +1028,7 @@ static void thermal_zone_cdev_bind(struct thermal_zone_device *tz,__thermal_zone_device_update (tz,THERMAL_EVENT_UNSPECIFIED ); } -static void thermal_cooling_device_init_complete (struct thermal_cooling_device *cdev) +void thermal_cooling_device_init_complete (struct thermal_cooling_device *cdev) {struct thermal_zone_device *tz;
@@ -1127,8 +1127,6 @@ __thermal_cooling_device_register(struct device_node *np,if (current_state <= cdev->max_state)thermal_debug_cdev_add (cdev, current_state); -thermal_cooling_device_init_complete (cdev); -return cdev; out_cooling_dev:
@@ -1159,7 +1157,13 @@ struct thermal_cooling_device * thermal_cooling_device_register(const char *type, void *devdata, const struct thermal_cooling_device_ops *ops) { - return __thermal_cooling_device_register(NULL, type, devdata, ops); + struct thermal_cooling_device *cdev; + + cdev =__thermal_cooling_device_register (NULL , type, devdata, ops); +if (!IS_ERR (cdev)) +thermal_cooling_device_init_complete (cdev); + +return cdev; }EXPORT_SYMBOL_GPL (thermal_cooling_device_register);
drivers/thermal/thermal_core.h +2 -0
@@ -269,6 +269,8 @@ void thermal_zone_device_critical_shutdown(struct thermal_zone_device *tz);void thermal_governor_update_tz (struct thermal_zone_device *tz,enum thermal_notify_event reason); +void thermal_cooling_device_init_complete (struct thermal_cooling_device *cdev); +struct thermal_cooling_device * __thermal_cooling_device_register(struct device_node *np, const char *type, void *devdata,
drivers/thermal/thermal_of.c +9 -1
@@ -531,7 +531,15 @@ thermal_of_cooling_device_register(struct device_node *np, const char *type, void *devdata, const struct thermal_cooling_device_ops *ops) { - return __thermal_cooling_device_register(np, type, devdata, ops); + struct thermal_cooling_device *cdev; + + cdev =__thermal_cooling_device_register (np, type, devdata, ops); +if (IS_ERR (cdev)) +return cdev; + +thermal_cooling_device_init_complete (cdev); + +return cdev; }EXPORT_SYMBOL_GPL (thermal_of_cooling_device_register);
Signature · 1 line
2.43.0
PATCH 4/14 thermal/of: Move the node pointer assignation in the OF code file
In reply to Daniel LezcanoThe node pointer being assigned to the cooling device structure is an action done by the thermal OF only and does not belong to the core framework code. Move the node pointer assignation in the thermal OF code. Consequently, the devm_thermal_of_cooling_device_register() can call its non-devm version resulting in a more intuitive design of the API.
--- drivers/thermal/thermal_core.c | 1 - drivers/thermal/thermal_of.c | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/thermal/thermal_core.c +0 -1
@@ -1089,7 +1089,6 @@ __thermal_cooling_device_register(struct device_node *np,mutex_init (&cdev->lock);INIT_LIST_HEAD (&cdev->thermal_instances); - cdev->np = np; cdev->ops = ops; cdev->updated = false; cdev->device.class = &thermal_class;
drivers/thermal/thermal_of.c +2 -1
@@ -537,6 +537,7 @@ thermal_of_cooling_device_register(struct device_node *np,if (IS_ERR (cdev))return cdev; + cdev->np = np;thermal_cooling_device_init_complete (cdev);return cdev;
@@ -578,7 +579,7 @@ devm_thermal_of_cooling_device_register(struct device *dev,if (!ptr)return ERR_PTR (-ENOMEM ); - tcd =__thermal_cooling_device_register (np, type, devdata, ops); + tcd =thermal_of_cooling_device_register (np, type, devdata, ops);if (IS_ERR (tcd)) {devres_free (ptr);return tcd;
Signature · 1 line
2.43.0
PATCH 5/14 thermal/core: Remove node pointer parameter parameter when registering a tz
In reply to Daniel LezcanoNow we have a OF version for all functions registering a thermal zone or a cooling device. Let's remove the device_node pointer parameter in the core function which is inconsistent with non-OF code.
--- drivers/thermal/thermal_core.c | 6 ++---- drivers/thermal/thermal_core.h | 3 +-- drivers/thermal/thermal_of.c | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-)
drivers/thermal/thermal_core.c +2 -4
@@ -1042,7 +1042,6 @@ void thermal_cooling_device_init_complete(struct thermal_cooling_device *cdev)/** * __thermal_cooling_device_register() - register a new thermal cooling device -* @np: a pointer to a device tree node. * @type: the thermal cooling device type. * @devdata: device private data. * @ops: standard thermal cooling devices callbacks.
@@ -1057,8 +1056,7 @@ void thermal_cooling_device_init_complete(struct thermal_cooling_device *cdev)* ERR_PTR. Caller must check return value with IS_ERR*() helpers. */ struct thermal_cooling_device * -__thermal_cooling_device_register (struct device_node *np, -const char *type,void *devdata, +__thermal_cooling_device_register (const char *type,void *devdata,const struct thermal_cooling_device_ops *ops) {struct thermal_cooling_device *cdev;
@@ -1158,7 +1156,7 @@ thermal_cooling_device_register(const char *type, void *devdata, {struct thermal_cooling_device *cdev; - cdev =__thermal_cooling_device_register (NULL , type, devdata, ops); + cdev =__thermal_cooling_device_register (type, devdata, ops);if (!IS_ERR (cdev))thermal_cooling_device_init_complete (cdev);
drivers/thermal/thermal_core.h +1 -2
@@ -272,8 +272,7 @@ void thermal_governor_update_tz(struct thermal_zone_device *tz,void thermal_cooling_device_init_complete (struct thermal_cooling_device *cdev);struct thermal_cooling_device * -__thermal_cooling_device_register (struct device_node *np, -const char *type,void *devdata, +__thermal_cooling_device_register (const char *type,void *devdata,const struct thermal_cooling_device_ops *ops);/* Helpers */
drivers/thermal/thermal_of.c +1 -1
@@ -533,7 +533,7 @@ thermal_of_cooling_device_register(struct device_node *np, {struct thermal_cooling_device *cdev; - cdev =__thermal_cooling_device_register (np, type, devdata, ops); + cdev =__thermal_cooling_device_register (type, devdata, ops);if (IS_ERR (cdev))return cdev;
Signature · 1 line
2.43.0
PATCH 6/14 thermal/core: Register cooling device non-OF drivers
In reply to Daniel LezcanoProvide a non-OF functions to register a cooling device in order to have a clear separation between OF and non-OF code. Drivers not using a devicetree can then migrate to this function.
--- drivers/thermal/thermal_core.c | 44 ++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 13 ++++++++++ 2 files changed, 57 insertions(+)
drivers/thermal/thermal_core.c +44 -0
@@ -1164,6 +1164,50 @@ thermal_cooling_device_register(const char *type, void *devdata, }EXPORT_SYMBOL_GPL (thermal_cooling_device_register); +static void thermal_cooling_device_release (struct device *dev,void *res) +{ +thermal_cooling_device_unregister (*(struct thermal_cooling_device **)res); +} + +/** +* devm_thermal_cooling_device_register() - register a thermal cooling device +* @dev: a valid struct device pointer of a sensor device. +* @type: the thermal cooling device type. +* @devdata: device private data. +* @ops: standard thermal cooling devices callbacks. +* +* This function will register a cooling device with device tree node reference. +* This interface function adds a new thermal cooling device (fan/processor/...) +* to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself +* to all the thermal zone devices registered at the same time. +* +* Return: a pointer to the created struct thermal_cooling_device or an +* ERR_PTR. Caller must check return value with IS_ERR*() helpers. +*/ +struct thermal_cooling_device * +devm_thermal_cooling_device_register (struct device *dev,const char *type, +void *devdata,const struct thermal_cooling_device_ops *ops) +{ +struct thermal_cooling_device **ptr, *tcd; + + ptr =devres_alloc (thermal_cooling_device_release,sizeof (*ptr), +GFP_KERNEL ); +if (!ptr) +return ERR_PTR (-ENOMEM ); + + tcd =thermal_cooling_device_register (type, devdata, ops); +if (IS_ERR (tcd)) { +devres_free (ptr); +return tcd; + } + + *ptr = tcd; +devres_add (dev, ptr); + +return tcd; +} +EXPORT_SYMBOL_GPL (devm_thermal_cooling_device_register); +static bool thermal_cooling_device_present (struct thermal_cooling_device *cdev) {struct thermal_cooling_device *pos =NULL ;
include/linux/thermal.h +13 -0
@@ -260,6 +260,11 @@ devm_thermal_of_cooling_device_register(struct device *dev,struct device_node *np, const char *type, void *devdata, const struct thermal_cooling_device_ops *ops); + +struct thermal_cooling_device * +devm_thermal_cooling_device_register (struct device *dev,const char *type, +void *devdata,const struct thermal_cooling_device_ops *ops); +void thermal_cooling_device_update (struct thermal_cooling_device *);void thermal_cooling_device_unregister (struct thermal_cooling_device *);struct thermal_zone_device *thermal_zone_get_zone_by_name (const char *name);
@@ -317,6 +322,14 @@ devm_thermal_of_cooling_device_register(struct device *dev, {return ERR_PTR (-ENODEV ); } + +struct thermal_cooling_device * +devm_thermal_cooling_device_register (struct device *dev,const char *type, +void *devdata,const struct thermal_cooling_device_ops *ops) +{ +return ERR_PTR (-ENODEV ); +} +static inline void thermal_cooling_device_unregister (struct thermal_cooling_device *cdev) { }
Signature · 1 line
2.43.0
PATCH 7/14 hwmon:: Use non-OF thermal cooling device register function
In reply to Daniel LezcanoMake HWMON drivers which are not based on device tree to use the corresponding non-OF functions.
--- drivers/hwmon/cros_ec_hwmon.c | 4 ++-- drivers/hwmon/dell-smm-hwmon.c | 4 ++-- drivers/hwmon/mlxreg-fan.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/hwmon/cros_ec_hwmon.c +2 -2
@@ -532,8 +532,8 @@ static void cros_ec_hwmon_register_fan_cooling_devices(struct device *dev, cpriv->hwmon_priv = priv; cpriv->index = i; - cdev =devm_thermal_of_cooling_device_register (dev,NULL , type, cpriv, - &cros_ec_thermal_cooling_ops); + cdev =devm_thermal_cooling_device_register (dev, type, cpriv, + &cros_ec_thermal_cooling_ops);if (IS_ERR (cdev)) {dev_warn (dev,"failed to register fan %zu as a cooling device: %pe\n" , i, cdev);
drivers/hwmon/dell-smm-hwmon.c +2 -2
@@ -1161,8 +1161,8 @@ static int dell_smm_init_cdev(struct device *dev, u8 fan_num)if (cdata) { cdata->fan_num = fan_num; cdata->data = data; - cdev =devm_thermal_of_cooling_device_register (dev,NULL , name, cdata, - &dell_smm_cooling_ops); + cdev =devm_thermal_cooling_device_register (dev, name, cdata, + &dell_smm_cooling_ops);if (IS_ERR (cdev)) {devm_kfree (dev, cdata); ret =PTR_ERR (cdev);
drivers/hwmon/mlxreg-fan.c +2 -2
@@ -583,8 +583,8 @@ static int mlxreg_fan_cooling_config(struct device *dev, struct mlxreg_fan *fan) pwm->fan = fan;/* Set minimal PWM speed. */ pwm->last_hwmon_state =MLXREG_FAN_PWM_DUTY2STATE (MLXREG_FAN_MIN_DUTY ); - pwm->cdev =devm_thermal_of_cooling_device_register (dev,NULL , mlxreg_fan_name[i], - pwm, &mlxreg_fan_cooling_ops); + pwm->cdev =devm_thermal_cooling_device_register (dev, mlxreg_fan_name[i], + pwm, &mlxreg_fan_cooling_ops);if (IS_ERR (pwm->cdev)) {dev_err (dev,"Failed to register cooling device\n" );return PTR_ERR (pwm->cdev);
Signature · 1 line
2.43.0
PATCH 8/14 thermal/core: Move OF functions def in the CONFIG_OF section in thermal.h
In reply to Daniel LezcanoNow that OF functions are used only by OF drivers, let's move and group the functions definitions under the CONFIG_OF block. There is no need to keep them out because of non-OF drivers using them.
--- include/linux/thermal.h | 48 +++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 21 deletions(-)
include/linux/thermal.h +27 -21
@@ -198,6 +198,16 @@ struct thermal_zone_device *devm_thermal_of_zone_register(struct device *dev, invoid devm_thermal_of_zone_unregister (struct device *dev,struct thermal_zone_device *tz); +struct thermal_cooling_device * +thermal_of_cooling_device_register (struct device_node *np, +const char *type,void *data, +const struct thermal_cooling_device_ops *ops); + +struct thermal_cooling_device * +devm_thermal_of_cooling_device_register (struct device *dev, +struct device_node *np, +const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops);#else static inline
@@ -211,6 +221,23 @@ static inline void devm_thermal_of_zone_unregister(struct device *dev, struct thermal_zone_device *tz) { } + +static inline struct thermal_cooling_device * +thermal_of_cooling_device_register (struct device_node *np, +const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops) +{ +return ERR_PTR (-ENODEV ); +} + +static inline struct thermal_cooling_device * +devm_thermal_of_cooling_device_register (struct device *dev, +struct device_node *np, +const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops) +{ +return ERR_PTR (-ENODEV ); +}#endif int for_each_thermal_trip(struct thermal_zone_device *tz,
@@ -252,14 +279,6 @@ void thermal_zone_device_update(struct thermal_zone_device *,struct thermal_cooling_device *thermal_cooling_device_register (const char *,void *,const struct thermal_cooling_device_ops *); -struct thermal_cooling_device * -thermal_of_cooling_device_register (struct device_node *np,const char *,void *, -const struct thermal_cooling_device_ops *); -struct thermal_cooling_device * -devm_thermal_of_cooling_device_register (struct device *dev, -struct device_node *np, -const char *type,void *devdata, -const struct thermal_cooling_device_ops *ops);struct thermal_cooling_device * devm_thermal_cooling_device_register(struct device *dev, const char *type,
@@ -309,19 +328,6 @@ static inline struct thermal_cooling_device * thermal_cooling_device_register(const char *type, void *devdata, const struct thermal_cooling_device_ops *ops) { return ERR_PTR(-ENODEV); } -static inline struct thermal_cooling_device * -thermal_of_cooling_device_register (struct device_node *np, -const char *type,void *devdata, -const struct thermal_cooling_device_ops *ops) -{return ERR_PTR (-ENODEV ); } -static inline struct thermal_cooling_device * -devm_thermal_of_cooling_device_register (struct device *dev, -struct device_node *np, -const char *type,void *devdata, -const struct thermal_cooling_device_ops *ops) -{ -return ERR_PTR (-ENODEV ); -}struct thermal_cooling_device * devm_thermal_cooling_device_register(struct device *dev, const char *type,
Signature · 1 line
2.43.0
PATCH 9/14 thermal/core: Put of_node field cooling device structure under Kconfig option
In reply to Daniel LezcanoThe device node pointer in the cooling device structure is only needed by the thermal OF in order to bind a thermal zone with a cooling device. Now only the OF based drivers are using the thermal OF functions and do not call the function with a NULL device_node parameter as before. We can put this field under the CONFIG_THERMAL_OF condition and make it go away if the device tree is not used.
--- include/linux/thermal.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/thermal.h +3 -1
@@ -125,7 +125,6 @@ struct thermal_cooling_device {const char *type;unsigned long max_state;struct device device; -struct device_node *np;void *devdata;void *stats;const struct thermal_cooling_device_ops *ops;
@@ -133,6 +132,9 @@ struct thermal_cooling_device {struct mutex lock;/* protect thermal_instances list */ struct list_head thermal_instances;struct list_head node; +#ifdef CONFIG_THERMAL_OF +struct device_node *np; +#endif #ifdef CONFIG_THERMAL_DEBUGFS struct thermal_debugfs *debugfs;#endif
Signature · 1 line
2.43.0
PATCH 10/14 thermal/of: Rename the devm_thermal_of_cooling_device_register() function
In reply to Daniel LezcanoThe cooling devices can be composed with a cooling device controller and a set of cooling devices attached to it. Until now, the DT bindings were described using a node for the cooling device controller and child nodes for all the cooling devices.
Recently, a new set of cooling devices were proposed with the same bindings. Those were rejected because DT maintainers do not want this format anymore. In place, a cooling device will be created with an id. Whatever its meaning, the thermal OF will bind a thermal zone and a cooling device by checking the device node pointer + the id are matching the cooling map with the cooling device.
Actually this approach is consistent with the thermal which are also registered with a device and an id.
In order to do a distinction between the old binding with child nodes and the incoming new binding, let's rename the registering function with a self-explanatory name.
Rename the functions:
devm_thermal_of_cooling_device_register() -> devm_thermal_of_child_cooling_device_register()
Used the command:
find . -type f -name '*.[ch]' -exec \
sed -i 's/devm_thermal_of_cooling_device_register/\
devm_thermal_of_child_cooling_device_register/g' {} \;Did not used clang-format-diff because it does not indent correctly and checkpatch complained. Manually reindented to make checkpatch happy
--- drivers/hwmon/amc6821.c | 2 +- drivers/hwmon/aspeed-pwm-tacho.c | 5 +++-- drivers/hwmon/emc2305.c | 6 +++--- drivers/hwmon/gpio-fan.c | 6 ++++-- drivers/hwmon/max6650.c | 6 +++--- drivers/hwmon/npcm750-pwm-fan.c | 6 ++++-- drivers/hwmon/pwm-fan.c | 5 +++-- drivers/hwmon/qnap-mcu-hwmon.c | 6 +++--- drivers/hwmon/tc654.c | 5 +++-- drivers/memory/tegra/tegra210-emc-core.c | 4 ++-- drivers/soc/qcom/qcom_aoss.c | 2 +- drivers/thermal/khadas_mcu_fan.c | 7 ++++--- drivers/thermal/tegra/soctherm.c | 6 +++--- drivers/thermal/thermal_of.c | 12 ++++++------ include/linux/thermal.h | 16 ++++++++-------- 15 files changed, 51 insertions(+), 43 deletions(-)
drivers/hwmon/amc6821.c +1 -1
@@ -1076,7 +1076,7 @@ static int amc6821_probe(struct i2c_client *client) "Failed to initialize hwmon\n");if (IS_ENABLED (CONFIG_THERMAL ) && fan_np && data->fan_cooling_levels) -return PTR_ERR_OR_ZERO (devm_thermal_of_cooling_device_register (dev, +return PTR_ERR_OR_ZERO (devm_thermal_of_child_cooling_device_register (dev, fan_np, client->name, data, &amc6821_cooling_ops));return 0 ;
drivers/hwmon/aspeed-pwm-tacho.c +3 -2
@@ -841,8 +841,9 @@ static int aspeed_create_pwm_cooling(struct device *dev, }snprintf (cdev->name,MAX_CDEV_NAME_LEN ,"%pOFn%d" , child, pwm_port); - cdev->tcdev =devm_thermal_of_cooling_device_register (dev, child, - cdev->name, cdev, &aspeed_pwm_cool_ops); + cdev->tcdev =devm_thermal_of_child_cooling_device_register (dev, child, + cdev->name, cdev, + &aspeed_pwm_cool_ops);if (IS_ERR (cdev->tcdev))return PTR_ERR (cdev->tcdev);
drivers/hwmon/emc2305.c +3 -3
@@ -309,9 +309,9 @@ static int emc2305_set_single_tz(struct device *dev, struct device_node *fan_nod pwm = data->pwm_min[cdev_idx]; data->cdev_data[cdev_idx].cdev = -devm_thermal_of_cooling_device_register (dev, fan_node, - emc2305_fan_name[idx], data, - &emc2305_cooling_ops); +devm_thermal_of_child_cooling_device_register (dev, fan_node, + emc2305_fan_name[idx], data, + &emc2305_cooling_ops);if (IS_ERR (data->cdev_data[cdev_idx].cdev)) {dev_err (dev,"Failed to register cooling device %s\n" , emc2305_fan_name[idx]);
drivers/hwmon/gpio-fan.c +4 -2
@@ -592,8 +592,10 @@ static int gpio_fan_probe(struct platform_device *pdev) }/* Optional cooling device register for Device tree platforms */ - fan_data->cdev =devm_thermal_of_cooling_device_register (dev, np, -"gpio-fan" , fan_data, &gpio_fan_cool_ops); + fan_data->cdev =devm_thermal_of_child_cooling_device_register (dev, np, +"gpio-fan" , + fan_data, + &gpio_fan_cool_ops);dev_info (dev,"GPIO fan initialized\n" );
drivers/hwmon/max6650.c +3 -3
@@ -793,9 +793,9 @@ static int max6650_probe(struct i2c_client *client)return err;if (IS_ENABLED (CONFIG_THERMAL )) { - cooling_dev =devm_thermal_of_cooling_device_register (dev, - dev->of_node, client->name, - data, &max6650_cooling_ops); + cooling_dev =devm_thermal_of_child_cooling_device_register (dev, dev->of_node, + client->name, data, + &max6650_cooling_ops);if (IS_ERR (cooling_dev)) {dev_warn (dev,"thermal cooling device register failed: %ld\n" ,PTR_ERR (cooling_dev));
drivers/hwmon/npcm750-pwm-fan.c +4 -2
@@ -857,8 +857,10 @@ static int npcm7xx_create_pwm_cooling(struct device *dev,snprintf (cdev->name,THERMAL_NAME_LENGTH ,"%pOFn%d" , child, pwm_port); - cdev->tcdev =devm_thermal_of_cooling_device_register (dev, child, - cdev->name, cdev, &npcm7xx_pwm_cool_ops); + cdev->tcdev =devm_thermal_of_child_cooling_device_register (dev, child, + cdev->name, + cdev, + &npcm7xx_pwm_cool_ops);if (IS_ERR (cdev->tcdev))return PTR_ERR (cdev->tcdev);
drivers/hwmon/pwm-fan.c +3 -2
@@ -685,8 +685,9 @@ static int pwm_fan_probe(struct platform_device *pdev) ctx->pwm_fan_state = ctx->pwm_fan_max_state;if (IS_ENABLED (CONFIG_THERMAL )) { - cdev =devm_thermal_of_cooling_device_register (dev, - dev->of_node,"pwm-fan" , ctx, &pwm_fan_cooling_ops); + cdev =devm_thermal_of_child_cooling_device_register (dev, dev->of_node, +"pwm-fan" , ctx, + &pwm_fan_cooling_ops);if (IS_ERR (cdev)) { ret =PTR_ERR (cdev); dev_err(dev,
drivers/hwmon/qnap-mcu-hwmon.c +3 -3
@@ -337,9 +337,9 @@ static int qnap_mcu_hwmon_probe(struct platform_device *pdev)* levels and only succeed with either no or correct cooling levels. */ if (IS_ENABLED (CONFIG_THERMAL ) && hwm->fan_cooling_levels) { - cdev =devm_thermal_of_cooling_device_register (dev, -to_of_node (hwm->fan_node),"qnap-mcu-hwmon" , - hwm, &qnap_mcu_hwmon_cooling_ops); + cdev =devm_thermal_of_child_cooling_device_register (dev,to_of_node (hwm->fan_node), +"qnap-mcu-hwmon" , hwm, + &qnap_mcu_hwmon_cooling_ops);if (IS_ERR (cdev))return dev_err_probe (dev,PTR_ERR (cdev),"Failed to register qnap-mcu-hwmon as cooling device\n" );
drivers/hwmon/tc654.c +3 -2
@@ -541,8 +541,9 @@ static int tc654_probe(struct i2c_client *client)if (IS_ENABLED (CONFIG_THERMAL )) {struct thermal_cooling_device *cdev; - cdev =devm_thermal_of_cooling_device_register (dev, dev->of_node, client->name, - hwmon_dev, &tc654_fan_cool_ops); + cdev =devm_thermal_of_child_cooling_device_register (dev, dev->of_node, + client->name, hwmon_dev, + &tc654_fan_cool_ops);return PTR_ERR_OR_ZERO (cdev); }
drivers/memory/tegra/tegra210-emc-core.c +2 -2
@@ -1966,8 +1966,8 @@ static int tegra210_emc_probe(struct platform_device *pdev)tegra210_emc_debugfs_init (emc); - cd =devm_thermal_of_cooling_device_register (emc->dev, np,"emc" , emc, - &tegra210_emc_cd_ops); + cd =devm_thermal_of_child_cooling_device_register (emc->dev, np,"emc" , emc, + &tegra210_emc_cd_ops);if (IS_ERR (cd)) { err =PTR_ERR (cd); dev_err(emc->dev, "failed to register cooling device: %d\n",
drivers/soc/qcom/qcom_aoss.c +1 -1
@@ -381,7 +381,7 @@ static int qmp_cooling_device_add(struct qmp *qmp, qmp_cdev->qmp = qmp; qmp_cdev->state = !qmp_cdev_max_state; qmp_cdev->name = cdev_name; - qmp_cdev->cdev =devm_thermal_of_cooling_device_register + qmp_cdev->cdev =devm_thermal_of_child_cooling_device_register (qmp->dev, node, cdev_name, qmp_cdev, &qmp_cooling_device_ops);
drivers/thermal/khadas_mcu_fan.c +4 -3
@@ -90,9 +90,10 @@ static int khadas_mcu_fan_probe(struct platform_device *pdev) ctx->mcu = mcu;platform_set_drvdata (pdev, ctx); - cdev =devm_thermal_of_cooling_device_register (dev->parent, - dev->parent->of_node,"khadas-mcu-fan" , ctx, - &khadas_mcu_fan_cooling_ops); + cdev =devm_thermal_of_child_cooling_device_register (dev->parent, + dev->parent->of_node, +"khadas-mcu-fan" , ctx, + &khadas_mcu_fan_cooling_ops);if (IS_ERR (cdev)) { ret =PTR_ERR (cdev); dev_err(dev, "Failed to register khadas-mcu-fan as cooling device: %d\n",
drivers/thermal/tegra/soctherm.c +3 -3
@@ -1700,9 +1700,9 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev) stc->init = true; }else { - tcd =devm_thermal_of_cooling_device_register (dev, np_stcc, - (char *)name, ts, - &throt_cooling_ops); + tcd =devm_thermal_of_child_cooling_device_register (dev, np_stcc, + (char *)name, ts, + &throt_cooling_ops);if (IS_ERR_OR_NULL (tcd)) { dev_err(dev, "throttle-cfg: %s: failed to register cooling device\n",
drivers/thermal/thermal_of.c +6 -6
@@ -550,7 +550,7 @@ static void thermal_cooling_device_release(struct device *dev, void *res) }/** -* devm_thermal_of_cooling_device_register() - register an OF thermal cooling +* devm_thermal_of_child_cooling_device_register() - register an OF thermal cooling * device * @dev: a valid struct device pointer of a sensor device. * @np: a pointer to a device tree node.
@@ -567,10 +567,10 @@ static void thermal_cooling_device_release(struct device *dev, void *res)* ERR_PTR. Caller must check return value with IS_ERR*() helpers. */ struct thermal_cooling_device * -devm_thermal_of_cooling_device_register (struct device *dev, -struct device_node *np, -const char *type,void *devdata, -const struct thermal_cooling_device_ops *ops) +devm_thermal_of_child_cooling_device_register (struct device *dev, +struct device_node *np, +const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops) {struct thermal_cooling_device **ptr, *tcd;
@@ -590,4 +590,4 @@ devm_thermal_of_cooling_device_register(struct device *dev,return tcd; } -EXPORT_SYMBOL_GPL (devm_thermal_of_cooling_device_register); +EXPORT_SYMBOL_GPL (devm_thermal_of_child_cooling_device_register);
include/linux/thermal.h +8 -8
@@ -206,10 +206,10 @@ thermal_of_cooling_device_register(struct device_node *np, const struct thermal_cooling_device_ops *ops);struct thermal_cooling_device * -devm_thermal_of_cooling_device_register (struct device *dev, -struct device_node *np, -const char *type,void *devdata, -const struct thermal_cooling_device_ops *ops); +devm_thermal_of_child_cooling_device_register (struct device *dev, +struct device_node *np, +const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops);#else static inline
@@ -233,10 +233,10 @@ thermal_of_cooling_device_register(struct device_node *np, }static inline struct thermal_cooling_device * -devm_thermal_of_cooling_device_register (struct device *dev, -struct device_node *np, -const char *type,void *devdata, -const struct thermal_cooling_device_ops *ops) +devm_thermal_of_child_cooling_device_register (struct device *dev, +struct device_node *np, +const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops) {return ERR_PTR (-ENODEV ); }
Signature · 1 line
2.43.0
PATCH 11/14 thermal/of: Introduce cooling device of_index
In reply to Daniel LezcanoAs described in the previous change, the new incoming DT binding will describe a tuple device_node + cooling device id, instead of child nodes.
Let's augment thermal_of_cooling_device_register() to receive the cooling device id and propagate the changes to the four remaining drivers using the non-devm version of the cooling device registering function.
Add the id in the cooling device structure and store the value when registering it.
--- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 2 +- drivers/thermal/cpufreq_cooling.c | 2 +- drivers/thermal/cpuidle_cooling.c | 2 +- drivers/thermal/devfreq_cooling.c | 2 +- drivers/thermal/thermal_of.c | 6 ++++-- include/linux/thermal.h | 5 +++-- 6 files changed, 11 insertions(+), 8 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +1 -1
@@ -1791,7 +1791,7 @@ static int etnaviv_gpu_bind(struct device *dev, struct device *master,int ret;if (IS_ENABLED (CONFIG_DRM_ETNAVIV_THERMAL )) { - gpu->cooling =thermal_of_cooling_device_register (dev->of_node, + gpu->cooling =thermal_of_cooling_device_register (dev->of_node,0 , (char *)dev_name (dev), gpu, &cooling_ops);if (IS_ERR (gpu->cooling))return PTR_ERR (gpu->cooling);
drivers/thermal/cpufreq_cooling.c +1 -1
@@ -592,7 +592,7 @@ __cpufreq_cooling_register(struct device_node *np,if (!name) goto remove_qos_req; - cdev =thermal_of_cooling_device_register (np, name, cpufreq_cdev, + cdev =thermal_of_cooling_device_register (np,0 , name, cpufreq_cdev, cooling_ops);kfree (name);
drivers/thermal/cpuidle_cooling.c +1 -1
@@ -207,7 +207,7 @@ static int __cpuidle_cooling_register(struct device_node *np, goto out_unregister; } - cdev =thermal_of_cooling_device_register (np, name, idle_cdev, + cdev =thermal_of_cooling_device_register (np,0 , name, idle_cdev, &cpuidle_cooling_ops);if (IS_ERR (cdev)) { ret =PTR_ERR (cdev);
drivers/thermal/devfreq_cooling.c +1 -1
@@ -454,7 +454,7 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,if (!name) goto remove_qos_req; - cdev =thermal_of_cooling_device_register (np, name, dfc, ops); + cdev =thermal_of_cooling_device_register (np,0 , name, dfc, ops);kfree (name);if (IS_ERR (cdev)) {
drivers/thermal/thermal_of.c +4 -2
@@ -514,6 +514,7 @@ EXPORT_SYMBOL_GPL(devm_thermal_of_zone_unregister);/** * thermal_of_cooling_device_register() - register an OF thermal cooling device * @np: a pointer to a device tree node. +* @of_index: a cooling device index in the cooling controller * @type: the thermal cooling device type. * @devdata: device private data. * @ops: standard thermal cooling devices callbacks.
@@ -527,7 +528,7 @@ EXPORT_SYMBOL_GPL(devm_thermal_of_zone_unregister);* ERR_PTR. Caller must check return value with IS_ERR*() helpers. */ struct thermal_cooling_device * -thermal_of_cooling_device_register (struct device_node *np, +thermal_of_cooling_device_register (struct device_node *np,int of_index,const char *type,void *devdata,const struct thermal_cooling_device_ops *ops) {
@@ -538,6 +539,7 @@ thermal_of_cooling_device_register(struct device_node *np,return cdev; cdev->np = np; + cdev->of_index = of_index;thermal_cooling_device_init_complete (cdev);return cdev;
@@ -579,7 +581,7 @@ devm_thermal_of_child_cooling_device_register(struct device *dev,if (!ptr)return ERR_PTR (-ENOMEM ); - tcd =thermal_of_cooling_device_register (np, type, devdata, ops); + tcd =thermal_of_cooling_device_register (np,0 , type, devdata, ops);if (IS_ERR (tcd)) {devres_free (ptr);return tcd;
include/linux/thermal.h +3 -2
@@ -134,6 +134,7 @@ struct thermal_cooling_device {struct list_head node;#ifdef CONFIG_THERMAL_OF struct device_node *np; +int of_index;#endif #ifdef CONFIG_THERMAL_DEBUGFS struct thermal_debugfs *debugfs;
@@ -201,7 +202,7 @@ struct thermal_zone_device *devm_thermal_of_zone_register(struct device *dev, invoid devm_thermal_of_zone_unregister (struct device *dev,struct thermal_zone_device *tz);struct thermal_cooling_device * -thermal_of_cooling_device_register (struct device_node *np, +thermal_of_cooling_device_register (struct device_node *np,int of_index,const char *type,void *data,const struct thermal_cooling_device_ops *ops);
@@ -225,7 +226,7 @@ static inline void devm_thermal_of_zone_unregister(struct device *dev, }static inline struct thermal_cooling_device * -thermal_of_cooling_device_register (struct device_node *np, +thermal_of_cooling_device_register (struct device_node *np,int of_index,const char *type,void *devdata,const struct thermal_cooling_device_ops *ops) {
Signature · 1 line
2.43.0
PATCH 12/14 thermal/of: Pass the of_index and add a function to register with an index
In reply to Daniel LezcanoIntroduce a new function devm_thermal_of_cooling_device_register() which will register a cooling device and its id.
--- drivers/thermal/thermal_of.c | 68 +++++++++++++++++++++++++++--------- include/linux/thermal.h | 13 +++++++ 2 files changed, 64 insertions(+), 17 deletions(-)
drivers/thermal/thermal_of.c +51 -17
@@ -551,6 +551,56 @@ static void thermal_cooling_device_release(struct device *dev, void *res)thermal_cooling_device_unregister (*(struct thermal_cooling_device **)res); } +static struct thermal_cooling_device * +__devm_thermal_of_cooling_device_register (struct device *dev,struct device_node *np, +int of_index,const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops) +{ +struct thermal_cooling_device **ptr, *tcd; + + ptr =devres_alloc (thermal_cooling_device_release,sizeof (*ptr), +GFP_KERNEL ); +if (!ptr) +return ERR_PTR (-ENOMEM ); + + tcd =thermal_of_cooling_device_register (np, of_index, type, devdata, ops); +if (IS_ERR (tcd)) { +devres_free (ptr); +return tcd; + } + + *ptr = tcd; +devres_add (dev, ptr); + +return tcd; +} + +/** +* devm_thermal_of_cooling_device_register() - register an OF thermal cooling device +* @dev: a valid struct device pointer of a sensor device. +* @of_index: a cooling device index in the cooling controller +* @type: the thermal cooling device type. +* @devdata: device private data. +* @ops: standard thermal cooling devices callbacks. +* +* This function will register a cooling device with device tree node reference. +* This interface function adds a new thermal cooling device (fan/processor/...) +* to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself +* to all the thermal zone devices registered at the same time. +* +* Return: a pointer to the created struct thermal_cooling_device or an +* ERR_PTR. Caller must check return value with IS_ERR*() helpers. +*/ +struct thermal_cooling_device * +devm_thermal_of_cooling_device_register (struct device *dev,int of_index, +const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops) +{ +return __devm_thermal_of_cooling_device_register (dev, dev->of_node, of_index, + type, devdata, ops); +} +EXPORT_SYMBOL_GPL (devm_thermal_of_cooling_device_register); +/** * devm_thermal_of_child_cooling_device_register() - register an OF thermal cooling * device
@@ -574,22 +624,6 @@ devm_thermal_of_child_cooling_device_register(struct device *dev, const char *type, void *devdata, const struct thermal_cooling_device_ops *ops) { - struct thermal_cooling_device **ptr, *tcd; - - ptr =devres_alloc (thermal_cooling_device_release,sizeof (*ptr), -GFP_KERNEL ); -if (!ptr) -return ERR_PTR (-ENOMEM ); - - tcd =thermal_of_cooling_device_register (np,0 , type, devdata, ops); -if (IS_ERR (tcd)) { -devres_free (ptr); -return tcd; - } - - *ptr = tcd; -devres_add (dev, ptr); - -return tcd; + return __devm_thermal_of_cooling_device_register(dev, np, 0, type, devdata, ops); }EXPORT_SYMBOL_GPL (devm_thermal_of_child_cooling_device_register);
include/linux/thermal.h +13 -0
@@ -206,6 +206,11 @@ thermal_of_cooling_device_register(struct device_node *np, int of_index, const char *type, void *data, const struct thermal_cooling_device_ops *ops); +struct thermal_cooling_device * +devm_thermal_of_cooling_device_register (struct device *dev,int of_index, +const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops); +struct thermal_cooling_device * devm_thermal_of_child_cooling_device_register(struct device *dev, struct device_node *np,
@@ -233,6 +238,14 @@ thermal_of_cooling_device_register(struct device_node *np, int of_index,return ERR_PTR (-ENODEV ); } +static inline struct thermal_cooling_device * +devm_thermal_of_cooling_device_register (struct device *dev,int of_index, +const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops) +{ +return ERR_PTR (-ENODEV ); +} +static inline struct thermal_cooling_device * devm_thermal_of_child_cooling_device_register(struct device *dev, struct device_node *np,
Signature · 1 line
2.43.0
PATCH 13/14 thermal/of: Process cooling device index in cooling-spec
In reply to Daniel LezcanoThe new DT bindings format describes a cooling device spec with the cooling device node, the id and the mitigation limits.
Depending on the version of the DT bindings, in order to bind, check with the device node pointer only or, in addition, the cooling device id.
--- drivers/thermal/thermal_of.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
drivers/thermal/thermal_of.c +20 -2
@@ -264,11 +264,29 @@ static bool thermal_of_get_cooling_spec(struct device_node *map_np, int index,return false; } +/* +* There are two formats: +* - Legacy format : <&cdev lower upper> +* - New format : <&cdev of_index lower upper> +* +* With the new format, along with the device node pointer, +* the of_index must match with the cooling device of_index in +* order to bind +*/ +if (cooling_spec.args_count ==3 && + cooling_spec.args[0 ] != cdev->of_index) +return false; +if (cooling_spec.np != cdev->np)return false; - c->lower = cooling_spec.args[0 ]; - c->upper = cooling_spec.args[1 ]; +if (cooling_spec.args_count !=3 ) { + c->lower = cooling_spec.args[0 ]; + c->upper = cooling_spec.args[1 ]; + }else { + c->lower = cooling_spec.args[1 ]; + c->upper = cooling_spec.args[2 ]; + } c->weight = weight;return true;
Signature · 1 line
2.43.0
PATCH 14/14 dt-bindings: thermal: cooling-devices: Update support for 3 cells cooling device
In reply to Daniel LezcanoFrom: Gaurav Kohli <[email protected]>
Extend the thermal cooling device binding to support a 3 cells specifier along with tje 2 cells format.
Update #cooling-cells property to enum to support both 2 and 3 arguments.
--- .../bindings/thermal/thermal-cooling-devices.yaml | 8 ++++++-- .../devicetree/bindings/thermal/thermal-zones.yaml | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/thermal/thermal-cooling-devices.yaml +6 -2
@@ -44,10 +44,14 @@ select: true properties: "#cooling-cells": description: - Must be 2, in order to specify minimum and maximum cooling state used in + Must be 2 or 3. If 2, specifies minimum and maximum cooling state used in the cooling-maps reference. The first cell is the minimum cooling state and the second cell is the maximum cooling state requested. - const: 2 + If 3, the first cell specifies the thermal mitigation device specifier + index for devices that support multiple thermal mitigation mechanisms. + The two other cells are respectively the minimum cooling state and the + maximum cooling state. + enum: [2, 3] additionalProperties: true
Documentation/devicetree/bindings/thermal/thermal-zones.yaml +2 -1
@@ -214,7 +214,8 @@ patternProperties: device. Using the THERMAL_NO_LIMIT (-1UL) constant in the cooling-device phandle limit specifier lets the framework use the minimum and maximum cooling state for that cooling - device automatically. + device automatically. If three arguments are specified, + the first argument is the cooling device specifier. contribution: $ref: /schemas/types.yaml#/definitions/uint32
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v1 06/14] thermal/core: Register cooling device non-OF drivers
In reply to Daniel LezcanoSashiko AI review found 2 potential issue(s): - [Low] Missing `static inline` in the fallback dummy implementation of `devm_thermal_cooling_device_register`. - [Low] Incorrect kerneldoc comment for…
Sashiko AI review found 2 potential issue(s):
- [Low] Missing static inline in the fallback dummy implementation of devm_thermal_cooling_device_register.
- [Low] Incorrect kerneldoc comment for devm_thermal_cooling_device_register.
--
commit 18601ab408a18465a11642434a184fda33807cbc
Author: Daniel Lezcano <[email protected]>
thermal/core: Register cooling device non-OF drivers
This commit provides a non-OF function to register a cooling device, allowing a clear separation between OF and non-OF code. Drivers not using a devicetree can then migrate to this new function.
Quoted 4 lines
drivers/thermal/thermal_core.c +0
-0
[ ... ]
Quoted 7 lines
drivers/thermal/thermal_core.c +3
-0@@ -1164,6 +1164,50 @@ thermal_cooling_device_register(const char *type, void *devdata, }EXPORT_SYMBOL_GPL (thermal_cooling_device_register); +static void thermal_cooling_device_release (struct device *dev,void *res) +{ +thermal_cooling_device_unregister (*(struct thermal_cooling_device **)res);
drivers/thermal/thermal_core.c thermal_cooling_device_register(const char *type, void *devdata, · line 1179
Quoted 10 lines
drivers/thermal/thermal_core.c +10
-0+} + +/** +* devm_thermal_cooling_device_register() - register a thermal cooling device +* @dev: a valid struct device pointer of a sensor device. +* @type: the thermal cooling device type. +* @devdata: device private data. +* @ops: standard thermal cooling devices callbacks. +* +* This function will register a cooling device with device tree node reference.
This isn't a bug, but the comment states this registers a cooling device with a device tree node reference. Since this is the non-OF version, should this part of the comment be updated to reflect that it does not use a devicetree?
Quoted 9 lines
drivers/thermal/thermal_core.c +9
-0+* This interface function adds a new thermal cooling device (fan/processor/...) +* to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself +* to all the thermal zone devices registered at the same time. +* +* Return: a pointer to the created struct thermal_cooling_device or an +* ERR_PTR. Caller must check return value with IS_ERR*() helpers. +*/ +struct thermal_cooling_device * +devm_thermal_cooling_device_register(struct device *dev, const char *type,
[ ... ]
Quoted 4 lines
include/linux/thermal.h +0
-0
[ ... ]
include/linux/thermal.h devm_thermal_of_cooling_device_register(struct device *dev, · line 331
Quoted 11 lines
include/linux/thermal.h +7
-0@@ -317,6 +322,14 @@ devm_thermal_of_cooling_device_register(struct device *dev, {return ERR_PTR (-ENODEV ); } + +struct thermal_cooling_device * +devm_thermal_cooling_device_register (struct device *dev,const char *type, +void *devdata,const struct thermal_cooling_device_ops *ops) +{ +return ERR_PTR (-ENODEV ); +}
Does this fallback implementation need the static inline keywords? Without them, it looks like this will be defined as a strong global symbol in every translation unit that includes the thermal header when CONFIG_THERMAL is disabled, which could cause multiple definition linker errors.
Quoted 4 lines
include/linux/thermal.h +1
-0+static inline void thermal_cooling_device_unregister (struct thermal_cooling_device *cdev) { }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [PATCH v1 10/14] thermal/of: Rename the devm_thermal_of_cooling_device_register() function
In reply to Daniel LezcanoSashiko AI review found 3 potential issue(s): - [Low] Semantic mismatch in API naming for drivers not using child nodes. - [Low] Incomplete refactoring leaves `thermal_of_cooling_device_register()`…
Sashiko AI review found 3 potential issue(s):
- [Low] Semantic mismatch in API naming for drivers not using child nodes.
- [Low] Incomplete refactoring leaves thermal_of_cooling_device_register() with a generic name.
- [Low] Kerneldoc for the renamed function does not document the new specialized semantics. --
commit d1ab585391fe2969c56e5221cba69749aaa4c5c5
Author: Daniel Lezcano <[email protected]>
Subject: thermal/of: Rename the devm_thermal_of_cooling_device_register() function
This commit renames devm_thermal_of_cooling_device_register() to devm_thermal_of_child_cooling_device_register() across the kernel. This name change is intended to distinguish the old bindings using child nodes from an incoming new binding format for cooling devices.
Quoted 4 lines
drivers/hwmon/pwm-fan.c +0
-0
[ ... ]
drivers/hwmon/pwm-fan.c static int pwm_fan_probe(struct platform_device *pdev) · line 690
Quoted 9 lines
drivers/hwmon/pwm-fan.c +3
-2@@ -685,8 +685,9 @@ static int pwm_fan_probe(struct platform_device *pdev) ctx->pwm_fan_state = ctx->pwm_fan_max_state;if (IS_ENABLED (CONFIG_THERMAL )) { - cdev =devm_thermal_of_cooling_device_register (dev, - dev->of_node,"pwm-fan" , ctx, &pwm_fan_cooling_ops); + cdev =devm_thermal_of_child_cooling_device_register (dev, dev->of_node, +"pwm-fan" , ctx, + &pwm_fan_cooling_ops);
Since this driver is passing dev->of_node rather than a child node, does this renaming create a semantic mismatch for this and other similar drivers (such as tc654.c, max6650.c, and gpio-fan.c)?
[ ... ]
drivers/thermal/thermal_of.c static void thermal_cooling_device_release(struct device *dev, void *res) · line 556
Quoted 13 lines
drivers/thermal/thermal_of.c +1
-1@@ -550,7 +550,7 @@ static void thermal_cooling_device_release(struct device *dev, void *res) }/** -* devm_thermal_of_cooling_device_register() - register an OF thermal cooling +* devm_thermal_of_child_cooling_device_register() - register an OF thermal cooling * device * @dev: a valid struct device pointer of a sensor device. * @np: a pointer to a device tree node.
Since the function is now explicitly meant for legacy bindings utilizing child nodes, could this kerneldoc description be updated to clarify its specialized semantics instead of leaving it generically registering an OF thermal cooling device?
[ ... ]
Quoted 6 lines
include/linux/thermal.h +0
-0@@ -206,10 +206,10 @@ thermal_of_cooling_device_register(struct device_node *np, const struct thermal_cooling_device_ops *ops);
include/linux/thermal.h thermal_of_cooling_device_register(struct device_node *np, · line 212
Quoted 10 lines
include/linux/thermal.h +4
-4struct thermal_cooling_device * -devm_thermal_of_cooling_device_register (struct device *dev, -struct device_node *np, -const char *type,void *devdata, -const struct thermal_cooling_device_ops *ops); +devm_thermal_of_child_cooling_device_register (struct device *dev, +struct device_node *np, +const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops);
Should the underlying unmanaged thermal_of_cooling_device_register() also be renamed to maintain a consistent API surface between the managed and unmanaged variants?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
[email protected]
AI reviewRe: [PATCH v1 02/14] thermal/driver/tegra/soctherm: Use devm_ variant when registering a cooling device
In reply to Daniel LezcanoSashiko AI review found 1 potential issue(s): - [High] Teardown asymmetry / use-after-disable causing kernel panic on probe failure or driver unbind. --
Sashiko AI review found 1 potential issue(s):
- [High] Teardown asymmetry / use-after-disable causing kernel panic on probe failure or driver unbind. --
commit 7cd0558154b37412cd530ca6d0e191a67317cc1e
Author: Daniel Lezcano <[email protected]>
thermal/driver/tegra/soctherm: Use devm_ variant when registering a cooling device
This commit modifies the driver to use the devm_ variant for cooling device registration, aiming to fix a resource leak at removal time.
Quoted 3 lines
drivers/thermal/tegra/soctherm.c +0
-0
[ ... ]
drivers/thermal/tegra/soctherm.c static void soctherm_init_hw_throt_cdev(struct platform_device *pdev) · line 1705
Quoted 10 lines
drivers/thermal/tegra/soctherm.c +3
-3@@ -1700,9 +1700,9 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev) stc->init = true; }else { - tcd =thermal_of_cooling_device_register (np_stcc, - (char *)name, ts, - &throt_cooling_ops); + tcd =devm_thermal_of_cooling_device_register (dev, np_stcc, + (char *)name, ts, + &throt_cooling_ops);
Could this devm transition create a teardown asymmetry that leads to a kernel panic?
While this prevents the cooling device from leaking, the unregistration is now deferred until devres_release_all() runs (after probe() returns an error or remove() completes).
The driver still manually disables the hardware clocks during the probe error path and in tegra_soctherm_remove(). This creates a window where the cooling device remains registered and exposed to the thermal core and sysfs while the underlying hardware is powered down.
If there is a concurrent sysfs read of the cooling device state during this window, it will invoke throt_get_cdev_cur_state(), which executes:
readl(ts->regs + THROT_STATUS)
Accessing IP block registers with the clocks disabled causes a synchronous external abort on Tegra.
Should the clock disable operations also be managed via devres (e.g., using devm_add_action_or_reset()) to guarantee LIFO teardown ordering?
Quoted 3 lines
drivers/thermal/tegra/soctherm.c +0
-0if (IS_ERR_OR_NULL (tcd)) { dev_err(dev, "throttle-cfg: %s: failed to register cooling device\n",
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v1 05/14] thermal/core: Remove node pointer parameter parameter when registering a tz
In reply to Daniel LezcanoSashiko AI review found 2 potential issue(s): - [Medium] Commit subject incorrectly states the patch modifies a thermal zone registration function - [Low] Obsolete kernel-doc comment after parameter…
Sashiko AI review found 2 potential issue(s):
- [Medium] Commit subject incorrectly states the patch modifies a thermal zone registration function
- [Low] Obsolete kernel-doc comment after parameter removal
--
commit 2fc21aeabe9b7d0fc7c089083c8917e91802ab1b
Author: Daniel Lezcano <[email protected]>
thermal/core: Remove node pointer parameter parameter when registering a tz
This commit removes the device_node pointer parameter from the core thermal cooling device registration function, since OF variants are now available.
Quoted 1 line
thermal/core: Remove node pointer parameter parameter when registering a tz
This isn't a bug, but there's a typo (parameter parameter) in the subject line.
Additionally, does the subject incorrectly describe the changes? It mentions registering a tz (thermal zone), but the function being modified is __thermal_cooling_device_register, which registers a cooling device.
drivers/thermal/thermal_core.c void thermal_cooling_device_init_complete(struct thermal_cooling_device *cdev) · line 1047
Quoted 12 lines
drivers/thermal/thermal_core.c +0
-1@@ -1042,7 +1042,6 @@ void thermal_cooling_device_init_complete(struct thermal_cooling_device *cdev)/** * __thermal_cooling_device_register() - register a new thermal cooling device -* @np: a pointer to a device tree node. * @type: the thermal cooling device type. * @devdata: device private data. * @ops: standard thermal cooling devices callbacks.
Does this code leave an obsolete description in the kernel-doc?
Since the device tree node pointer parameter is being removed, the paragraph explaining it further down in the comment block seems stale:
drivers/thermal/thermal_core.c:__thermal_cooling_device_register() {
...
* This interface function adds a new thermal cooling device (fan/processor/...)
* to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
* to all the thermal zone devices registered at the same time.
* It also gives the opportunity to link the cooling device to a device tree
* node, so that it can be bound to a thermal zone created out of device tree. *
* Return: a pointer to the created struct thermal_cooling_device or an
...
}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH v1 03/14] thermal/core: Make thermal_cooling_device_init_complete() non static
In reply to Daniel LezcanoSashiko AI review found 1 potential issue(s): - [High] Missing initialization for devres-managed cooling devices leading to resource leaks and potential use-after-free. --
Sashiko AI review found 1 potential issue(s):
- [High] Missing initialization for devres-managed cooling devices leading to resource leaks and potential use-after-free. --
commit 45d7db5abc941e576e78d521933630ff7a08efc5
Author: Daniel Lezcano <[email protected]>
thermal/core: Make thermal_cooling_device_init_complete() non static
This commit splits thermal_cooling_device_init_complete() out from __thermal_cooling_device_register() so it can be called explicitly by specific implementations like the thermal OF code.
Quoted 4 lines
drivers/thermal/thermal_core.c +0
-0
[ ... ]
Quoted 7 lines
drivers/thermal/thermal_core.c +0
-2@@ -1127,8 +1127,6 @@ __thermal_cooling_device_register(struct device_node *np,if (current_state <= cdev->max_state)thermal_debug_cdev_add (cdev, current_state); -thermal_cooling_device_init_complete (cdev); -return cdev;
[ ... ]
Quoted 4 lines
drivers/thermal/thermal_of.c +0
-0
[ ... ]
Quoted 6 lines
drivers/thermal/thermal_of.c +1
-1@@ -531,7 +531,15 @@ thermal_of_cooling_device_register(struct device_node *np, const char *type, void *devdata, const struct thermal_cooling_device_ops *ops) { - return __thermal_cooling_device_register(np, type, devdata, ops); + struct thermal_cooling_device *cdev;
drivers/thermal/thermal_of.c thermal_of_cooling_device_register(struct device_node *np, · line 544
Quoted 10 lines
drivers/thermal/thermal_of.c +8
-0+ + cdev =__thermal_cooling_device_register (np, type, devdata, ops); +if (IS_ERR (cdev)) +return cdev; + +thermal_cooling_device_init_complete (cdev); + +return cdev; }EXPORT_SYMBOL_GPL (thermal_of_cooling_device_register);
Does this miss updating devm_thermal_of_cooling_device_register() which also calls __thermal_cooling_device_register() directly?
Because thermal_cooling_device_init_complete() was removed from the inner helper, cooling devices registered via the devm variant will no longer be added to the global thermal_cdev_list, and consequently won't bind to any thermal zones.
Furthermore, when devres calls thermal_cooling_device_release() on driver unload, thermal_cooling_device_unregister() aborts early because the device is missing from thermal_cdev_list:
void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
{
...
if (!thermal_cooling_device_present(cdev))
return;
...
}This skips device_unregister(), permanently leaking the memory and IDA, and leaving dangling sysfs entries which can trigger a use-after-free if accessed later.
While this is fixed later in the patch series by commit "thermal/of: Move the node pointer assignation in the OF code file", will this temporary breakage impact bisectability?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH v1 01/14] thermal/of: Move OF code where it belongs to
In reply to Daniel LezcanoSashiko AI review found 1 potential issue(s): - [Low] Moving `[devm_]thermal_of_cooling_device_register()` to `thermal_of.c` causes undefined reference build errors on non-OF platforms. --
Sashiko AI review found 1 potential issue(s):
- [Low] Moving [devm_]thermal_of_cooling_device_register() to thermal_of.c causes undefined reference build errors on non-OF platforms. --
commit 10b09a7422c3dc398ce39daac38970f758efdaee
Author: Daniel Lezcano <[email protected]>
thermal/of: Move OF code where it belongs to
This commit moves the OF-specific cooling device registration functions from the thermal core to the thermal-of implementation.
Quoted 4 lines
drivers/thermal/thermal_of.c +0
-0
[ ... ]
drivers/thermal/thermal_of.c void devm_thermal_of_zone_unregister(struct device *dev, struct thermal_zone_dev · line 566
Quoted 7 lines
drivers/thermal/thermal_of.c +7
-0+struct thermal_cooling_device * +devm_thermal_of_cooling_device_register (struct device *dev, +struct device_node *np, +const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops) +{ +struct thermal_cooling_device **ptr, *tcd;
Will moving these functions to thermal_of.c cause undefined reference linker errors on non-OF platforms?
Several non-OF drivers, such as dell-smm-hwmon on x86, use these variants unconditionally by passing a NULL pointer for the device tree node. Since thermal_of.c is only compiled when CONFIG_THERMAL_OF is enabled, and the headers do not provide dummy stubs for the disabled case, this move appears to break the build for those platforms.
I see this is addressed later in the patch series by commits 18601ab408a18, c24a43d962cbf, and 06c743d31c831. Could the dummy stubs or non-OF variants be introduced before or during this move to prevent bisectability issues?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH v1 07/14] hwmon:: Use non-OF thermal cooling device register function
In reply to Daniel LezcanoSashiko AI review found 2 potential issue(s): - [High] This problem wasn't introduced by this patch, but in mlxreg-fan.c, the hwmon sysfs interfaces are exposed before the thermal cooling device…
Sashiko AI review found 2 potential issue(s):
- [High] This problem wasn't introduced by this patch, but in mlxreg-fan.c, the hwmon sysfs interfaces are exposed before the thermal cooling device pointer (pwm->cdev) is initialized, leading to a possible NULL pointer dereference.
- [High] This problem wasn't introduced by this patch, but in mlxreg-fan.c, the variables pwm->last_hwmon_state and pwm->last_thermal_state are read and modified concurrently without any locking, leading to inconsistent hardware state. --
commit c24a43d962cbf165d7c767a5a51aa1a15586bd28
Author: Daniel Lezcano <[email protected]>
hwmon:: Use non-OF thermal cooling device register function
Make HWMON drivers which are not based on device tree to use the corresponding non-OF functions.
[ ... ]
drivers/hwmon/mlxreg-fan.c static int mlxreg_fan_cooling_config(struct device *dev, struct mlxreg_fan *fan) · line 585
Quoted 8 lines
drivers/hwmon/mlxreg-fan.c +0
-0@@ -583,8 +583,8 @@ static int mlxreg_fan_cooling_config(struct device *dev, struct mlxreg_fan *fan) pwm->fan = fan;/* Set minimal PWM speed. */ pwm->last_hwmon_state =MLXREG_FAN_PWM_DUTY2STATE (MLXREG_FAN_MIN_DUTY );
This isn't a bug introduced by this commit, but are pwm->last_hwmon_state and pwm->last_thermal_state read and modified concurrently without locking?
The function mlxreg_fan_write() (executed via sysfs) and mlxreg_fan_set_cur_state() (executed by the thermal subsystem) concurrently access and mutate these variables.
While the hwmon core serializes sysfs operations via hwmon_device_register_with_info(), it does not serialize calls from the thermal subsystem.
Because there is no lock protecting this multi-variable state, can a Time-Of-Check to Time-Of-Use race occur? One thread may evaluate the maximum of the two states using stale data and write an incorrectly low value to the hardware.
Does this violate the hwmon subsystem guidelines requiring drivers to implement locking for attributes registered by any other means?
drivers/hwmon/mlxreg-fan.c static int mlxreg_fan_cooling_config(struct device *dev, struct mlxreg_fan *fan) · line 587
Quoted 4 lines
drivers/hwmon/mlxreg-fan.c +2
-2- pwm->cdev =devm_thermal_of_cooling_device_register (dev,NULL , mlxreg_fan_name[i], - pwm, &mlxreg_fan_cooling_ops); + pwm->cdev =devm_thermal_cooling_device_register (dev, mlxreg_fan_name[i], + pwm, &mlxreg_fan_cooling_ops);
This problem also wasn't introduced by this commit, but are the hwmon sysfs interfaces exposed before the thermal cooling device pointer (pwm->cdev) is initialized?
In mlxreg_fan_probe(), the hwmon device is registered via devm_hwmon_device_register_with_info() before mlxreg_fan_cooling_config() is called. This exposes sysfs attributes to user-space immediately.
If a user writes to the PWM attribute in this narrow window, mlxreg_fan_write() will be invoked and pass the currently uninitialized pwm->cdev to _mlxreg_fan_set_cur_state().
Can this lead to a NULL pointer dereference when cdev->devdata is unconditionally dereferenced?
Quoted 3 lines
drivers/hwmon/mlxreg-fan.c +0
-0if (IS_ERR (pwm->cdev)) {dev_err (dev,"Failed to register cooling device\n" );return PTR_ERR (pwm->cdev);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
[email protected]
AI reviewRe: [PATCH v1 13/14] thermal/of: Process cooling device index in cooling-spec
In reply to Daniel LezcanoSashiko AI review found 1 potential issue(s): - [Medium] Brittle logic uses an exact `args_count == 3` check to identify the new binding format, leading to silent misparsing of bindings with more…
Sashiko AI review found 1 potential issue(s):
- [Medium] Brittle logic uses an exact args_count == 3 check to identify the new binding format, leading to silent misparsing of bindings with more than 3 cells. --
commit 90bb7215d764688a8fd719c59ad60bede0aee71e
Author: Daniel Lezcano <[email protected]>
thermal/of: Process cooling device index in cooling-spec
This commit updates thermal OF binding parsing to support a new format that includes a cooling device index alongside mitigation limits. It checks the argument count from the device tree specifier to differentiate between the legacy and new formats.
Quoted 4 lines
drivers/thermal/thermal_of.c +0
-0
[ ... ]
Quoted 6 lines
drivers/thermal/thermal_of.c +2
-0@@ -264,11 +264,29 @@ static bool thermal_of_get_cooling_spec(struct device_node *map_np, int index,return false; } +/* +* There are two formats:
drivers/thermal/thermal_of.c static bool thermal_of_get_cooling_spec(struct device_node *map_np, int index, · line 278
Quoted 10 lines
drivers/thermal/thermal_of.c +10
-0+* - Legacy format : <&cdev lower upper> +* - New format : <&cdev of_index lower upper> +* +* With the new format, along with the device node pointer, +* the of_index must match with the cooling device of_index in +* order to bind +*/ +if (cooling_spec.args_count ==3 && + cooling_spec.args[0 ] != cdev->of_index) +return false;
Does this code bypass the index validation for malformed bindings or future extensions? If a device tree specifies a cell count greater than 3, this condition evaluates to false and skips the check entirely.
drivers/thermal/thermal_of.c static bool thermal_of_get_cooling_spec(struct device_node *map_np, int index, · line 285
Quoted 9 lines
drivers/thermal/thermal_of.c +4
-2+if (cooling_spec.np != cdev->np)return false; - c->lower = cooling_spec.args[0 ]; - c->upper = cooling_spec.args[1 ]; +if (cooling_spec.args_count !=3 ) { + c->lower = cooling_spec.args[0 ]; + c->upper = cooling_spec.args[1 ];
Will this incorrectly parse the limits if the argument count is greater than 3?
Since a count greater than 3 falls into this legacy branch, it would assign the device index from args[0] to the lower limit, instead of args[1].
Should this logic either explicitly reject counts greater than 3, or use a greater-than-or-equal condition to identify the new format?
Quoted 4 lines
drivers/thermal/thermal_of.c +4
-0+ }else { + c->lower = cooling_spec.args[1 ]; + c->upper = cooling_spec.args[2 ]; + }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
Krzysztof Kozlowski
maintainerRe: [PATCH v1 14/14] dt-bindings: thermal: cooling-devices: Update support for 3 cells cooling device
In reply to Daniel LezcanoQuoted 8 lines · Daniel Lezcano
Documentation/devicetree/bindings/thermal/thermal-cooling-devices.yaml +0
-0@@ -44,10 +44,14 @@ select: true properties: "#cooling-cells": description:
Documentation/devicetree/bindings/thermal/thermal-cooling-devices.yaml select: true · line 54
Quoted 10 lines
Documentation/devicetree/bindings/thermal/thermal-cooling-devices.yaml +6
-2- Must be 2, in order to specify minimum and maximum cooling state used in + Must be 2 or 3. If 2, specifies minimum and maximum cooling state used in the cooling-maps reference. The first cell is the minimum cooling state and the second cell is the maximum cooling state requested. - const: 2 + If 3, the first cell specifies the thermal mitigation device specifier + index for devices that support multiple thermal mitigation mechanisms. + The two other cells are respectively the minimum cooling state and the + maximum cooling state. + enum: [2, 3]
In the same commit you need to narrow Documentation/devicetree/bindings/hwmon/pwm-fan.yaml
so it will keep value of '2' (const: 2, like all other bindings).
Best regards,
Krzysztof
Re: [PATCH v1 07/14] hwmon:: Use non-OF thermal cooling device register function
In reply to Daniel LezcanoQuoted 4 lines · Daniel Lezcano
Make HWMON drivers which are not based on device tree to use the corresponding non-OF functions.
Signed-off-by Daniel Lezcano <[email protected]>
Quoted 51 lines
--- drivers/hwmon/cros_ec_hwmon.c | 4 ++-- drivers/hwmon/dell-smm-hwmon.c | 4 ++-- drivers/hwmon/mlxreg-fan.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)drivers/hwmon/cros_ec_hwmon.c +2
-2@@ -532,8 +532,8 @@ static void cros_ec_hwmon_register_fan_cooling_devices(struct device *dev, cpriv->hwmon_priv = priv; cpriv->index = i; - cdev =devm_thermal_of_cooling_device_register (dev,NULL , type, cpriv, - &cros_ec_thermal_cooling_ops); + cdev =devm_thermal_cooling_device_register (dev, type, cpriv, + &cros_ec_thermal_cooling_ops);if (IS_ERR (cdev)) {dev_warn (dev,"failed to register fan %zu as a cooling device: %pe\n" , i, cdev);drivers/hwmon/dell-smm-hwmon.c +2
-2@@ -1161,8 +1161,8 @@ static int dell_smm_init_cdev(struct device *dev, u8 fan_num)if (cdata) { cdata->fan_num = fan_num; cdata->data = data; - cdev =devm_thermal_of_cooling_device_register (dev,NULL , name, cdata, - &dell_smm_cooling_ops); + cdev =devm_thermal_cooling_device_register (dev, name, cdata, + &dell_smm_cooling_ops);if (IS_ERR (cdev)) {devm_kfree (dev, cdata); ret =PTR_ERR (cdev);drivers/hwmon/mlxreg-fan.c +2
-2@@ -583,8 +583,8 @@ static int mlxreg_fan_cooling_config(struct device *dev, struct mlxreg_fan *fan) pwm->fan = fan;/* Set minimal PWM speed. */ pwm->last_hwmon_state =MLXREG_FAN_PWM_DUTY2STATE (MLXREG_FAN_MIN_DUTY ); - pwm->cdev =devm_thermal_of_cooling_device_register (dev,NULL , mlxreg_fan_name[i], - pwm, &mlxreg_fan_cooling_ops); + pwm->cdev =devm_thermal_cooling_device_register (dev, mlxreg_fan_name[i], + pwm, &mlxreg_fan_cooling_ops);if (IS_ERR (pwm->cdev)) {dev_err (dev,"Failed to register cooling device\n" );return PTR_ERR (pwm->cdev);
Re: [PATCH v1 07/14] hwmon:: Use non-OF thermal cooling device register function
Quoted 7 lines · Guenter Roeck
Quoted 4 lines · Daniel Lezcano
Make HWMON drivers which are not based on device tree to use the corresponding non-OF functions.
Signed-off-by Daniel Lezcano <[email protected]>Acked-by Guenter Roeck <[email protected]>
Thanks for the review
Re: [PATCH v1 14/14] dt-bindings: thermal: cooling-devices: Update support for 3 cells cooling device
In reply to Krzysztof KozlowskiQuoted 15 lines · Krzysztof Kozlowski
Quoted 14 lines · Daniel Lezcano
Documentation/devicetree/bindings/thermal/thermal-cooling-devices.yaml +2
-2@@ -44,10 +44,14 @@ select: true properties: "#cooling-cells": description: - Must be 2, in order to specify minimum and maximum cooling state used in + Must be 2 or 3. If 2, specifies minimum and maximum cooling state used in the cooling-maps reference. The first cell is the minimum cooling state and the second cell is the maximum cooling state requested. - const: 2 + If 3, the first cell specifies the thermal mitigation device specifier
Quoted 8 lines
Documentation/devicetree/bindings/thermal/thermal-cooling-devices.yaml select: true · line 54
Quoted 4 lines
Documentation/devicetree/bindings/thermal/thermal-cooling-devices.yaml +4
-0+ index for devices that support multiple thermal mitigation mechanisms. + The two other cells are respectively the minimum cooling state and the + maximum cooling state. + enum: [2, 3]In the same commit you need to narrow
Documentation/devicetree/bindings/hwmon/pwm-fan.yaml
so it will keep value of '2' (const: 2, like all other bindings).
Ah yes, thanks !