diff mbox series

[v3,04/14] thermal: sysfs: Use the dev argument in instance-related show/store

Message ID 1987669.PYKUYFuaPT@rjwysocki.net (mailing list archive)
State Mainlined, archived
Headers show
Series thermal: Rework binding cooling devices to trip points | expand

Commit Message

Rafael J. Wysocki Aug. 19, 2024, 3:56 p.m. UTC
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Two sysfs show/store functions for attributes representing thermal
instances, trip_point_show() and weight_store(), retrieve the thermal
zone pointer from the instance object at hand, but they may also get
it from their dev argument, which is more consistent with what the
other thermal sysfs functions do, so make them do so.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

v1 -> v3: No changes (previously [06/17])

---
 drivers/thermal/thermal_sysfs.c |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Comments

Zhang Rui Aug. 20, 2024, 7:05 a.m. UTC | #1
On Mon, 2024-08-19 at 17:56 +0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Two sysfs show/store functions for attributes representing thermal
> instances, trip_point_show() and weight_store(), retrieve the thermal
> zone pointer from the instance object at hand, but they may also get
> it from their dev argument, which is more consistent with what the
> other thermal sysfs functions do, so make them do so.
> 
> No intentional functional impact.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Reviewed-by: Zhang Rui <rui.zhang@intel.com>

thanks,
rui

> ---
> 
> v1 -> v3: No changes (previously [06/17])
> 
> ---
>  drivers/thermal/thermal_sysfs.c |   15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> Index: linux-pm/drivers/thermal/thermal_sysfs.c
> ===================================================================
> --- linux-pm.orig/drivers/thermal/thermal_sysfs.c
> +++ linux-pm/drivers/thermal/thermal_sysfs.c
> @@ -836,13 +836,12 @@ void thermal_cooling_device_stats_reinit
>  ssize_t
>  trip_point_show(struct device *dev, struct device_attribute *attr,
> char *buf)
>  {
> +       struct thermal_zone_device *tz = to_thermal_zone(dev);
>         struct thermal_instance *instance;
>  
> -       instance =
> -           container_of(attr, struct thermal_instance, attr);
> +       instance = container_of(attr, struct thermal_instance, attr);
>  
> -       return sprintf(buf, "%d\n",
> -                      thermal_zone_trip_id(instance->tz, instance-
> >trip));
> +       return sprintf(buf, "%d\n", thermal_zone_trip_id(tz,
> instance->trip));
>  }
>  
>  ssize_t
> @@ -858,6 +857,7 @@ weight_show(struct device *dev, struct d
>  ssize_t weight_store(struct device *dev, struct device_attribute
> *attr,
>                      const char *buf, size_t count)
>  {
> +       struct thermal_zone_device *tz = to_thermal_zone(dev);
>         struct thermal_instance *instance;
>         int ret, weight;
>  
> @@ -868,14 +868,13 @@ ssize_t weight_store(struct device *dev,
>         instance = container_of(attr, struct thermal_instance,
> weight_attr);
>  
>         /* Don't race with governors using the 'weight' value */
> -       mutex_lock(&instance->tz->lock);
> +       mutex_lock(&tz->lock);
>  
>         instance->weight = weight;
>  
> -       thermal_governor_update_tz(instance->tz,
> -                                  THERMAL_INSTANCE_WEIGHT_CHANGED);
> +       thermal_governor_update_tz(tz,
> THERMAL_INSTANCE_WEIGHT_CHANGED);
>  
> -       mutex_unlock(&instance->tz->lock);
> +       mutex_unlock(&tz->lock);
>  
>         return count;
>  }
> 
> 
>
lihuisong (C) Aug. 20, 2024, 7:59 a.m. UTC | #2
在 2024/8/19 23:56, Rafael J. Wysocki 写道:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Two sysfs show/store functions for attributes representing thermal
> instances, trip_point_show() and weight_store(), retrieve the thermal
> zone pointer from the instance object at hand, but they may also get
> it from their dev argument, which is more consistent with what the
> other thermal sysfs functions do, so make them do so.
>
> No intentional functional impact.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>
> v1 -> v3: No changes (previously [06/17])
>
> ---
>   drivers/thermal/thermal_sysfs.c |   15 +++++++--------
>   1 file changed, 7 insertions(+), 8 deletions(-)
Using to_thermal_zone() and to_cooling_device() in sysfs looks good to me.
Acked-by: Huisong Li <lihuisong@huawei.com>
Daniel Lezcano Aug. 21, 2024, 9:36 a.m. UTC | #3
On 19/08/2024 17:56, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Two sysfs show/store functions for attributes representing thermal
> instances, trip_point_show() and weight_store(), retrieve the thermal
> zone pointer from the instance object at hand, but they may also get
> it from their dev argument, which is more consistent with what the
> other thermal sysfs functions do, so make them do so.
> 
> No intentional functional impact.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
diff mbox series

Patch

Index: linux-pm/drivers/thermal/thermal_sysfs.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_sysfs.c
+++ linux-pm/drivers/thermal/thermal_sysfs.c
@@ -836,13 +836,12 @@  void thermal_cooling_device_stats_reinit
 ssize_t
 trip_point_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
+	struct thermal_zone_device *tz = to_thermal_zone(dev);
 	struct thermal_instance *instance;
 
-	instance =
-	    container_of(attr, struct thermal_instance, attr);
+	instance = container_of(attr, struct thermal_instance, attr);
 
-	return sprintf(buf, "%d\n",
-		       thermal_zone_trip_id(instance->tz, instance->trip));
+	return sprintf(buf, "%d\n", thermal_zone_trip_id(tz, instance->trip));
 }
 
 ssize_t
@@ -858,6 +857,7 @@  weight_show(struct device *dev, struct d
 ssize_t weight_store(struct device *dev, struct device_attribute *attr,
 		     const char *buf, size_t count)
 {
+	struct thermal_zone_device *tz = to_thermal_zone(dev);
 	struct thermal_instance *instance;
 	int ret, weight;
 
@@ -868,14 +868,13 @@  ssize_t weight_store(struct device *dev,
 	instance = container_of(attr, struct thermal_instance, weight_attr);
 
 	/* Don't race with governors using the 'weight' value */
-	mutex_lock(&instance->tz->lock);
+	mutex_lock(&tz->lock);
 
 	instance->weight = weight;
 
-	thermal_governor_update_tz(instance->tz,
-				   THERMAL_INSTANCE_WEIGHT_CHANGED);
+	thermal_governor_update_tz(tz, THERMAL_INSTANCE_WEIGHT_CHANGED);
 
-	mutex_unlock(&instance->tz->lock);
+	mutex_unlock(&tz->lock);
 
 	return count;
 }