diff mbox series

[v2] driver: thermal: simplify the traverse of sensor in thermal_zone.

Message ID 20231102093334.1363324-1-xinglong.yang@cixtech.com (mailing list archive)
State New
Delegated to: Daniel Lezcano
Headers show
Series [v2] driver: thermal: simplify the traverse of sensor in thermal_zone. | expand

Commit Message

xinglong.yang Nov. 2, 2023, 9:33 a.m. UTC
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 | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index e615f735f4c0..c800599e7ebd 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -185,7 +185,8 @@  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 count;
+		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);