diff mbox series

[RESEND,v1,2/8] thermal: hisi: Use thermal_zone_for_each_trip() in hisi_thermal_register_sensor()

Message ID 1994088.PYKUYFuaPT@rjwysocki.net
State New
Headers show
Series thermal: Use trip pointers in thermal driver interface | expand

Commit Message

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

Modify hisi_thermal_register_sensor() to use thermal_zone_for_each_trip()
for walking trip points instead of iterating over trip indices and using
thermal_zone_get_trip() to get a struct thermal_trip pointer from a trip
index.

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

This patch does not depend on the previous patch(es) in the series.

---
 drivers/thermal/hisi_thermal.c |   22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

Comments

Lukasz Luba Aug. 2, 2024, 9:35 a.m. UTC | #1
On 7/29/24 16:56, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Modify hisi_thermal_register_sensor() to use thermal_zone_for_each_trip()
> for walking trip points instead of iterating over trip indices and using
> thermal_zone_get_trip() to get a struct thermal_trip pointer from a trip
> index.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> 
> This patch does not depend on the previous patch(es) in the series.
> 
> ---
>   drivers/thermal/hisi_thermal.c |   22 +++++++++++++---------
>   1 file changed, 13 insertions(+), 9 deletions(-)
> 
> Index: linux-pm/drivers/thermal/hisi_thermal.c
> ===================================================================
> --- linux-pm.orig/drivers/thermal/hisi_thermal.c
> +++ linux-pm/drivers/thermal/hisi_thermal.c
> @@ -465,6 +465,18 @@ static irqreturn_t hisi_thermal_alarm_ir
>   	return IRQ_HANDLED;
>   }
>   
> +static int hisi_trip_walk_cb(struct thermal_trip *trip, void *arg)
> +{
> +	struct hisi_thermal_sensor *sensor = arg;
> +
> +	if (trip->type != THERMAL_TRIP_PASSIVE)
> +		return 0;
> +
> +	sensor->thres_temp = trip->temperature;
> +	/* Return nonzero to terminate the search. */
> +	return 1;
> +}
> +
>   static int hisi_thermal_register_sensor(struct platform_device *pdev,
>   					struct hisi_thermal_sensor *sensor)
>   {
> @@ -482,15 +494,7 @@ static int hisi_thermal_register_sensor(
>   		return ret;
>   	}
>   
> -	for (i = 0; i < thermal_zone_get_num_trips(sensor->tzd); i++) {
> -
> -		thermal_zone_get_trip(sensor->tzd, i, &trip);
> -
> -		if (trip.type == THERMAL_TRIP_PASSIVE) {
> -			sensor->thres_temp = trip.temperature;
> -			break;
> -		}
> -	}
> +	thermal_zone_for_each_trip(sensor->tzd, hisi_trip_walk_cb, sensor);
>   
>   	return 0;
>   }
> 
> 
> 



Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
diff mbox series

Patch

Index: linux-pm/drivers/thermal/hisi_thermal.c
===================================================================
--- linux-pm.orig/drivers/thermal/hisi_thermal.c
+++ linux-pm/drivers/thermal/hisi_thermal.c
@@ -465,6 +465,18 @@  static irqreturn_t hisi_thermal_alarm_ir
 	return IRQ_HANDLED;
 }
 
+static int hisi_trip_walk_cb(struct thermal_trip *trip, void *arg)
+{
+	struct hisi_thermal_sensor *sensor = arg;
+
+	if (trip->type != THERMAL_TRIP_PASSIVE)
+		return 0;
+
+	sensor->thres_temp = trip->temperature;
+	/* Return nonzero to terminate the search. */
+	return 1;
+}
+
 static int hisi_thermal_register_sensor(struct platform_device *pdev,
 					struct hisi_thermal_sensor *sensor)
 {
@@ -482,15 +494,7 @@  static int hisi_thermal_register_sensor(
 		return ret;
 	}
 
-	for (i = 0; i < thermal_zone_get_num_trips(sensor->tzd); i++) {
-
-		thermal_zone_get_trip(sensor->tzd, i, &trip);
-
-		if (trip.type == THERMAL_TRIP_PASSIVE) {
-			sensor->thres_temp = trip.temperature;
-			break;
-		}
-	}
+	thermal_zone_for_each_trip(sensor->tzd, hisi_trip_walk_cb, sensor);
 
 	return 0;
 }