public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: "xinglong.yang" <seanyang230@gmail.com>
To: xinglong.yang@cixtech.com, rafael@kernel.org,
	daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] driver: thermal: simplify the traverse of sensor in thermal_zone.
Date: Thu,  2 Nov 2023 13:51:20 +0800	[thread overview]
Message-ID: <20231102055120.1192015-1-xinglong.yang@cixtech.com> (raw)

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


             reply	other threads:[~2023-11-02  5:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-02  5:51 xinglong.yang [this message]
2023-11-02  9:18 ` [PATCH] driver: thermal: simplify the traverse of sensor in thermal_zone kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2023-11-02  3:09 sean yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231102055120.1192015-1-xinglong.yang@cixtech.com \
    --to=seanyang230@gmail.com \
    --cc=amitk@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=xinglong.yang@cixtech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox