public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] driver: thermal: simplify the traverse of sensor in thermal_zone.
@ 2023-11-02  5:51 xinglong.yang
  2023-11-02  9:18 ` kernel test robot
  0 siblings, 1 reply; 3+ messages in thread
From: xinglong.yang @ 2023-11-02  5:51 UTC (permalink / raw)
  To: xinglong.yang, rafael, daniel.lezcano, amitk, rui.zhang
  Cc: linux-pm, linux-kernel

The number of sensor in a thermal zone needs to be greater than zero
and equal to one. Add the opinion when the number of sensor is greater
than one in a thermal zone.

There is also no need to traverse the sensor in the thermal zone,
because there is only one sensor on one thermal zone.

Signed-off-by: xinglong.yang <xinglong.yang@cixtech.com>
---
 drivers/thermal/thermal_of.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index e615f735f4c0..a405754c42cd 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -186,6 +186,7 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int
 	for_each_available_child_of_node(np, tz) {
 
 		int count, i;
+		int ret;
 
 		count = of_count_phandle_with_args(tz, "thermal-sensors",
 						   "#thermal-sensor-cells");
@@ -193,26 +194,25 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int
 			pr_err("%pOFn: missing thermal sensor\n", tz);
 			tz = ERR_PTR(-EINVAL);
 			goto out;
+		} else if (count > 1) {
+			pr_err("%pOFn: number of thermal sensor greater than one\n", tz);
+			tz = ERR_PTR(-EINVAL);
+			goto out;
 		}
 
-		for (i = 0; i < count; i++) {
-
-			int ret;
-
-			ret = of_parse_phandle_with_args(tz, "thermal-sensors",
-							 "#thermal-sensor-cells",
-							 i, &sensor_specs);
-			if (ret < 0) {
-				pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", tz, ret);
-				tz = ERR_PTR(ret);
-				goto out;
-			}
+		ret = of_parse_phandle_with_args(tz, "thermal-sensors",
+						 "#thermal-sensor-cells",
+						 0, &sensor_specs);
+		if (ret < 0) {
+			pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", tz, ret);
+			tz = ERR_PTR(ret);
+			goto out;
+		}
 
-			if ((sensor == sensor_specs.np) && id == (sensor_specs.args_count ?
-								  sensor_specs.args[0] : 0)) {
-				pr_debug("sensor %pOFn id=%d belongs to %pOFn\n", sensor, id, tz);
-				goto out;
-			}
+		if ((sensor == sensor_specs.np) && id == (sensor_specs.args_count ?
+							  sensor_specs.args[0] : 0)) {
+			pr_debug("sensor %pOFn id=%d belongs to %pOFn\n", sensor, id, tz);
+			goto out;
 		}
 	}
 	tz = ERR_PTR(-ENODEV);
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread
* [PATCH] driver: thermal: simplify the traverse of sensor in thermal_zone.
@ 2023-11-02  3:09 sean yang
  0 siblings, 0 replies; 3+ messages in thread
From: sean yang @ 2023-11-02  3:09 UTC (permalink / raw)
  To: xinglong.yang, rafael, daniel.lezcano, amitk, rui.zhang
  Cc: linux-pm, linux-kernel

The number of sensor in a thermal zone needs to be greater than zero
and equal to one. Add the opinion when the number of sensor is greater
than one in a thermal zone.

There is also no need to traverse the sensor in the thermal zone,
because there is only one sensor on one thermal zone.

Signed-off-by: xinglong.yang <xinglong.yang@cixtech.com>
---
 drivers/thermal/thermal_of.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index e615f735f4c0..a405754c42cd 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -186,6 +186,7 @@ static struct device_node
*of_thermal_zone_find(struct device_node *sensor, int
  for_each_available_child_of_node(np, tz) {

  int count, i;
+ int ret;

  count = of_count_phandle_with_args(tz, "thermal-sensors",
     "#thermal-sensor-cells");
@@ -193,26 +194,25 @@ static struct device_node
*of_thermal_zone_find(struct device_node *sensor, int
  pr_err("%pOFn: missing thermal sensor\n", tz);
  tz = ERR_PTR(-EINVAL);
  goto out;
+ } else if (count > 1) {
+ pr_err("%pOFn: number of thermal sensor greater than one\n", tz);
+ tz = ERR_PTR(-EINVAL);
+ goto out;
  }

- for (i = 0; i < count; i++) {
-
- int ret;
-
- ret = of_parse_phandle_with_args(tz, "thermal-sensors",
- "#thermal-sensor-cells",
- i, &sensor_specs);
- if (ret < 0) {
- pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", tz, ret);
- tz = ERR_PTR(ret);
- goto out;
- }
+ ret = of_parse_phandle_with_args(tz, "thermal-sensors",
+ "#thermal-sensor-cells",
+ 0, &sensor_specs);
+ if (ret < 0) {
+ pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", tz, ret);
+ tz = ERR_PTR(ret);
+ goto out;
+ }

- if ((sensor == sensor_specs.np) && id == (sensor_specs.args_count ?
-   sensor_specs.args[0] : 0)) {
- pr_debug("sensor %pOFn id=%d belongs to %pOFn\n", sensor, id, tz);
- goto out;
- }
+ if ((sensor == sensor_specs.np) && id == (sensor_specs.args_count ?
+   sensor_specs.args[0] : 0)) {
+ pr_debug("sensor %pOFn id=%d belongs to %pOFn\n", sensor, id, tz);
+ goto out;
  }
  }
  tz = ERR_PTR(-ENODEV);
-- 
2.42.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-02  9:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-02  5:51 [PATCH] driver: thermal: simplify the traverse of sensor in thermal_zone xinglong.yang
2023-11-02  9:18 ` kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2023-11-02  3:09 sean yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox