public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] thermal/drivers/sprd: Use for_each_child_of_node_scoped() in probe
@ 2026-04-15 15:07 Felix Gu
  0 siblings, 0 replies; only message in thread
From: Felix Gu @ 2026-04-15 15:07 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Orson Zhai, Baolin Wang, Chunyan Zhang
  Cc: linux-pm, linux-kernel, Felix Gu

Use for_each_child_of_node_scoped() to avoid manual cleanup
of_node_put() in early exits from the loop, simplify the code.

Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/thermal/sprd_thermal.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c
index d683fcb0f8ab..069bc13ffc57 100644
--- a/drivers/thermal/sprd_thermal.c
+++ b/drivers/thermal/sprd_thermal.c
@@ -331,7 +331,6 @@ static void sprd_thm_toggle_sensor(struct sprd_thermal_sensor *sen, bool on)
 static int sprd_thm_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
-	struct device_node *sen_child;
 	struct sprd_thermal_data *thm;
 	struct sprd_thermal_sensor *sen;
 	const struct sprd_thm_variant_data *pdata;
@@ -380,12 +379,10 @@ static int sprd_thm_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	for_each_child_of_node(np, sen_child) {
+	for_each_child_of_node_scoped(np, sen_child) {
 		sen = devm_kzalloc(&pdev->dev, sizeof(*sen), GFP_KERNEL);
-		if (!sen) {
-			ret = -ENOMEM;
-			goto of_put;
-		}
+		if (!sen)
+			return -ENOMEM;
 
 		sen->data = thm;
 		sen->dev = &pdev->dev;
@@ -393,13 +390,13 @@ static int sprd_thm_probe(struct platform_device *pdev)
 		ret = of_property_read_u32(sen_child, "reg", &sen->id);
 		if (ret) {
 			dev_err(&pdev->dev, "get sensor reg failed");
-			goto of_put;
+			return ret;
 		}
 
 		ret = sprd_thm_sensor_calibration(sen_child, thm, sen);
 		if (ret) {
 			dev_err(&pdev->dev, "efuse cal analysis failed");
-			goto of_put;
+			return ret;
 		}
 
 		sprd_thm_sensor_init(thm, sen);
@@ -411,31 +408,25 @@ static int sprd_thm_probe(struct platform_device *pdev)
 		if (IS_ERR(sen->tzd)) {
 			dev_err(&pdev->dev, "register thermal zone failed %d\n",
 				sen->id);
-			ret = PTR_ERR(sen->tzd);
-			goto of_put;
+			return PTR_ERR(sen->tzd);
 		}
 
 		thm->sensor[sen->id] = sen;
 	}
-	/* sen_child set to NULL at this point */
 
 	ret = sprd_thm_set_ready(thm);
 	if (ret)
-		goto of_put;
+		return ret;
 
 	ret = sprd_thm_wait_temp_ready(thm);
 	if (ret)
-		goto of_put;
+		return ret;
 
 	for (i = 0; i < thm->nr_sensors; i++)
 		sprd_thm_toggle_sensor(thm->sensor[i], true);
 
 	platform_set_drvdata(pdev, thm);
 	return 0;
-
-of_put:
-	of_node_put(sen_child);
-	return ret;
 }
 
 #ifdef CONFIG_PM_SLEEP

---
base-commit: 936c21068d7ade00325e40d82bfd2f3f29d9f659
change-id: 20260415-sprd-3034c3aa9649

Best regards,
-- 
Felix Gu <ustc.gu@gmail.com>


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-04-15 15:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-15 15:07 [PATCH] thermal/drivers/sprd: Use for_each_child_of_node_scoped() in probe Felix Gu

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