diff mbox series

driver: thermal: simplify the traverse of sensor in thermal_zone.

Message ID CADGqjFLEJ8WK+_DHJo4APfJGkDf8PLNRR0JboEVk2TL2oC2iog@mail.gmail.com (mailing list archive)
State Superseded, archived
Headers show
Series driver: thermal: simplify the traverse of sensor in thermal_zone. | expand

Commit Message

xinglong.yang Nov. 2, 2023, 3:09 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 | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

     "#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);
diff mbox series

Patch

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",