linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes
@ 2024-08-16 10:54 Krzysztof Kozlowski
  2024-08-16 10:54 ` [PATCH v2 01/13] memory: atmel-ebi: use scoped device node handling to simplify error paths Krzysztof Kozlowski
                   ` (13 more replies)
  0 siblings, 14 replies; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Krzysztof Kozlowski, Jonathan Cameron

Changes in v2:
- Add tags
- Wrap lines before of_parse_phandle() (Jonathan)
- Few new patches (see individual changelogs)
- Link to v1: https://lore.kernel.org/r/20240812-cleanup-h-of-node-put-memory-v1-0-5065a8f361d2@linaro.org

Make code a bit simpler and smaller by using cleanup.h when handling
device nodes.

Best regards,
Krzysztof

---
Krzysztof Kozlowski (13):
      memory: atmel-ebi: use scoped device node handling to simplify error paths
      memory: atmel-ebi: simplify with scoped for each OF child loop
      memory: samsung: exynos5422-dmc: simplify dmc->dev usage
      memory: samsung: exynos5422-dmc: use scoped device node handling to simplify error paths
      memory: stm32-fmc2-ebi: simplify with scoped for each OF child loop
      memory: stm32-fmc2-ebi: simplify with dev_err_probe()
      memory: tegra-mc: simplify with scoped for each OF child loop
      memory: tegra124-emc: simplify with scoped for each OF child loop
      memory: tegra20-emc: simplify with scoped for each OF child loop
      memory: tegra30-emc: simplify with scoped for each OF child loop
      memory: ti-aemif: simplify with dev_err_probe()
      memory: ti-aemif: simplify with devm_clk_get_enabled()
      memory: ti-aemif: simplify with scoped for each OF child loop

 drivers/memory/atmel-ebi.c              | 35 +++++--------
 drivers/memory/samsung/exynos5422-dmc.c | 90 +++++++++++++++------------------
 drivers/memory/stm32-fmc2-ebi.c         | 23 +++------
 drivers/memory/tegra/mc.c               | 11 ++--
 drivers/memory/tegra/tegra124-emc.c     |  7 +--
 drivers/memory/tegra/tegra20-emc.c      |  7 +--
 drivers/memory/tegra/tegra30-emc.c      |  7 +--
 drivers/memory/ti-aemif.c               | 48 +++++-------------
 8 files changed, 80 insertions(+), 148 deletions(-)
---
base-commit: cf4d89333014d387065aa296160aaec5cec04cc5
change-id: 20240812-cleanup-h-of-node-put-memory-dd6de1b92917

Best regards,
-- 
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>



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

* [PATCH v2 01/13] memory: atmel-ebi: use scoped device node handling to simplify error paths
  2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
@ 2024-08-16 10:54 ` Krzysztof Kozlowski
  2024-08-19 16:04   ` Jonathan Cameron
  2024-08-27 10:35   ` Nicolas Ferre
  2024-08-16 10:54 ` [PATCH v2 02/13] memory: atmel-ebi: simplify with scoped for each OF child loop Krzysztof Kozlowski
                   ` (12 subsequent siblings)
  13 siblings, 2 replies; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Krzysztof Kozlowski

Obtain the device node reference with scoped/cleanup.h to reduce error
handling and make the code a bit simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

---

Changes in v2:
1. Wrap line before of_parse_phandle()
---
 drivers/memory/atmel-ebi.c | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/drivers/memory/atmel-ebi.c b/drivers/memory/atmel-ebi.c
index e8bb5f37f5cb..8f5b3302ee30 100644
--- a/drivers/memory/atmel-ebi.c
+++ b/drivers/memory/atmel-ebi.c
@@ -6,6 +6,7 @@
  * Copyright (C) 2013 Jean-Jacques Hiblot <jjhiblot@traphandler.com>
  */
 
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/mfd/syscon.h>
@@ -517,7 +518,7 @@ static int atmel_ebi_dev_disable(struct atmel_ebi *ebi, struct device_node *np)
 static int atmel_ebi_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *child, *np = dev->of_node, *smc_np;
+	struct device_node *child, *np = dev->of_node;
 	struct atmel_ebi *ebi;
 	int ret, reg_cells;
 	struct clk *clk;
@@ -541,30 +542,24 @@ static int atmel_ebi_probe(struct platform_device *pdev)
 
 	ebi->clk = clk;
 
-	smc_np = of_parse_phandle(dev->of_node, "atmel,smc", 0);
+	struct device_node *smc_np __free(device_node) =
+		of_parse_phandle(dev->of_node, "atmel,smc", 0);
 
 	ebi->smc.regmap = syscon_node_to_regmap(smc_np);
-	if (IS_ERR(ebi->smc.regmap)) {
-		ret = PTR_ERR(ebi->smc.regmap);
-		goto put_node;
-	}
+	if (IS_ERR(ebi->smc.regmap))
+		return PTR_ERR(ebi->smc.regmap);
 
 	ebi->smc.layout = atmel_hsmc_get_reg_layout(smc_np);
-	if (IS_ERR(ebi->smc.layout)) {
-		ret = PTR_ERR(ebi->smc.layout);
-		goto put_node;
-	}
+	if (IS_ERR(ebi->smc.layout))
+		return PTR_ERR(ebi->smc.layout);
 
 	ebi->smc.clk = of_clk_get(smc_np, 0);
 	if (IS_ERR(ebi->smc.clk)) {
-		if (PTR_ERR(ebi->smc.clk) != -ENOENT) {
-			ret = PTR_ERR(ebi->smc.clk);
-			goto put_node;
-		}
+		if (PTR_ERR(ebi->smc.clk) != -ENOENT)
+			return PTR_ERR(ebi->smc.clk);
 
 		ebi->smc.clk = NULL;
 	}
-	of_node_put(smc_np);
 	ret = clk_prepare_enable(ebi->smc.clk);
 	if (ret)
 		return ret;
@@ -615,10 +610,6 @@ static int atmel_ebi_probe(struct platform_device *pdev)
 	}
 
 	return of_platform_populate(np, NULL, NULL, dev);
-
-put_node:
-	of_node_put(smc_np);
-	return ret;
 }
 
 static __maybe_unused int atmel_ebi_resume(struct device *dev)

-- 
2.43.0



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

* [PATCH v2 02/13] memory: atmel-ebi: simplify with scoped for each OF child loop
  2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
  2024-08-16 10:54 ` [PATCH v2 01/13] memory: atmel-ebi: use scoped device node handling to simplify error paths Krzysztof Kozlowski
@ 2024-08-16 10:54 ` Krzysztof Kozlowski
  2024-08-27 10:30   ` Nicolas Ferre
  2024-08-16 10:54 ` [PATCH v2 03/13] memory: samsung: exynos5422-dmc: simplify dmc->dev usage Krzysztof Kozlowski
                   ` (11 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Jonathan Cameron, Krzysztof Kozlowski

Use scoped for_each_available_child_of_node_scoped() when iterating over
device nodes to make code a bit simpler.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/memory/atmel-ebi.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/memory/atmel-ebi.c b/drivers/memory/atmel-ebi.c
index 8f5b3302ee30..8db970da9af9 100644
--- a/drivers/memory/atmel-ebi.c
+++ b/drivers/memory/atmel-ebi.c
@@ -518,7 +518,7 @@ static int atmel_ebi_dev_disable(struct atmel_ebi *ebi, struct device_node *np)
 static int atmel_ebi_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *child, *np = dev->of_node;
+	struct device_node *np = dev->of_node;
 	struct atmel_ebi *ebi;
 	int ret, reg_cells;
 	struct clk *clk;
@@ -592,7 +592,7 @@ static int atmel_ebi_probe(struct platform_device *pdev)
 
 	reg_cells += val;
 
-	for_each_available_child_of_node(np, child) {
+	for_each_available_child_of_node_scoped(np, child) {
 		if (!of_property_present(child, "reg"))
 			continue;
 
@@ -602,10 +602,8 @@ static int atmel_ebi_probe(struct platform_device *pdev)
 				child);
 
 			ret = atmel_ebi_dev_disable(ebi, child);
-			if (ret) {
-				of_node_put(child);
+			if (ret)
 				return ret;
-			}
 		}
 	}
 

-- 
2.43.0



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

* [PATCH v2 03/13] memory: samsung: exynos5422-dmc: simplify dmc->dev usage
  2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
  2024-08-16 10:54 ` [PATCH v2 01/13] memory: atmel-ebi: use scoped device node handling to simplify error paths Krzysztof Kozlowski
  2024-08-16 10:54 ` [PATCH v2 02/13] memory: atmel-ebi: simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-16 10:54 ` Krzysztof Kozlowski
  2024-08-19 16:03   ` Jonathan Cameron
  2024-08-16 10:54 ` [PATCH v2 04/13] memory: samsung: exynos5422-dmc: use scoped device node handling to simplify error paths Krzysztof Kozlowski
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Krzysztof Kozlowski

Store 'dmc->dev' in local 'dev' variable, to make several pieces of code
using it shorter and easier to read.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/memory/samsung/exynos5422-dmc.c | 61 +++++++++++++++++----------------
 1 file changed, 31 insertions(+), 30 deletions(-)

diff --git a/drivers/memory/samsung/exynos5422-dmc.c b/drivers/memory/samsung/exynos5422-dmc.c
index da7ecd921c72..48ef41b8eaa0 100644
--- a/drivers/memory/samsung/exynos5422-dmc.c
+++ b/drivers/memory/samsung/exynos5422-dmc.c
@@ -339,19 +339,20 @@ static int exynos5_switch_timing_regs(struct exynos5_dmc *dmc, bool set)
 static int exynos5_init_freq_table(struct exynos5_dmc *dmc,
 				   struct devfreq_dev_profile *profile)
 {
+	struct device *dev = dmc->dev;
 	int i, ret;
 	int idx;
 	unsigned long freq;
 
-	ret = devm_pm_opp_of_add_table(dmc->dev);
+	ret = devm_pm_opp_of_add_table(dev);
 	if (ret < 0) {
-		dev_err(dmc->dev, "Failed to get OPP table\n");
+		dev_err(dev, "Failed to get OPP table\n");
 		return ret;
 	}
 
-	dmc->opp_count = dev_pm_opp_get_opp_count(dmc->dev);
+	dmc->opp_count = dev_pm_opp_get_opp_count(dev);
 
-	dmc->opp = devm_kmalloc_array(dmc->dev, dmc->opp_count,
+	dmc->opp = devm_kmalloc_array(dev, dmc->opp_count,
 				      sizeof(struct dmc_opp_table), GFP_KERNEL);
 	if (!dmc->opp)
 		return -ENOMEM;
@@ -360,7 +361,7 @@ static int exynos5_init_freq_table(struct exynos5_dmc *dmc,
 	for (i = 0, freq = ULONG_MAX; i < dmc->opp_count; i++, freq--) {
 		struct dev_pm_opp *opp;
 
-		opp = dev_pm_opp_find_freq_floor(dmc->dev, &freq);
+		opp = dev_pm_opp_find_freq_floor(dev, &freq);
 		if (IS_ERR(opp))
 			return PTR_ERR(opp);
 
@@ -1175,49 +1176,50 @@ static int create_timings_aligned(struct exynos5_dmc *dmc, u32 *reg_timing_row,
 static int of_get_dram_timings(struct exynos5_dmc *dmc)
 {
 	int ret = 0;
+	struct device *dev = dmc->dev;
 	int idx;
 	struct device_node *np_ddr;
 	u32 freq_mhz, clk_period_ps;
 
-	np_ddr = of_parse_phandle(dmc->dev->of_node, "device-handle", 0);
+	np_ddr = of_parse_phandle(dev->of_node, "device-handle", 0);
 	if (!np_ddr) {
-		dev_warn(dmc->dev, "could not find 'device-handle' in DT\n");
+		dev_warn(dev, "could not find 'device-handle' in DT\n");
 		return -EINVAL;
 	}
 
-	dmc->timing_row = devm_kmalloc_array(dmc->dev, TIMING_COUNT,
+	dmc->timing_row = devm_kmalloc_array(dev, TIMING_COUNT,
 					     sizeof(u32), GFP_KERNEL);
 	if (!dmc->timing_row) {
 		ret = -ENOMEM;
 		goto put_node;
 	}
 
-	dmc->timing_data = devm_kmalloc_array(dmc->dev, TIMING_COUNT,
+	dmc->timing_data = devm_kmalloc_array(dev, TIMING_COUNT,
 					      sizeof(u32), GFP_KERNEL);
 	if (!dmc->timing_data) {
 		ret = -ENOMEM;
 		goto put_node;
 	}
 
-	dmc->timing_power = devm_kmalloc_array(dmc->dev, TIMING_COUNT,
+	dmc->timing_power = devm_kmalloc_array(dev, TIMING_COUNT,
 					       sizeof(u32), GFP_KERNEL);
 	if (!dmc->timing_power) {
 		ret = -ENOMEM;
 		goto put_node;
 	}
 
-	dmc->timings = of_lpddr3_get_ddr_timings(np_ddr, dmc->dev,
+	dmc->timings = of_lpddr3_get_ddr_timings(np_ddr, dev,
 						 DDR_TYPE_LPDDR3,
 						 &dmc->timings_arr_size);
 	if (!dmc->timings) {
-		dev_warn(dmc->dev, "could not get timings from DT\n");
+		dev_warn(dev, "could not get timings from DT\n");
 		ret = -EINVAL;
 		goto put_node;
 	}
 
-	dmc->min_tck = of_lpddr3_get_min_tck(np_ddr, dmc->dev);
+	dmc->min_tck = of_lpddr3_get_min_tck(np_ddr, dev);
 	if (!dmc->min_tck) {
-		dev_warn(dmc->dev, "could not get tck from DT\n");
+		dev_warn(dev, "could not get tck from DT\n");
 		ret = -EINVAL;
 		goto put_node;
 	}
@@ -1254,34 +1256,34 @@ static int of_get_dram_timings(struct exynos5_dmc *dmc)
 static int exynos5_dmc_init_clks(struct exynos5_dmc *dmc)
 {
 	int ret;
+	struct device *dev = dmc->dev;
 	unsigned long target_volt = 0;
 	unsigned long target_rate = 0;
 	unsigned int tmp;
 
-	dmc->fout_spll = devm_clk_get(dmc->dev, "fout_spll");
+	dmc->fout_spll = devm_clk_get(dev, "fout_spll");
 	if (IS_ERR(dmc->fout_spll))
 		return PTR_ERR(dmc->fout_spll);
 
-	dmc->fout_bpll = devm_clk_get(dmc->dev, "fout_bpll");
+	dmc->fout_bpll = devm_clk_get(dev, "fout_bpll");
 	if (IS_ERR(dmc->fout_bpll))
 		return PTR_ERR(dmc->fout_bpll);
 
-	dmc->mout_mclk_cdrex = devm_clk_get(dmc->dev, "mout_mclk_cdrex");
+	dmc->mout_mclk_cdrex = devm_clk_get(dev, "mout_mclk_cdrex");
 	if (IS_ERR(dmc->mout_mclk_cdrex))
 		return PTR_ERR(dmc->mout_mclk_cdrex);
 
-	dmc->mout_bpll = devm_clk_get(dmc->dev, "mout_bpll");
+	dmc->mout_bpll = devm_clk_get(dev, "mout_bpll");
 	if (IS_ERR(dmc->mout_bpll))
 		return PTR_ERR(dmc->mout_bpll);
 
-	dmc->mout_mx_mspll_ccore = devm_clk_get(dmc->dev,
-						"mout_mx_mspll_ccore");
+	dmc->mout_mx_mspll_ccore = devm_clk_get(dev, "mout_mx_mspll_ccore");
 	if (IS_ERR(dmc->mout_mx_mspll_ccore))
 		return PTR_ERR(dmc->mout_mx_mspll_ccore);
 
-	dmc->mout_spll = devm_clk_get(dmc->dev, "ff_dout_spll2");
+	dmc->mout_spll = devm_clk_get(dev, "ff_dout_spll2");
 	if (IS_ERR(dmc->mout_spll)) {
-		dmc->mout_spll = devm_clk_get(dmc->dev, "mout_sclk_spll");
+		dmc->mout_spll = devm_clk_get(dev, "mout_sclk_spll");
 		if (IS_ERR(dmc->mout_spll))
 			return PTR_ERR(dmc->mout_spll);
 	}
@@ -1329,38 +1331,37 @@ static int exynos5_dmc_init_clks(struct exynos5_dmc *dmc)
  */
 static int exynos5_performance_counters_init(struct exynos5_dmc *dmc)
 {
+	struct device *dev = dmc->dev;
 	int ret, i;
 
-	dmc->num_counters = devfreq_event_get_edev_count(dmc->dev,
-							"devfreq-events");
+	dmc->num_counters = devfreq_event_get_edev_count(dev, "devfreq-events");
 	if (dmc->num_counters < 0) {
-		dev_err(dmc->dev, "could not get devfreq-event counters\n");
+		dev_err(dev, "could not get devfreq-event counters\n");
 		return dmc->num_counters;
 	}
 
-	dmc->counter = devm_kcalloc(dmc->dev, dmc->num_counters,
+	dmc->counter = devm_kcalloc(dev, dmc->num_counters,
 				    sizeof(*dmc->counter), GFP_KERNEL);
 	if (!dmc->counter)
 		return -ENOMEM;
 
 	for (i = 0; i < dmc->num_counters; i++) {
 		dmc->counter[i] =
-			devfreq_event_get_edev_by_phandle(dmc->dev,
-						"devfreq-events", i);
+			devfreq_event_get_edev_by_phandle(dev, "devfreq-events", i);
 		if (IS_ERR_OR_NULL(dmc->counter[i]))
 			return -EPROBE_DEFER;
 	}
 
 	ret = exynos5_counters_enable_edev(dmc);
 	if (ret < 0) {
-		dev_err(dmc->dev, "could not enable event counter\n");
+		dev_err(dev, "could not enable event counter\n");
 		return ret;
 	}
 
 	ret = exynos5_counters_set_event(dmc);
 	if (ret < 0) {
 		exynos5_counters_disable_edev(dmc);
-		dev_err(dmc->dev, "could not set event counter\n");
+		dev_err(dev, "could not set event counter\n");
 		return ret;
 	}
 

-- 
2.43.0



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

* [PATCH v2 04/13] memory: samsung: exynos5422-dmc: use scoped device node handling to simplify error paths
  2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
                   ` (2 preceding siblings ...)
  2024-08-16 10:54 ` [PATCH v2 03/13] memory: samsung: exynos5422-dmc: simplify dmc->dev usage Krzysztof Kozlowski
@ 2024-08-16 10:54 ` Krzysztof Kozlowski
  2024-08-16 10:54 ` [PATCH v2 05/13] memory: stm32-fmc2-ebi: simplify with scoped for each OF child loop Krzysztof Kozlowski
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Jonathan Cameron, Krzysztof Kozlowski

Obtain the device node reference with scoped/cleanup.h to reduce error
handling and make the code a bit simpler.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

---

Changes in v2:
1. Wrap line before of_parse_phandle()
---
 drivers/memory/samsung/exynos5422-dmc.c | 31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/drivers/memory/samsung/exynos5422-dmc.c b/drivers/memory/samsung/exynos5422-dmc.c
index 48ef41b8eaa0..7d80322754fa 100644
--- a/drivers/memory/samsung/exynos5422-dmc.c
+++ b/drivers/memory/samsung/exynos5422-dmc.c
@@ -4,6 +4,7 @@
  * Author: Lukasz Luba <l.luba@partner.samsung.com>
  */
 
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/devfreq.h>
 #include <linux/devfreq-event.h>
@@ -1178,10 +1179,10 @@ static int of_get_dram_timings(struct exynos5_dmc *dmc)
 	int ret = 0;
 	struct device *dev = dmc->dev;
 	int idx;
-	struct device_node *np_ddr;
 	u32 freq_mhz, clk_period_ps;
 
-	np_ddr = of_parse_phandle(dev->of_node, "device-handle", 0);
+	struct device_node *np_ddr __free(device_node) =
+		of_parse_phandle(dev->of_node, "device-handle", 0);
 	if (!np_ddr) {
 		dev_warn(dev, "could not find 'device-handle' in DT\n");
 		return -EINVAL;
@@ -1189,39 +1190,31 @@ static int of_get_dram_timings(struct exynos5_dmc *dmc)
 
 	dmc->timing_row = devm_kmalloc_array(dev, TIMING_COUNT,
 					     sizeof(u32), GFP_KERNEL);
-	if (!dmc->timing_row) {
-		ret = -ENOMEM;
-		goto put_node;
-	}
+	if (!dmc->timing_row)
+		return -ENOMEM;
 
 	dmc->timing_data = devm_kmalloc_array(dev, TIMING_COUNT,
 					      sizeof(u32), GFP_KERNEL);
-	if (!dmc->timing_data) {
-		ret = -ENOMEM;
-		goto put_node;
-	}
+	if (!dmc->timing_data)
+		return -ENOMEM;
 
 	dmc->timing_power = devm_kmalloc_array(dev, TIMING_COUNT,
 					       sizeof(u32), GFP_KERNEL);
-	if (!dmc->timing_power) {
-		ret = -ENOMEM;
-		goto put_node;
-	}
+	if (!dmc->timing_power)
+		return -ENOMEM;
 
 	dmc->timings = of_lpddr3_get_ddr_timings(np_ddr, dev,
 						 DDR_TYPE_LPDDR3,
 						 &dmc->timings_arr_size);
 	if (!dmc->timings) {
 		dev_warn(dev, "could not get timings from DT\n");
-		ret = -EINVAL;
-		goto put_node;
+		return -EINVAL;
 	}
 
 	dmc->min_tck = of_lpddr3_get_min_tck(np_ddr, dev);
 	if (!dmc->min_tck) {
 		dev_warn(dev, "could not get tck from DT\n");
-		ret = -EINVAL;
-		goto put_node;
+		return -EINVAL;
 	}
 
 	/* Sorted array of OPPs with frequency ascending */
@@ -1241,8 +1234,6 @@ static int of_get_dram_timings(struct exynos5_dmc *dmc)
 	dmc->bypass_timing_data = dmc->timing_data[idx - 1];
 	dmc->bypass_timing_power = dmc->timing_power[idx - 1];
 
-put_node:
-	of_node_put(np_ddr);
 	return ret;
 }
 

-- 
2.43.0



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

* [PATCH v2 05/13] memory: stm32-fmc2-ebi: simplify with scoped for each OF child loop
  2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
                   ` (3 preceding siblings ...)
  2024-08-16 10:54 ` [PATCH v2 04/13] memory: samsung: exynos5422-dmc: use scoped device node handling to simplify error paths Krzysztof Kozlowski
@ 2024-08-16 10:54 ` Krzysztof Kozlowski
  2024-08-16 10:54 ` [PATCH v2 06/13] memory: stm32-fmc2-ebi: simplify with dev_err_probe() Krzysztof Kozlowski
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Jonathan Cameron, Krzysztof Kozlowski

Use scoped for_each_available_child_of_node_scoped() when iterating over
device nodes to make code a bit simpler.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/memory/stm32-fmc2-ebi.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/memory/stm32-fmc2-ebi.c b/drivers/memory/stm32-fmc2-ebi.c
index 1c63eeacd071..7167e1da56d3 100644
--- a/drivers/memory/stm32-fmc2-ebi.c
+++ b/drivers/memory/stm32-fmc2-ebi.c
@@ -1573,29 +1573,25 @@ static int stm32_fmc2_ebi_setup_cs(struct stm32_fmc2_ebi *ebi,
 static int stm32_fmc2_ebi_parse_dt(struct stm32_fmc2_ebi *ebi)
 {
 	struct device *dev = ebi->dev;
-	struct device_node *child;
 	bool child_found = false;
 	u32 bank;
 	int ret;
 
-	for_each_available_child_of_node(dev->of_node, child) {
+	for_each_available_child_of_node_scoped(dev->of_node, child) {
 		ret = of_property_read_u32(child, "reg", &bank);
 		if (ret) {
 			dev_err(dev, "could not retrieve reg property: %d\n",
 				ret);
-			of_node_put(child);
 			return ret;
 		}
 
 		if (bank >= FMC2_MAX_BANKS) {
 			dev_err(dev, "invalid reg value: %d\n", bank);
-			of_node_put(child);
 			return -EINVAL;
 		}
 
 		if (ebi->bank_assigned & BIT(bank)) {
 			dev_err(dev, "bank already assigned: %d\n", bank);
-			of_node_put(child);
 			return -EINVAL;
 		}
 
@@ -1603,7 +1599,6 @@ static int stm32_fmc2_ebi_parse_dt(struct stm32_fmc2_ebi *ebi)
 			ret = ebi->data->check_rif(ebi, bank + 1);
 			if (ret) {
 				dev_err(dev, "bank access failed: %d\n", bank);
-				of_node_put(child);
 				return ret;
 			}
 		}
@@ -1613,7 +1608,6 @@ static int stm32_fmc2_ebi_parse_dt(struct stm32_fmc2_ebi *ebi)
 			if (ret) {
 				dev_err(dev, "setup chip select %d failed: %d\n",
 					bank, ret);
-				of_node_put(child);
 				return ret;
 			}
 		}

-- 
2.43.0



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

* [PATCH v2 06/13] memory: stm32-fmc2-ebi: simplify with dev_err_probe()
  2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
                   ` (4 preceding siblings ...)
  2024-08-16 10:54 ` [PATCH v2 05/13] memory: stm32-fmc2-ebi: simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-16 10:54 ` Krzysztof Kozlowski
  2024-08-19 16:02   ` Jonathan Cameron
  2024-08-16 10:54 ` [PATCH v2 07/13] memory: tegra-mc: simplify with scoped for each OF child loop Krzysztof Kozlowski
                   ` (7 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Jonathan Cameron, Krzysztof Kozlowski

dev_err_probe() combines 'return' and error code printing, thus code is
a bit simpler, even if it cannot actually defer.

Suggested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

---

Changes in v2:
1. New patch
---
 drivers/memory/stm32-fmc2-ebi.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/memory/stm32-fmc2-ebi.c b/drivers/memory/stm32-fmc2-ebi.c
index 7167e1da56d3..566c225f71c0 100644
--- a/drivers/memory/stm32-fmc2-ebi.c
+++ b/drivers/memory/stm32-fmc2-ebi.c
@@ -1579,11 +1579,8 @@ static int stm32_fmc2_ebi_parse_dt(struct stm32_fmc2_ebi *ebi)
 
 	for_each_available_child_of_node_scoped(dev->of_node, child) {
 		ret = of_property_read_u32(child, "reg", &bank);
-		if (ret) {
-			dev_err(dev, "could not retrieve reg property: %d\n",
-				ret);
-			return ret;
-		}
+		if (ret)
+			return dev_err_probe(dev, ret, "could not retrieve reg property\n");
 
 		if (bank >= FMC2_MAX_BANKS) {
 			dev_err(dev, "invalid reg value: %d\n", bank);
@@ -1605,11 +1602,9 @@ static int stm32_fmc2_ebi_parse_dt(struct stm32_fmc2_ebi *ebi)
 
 		if (bank < FMC2_MAX_EBI_CE) {
 			ret = stm32_fmc2_ebi_setup_cs(ebi, child, bank);
-			if (ret) {
-				dev_err(dev, "setup chip select %d failed: %d\n",
-					bank, ret);
-				return ret;
-			}
+			if (ret)
+				return dev_err_probe(dev, ret,
+						     "setup chip select %d failed\n", bank);
 		}
 
 		ebi->bank_assigned |= BIT(bank);

-- 
2.43.0



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

* [PATCH v2 07/13] memory: tegra-mc: simplify with scoped for each OF child loop
  2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
                   ` (5 preceding siblings ...)
  2024-08-16 10:54 ` [PATCH v2 06/13] memory: stm32-fmc2-ebi: simplify with dev_err_probe() Krzysztof Kozlowski
@ 2024-08-16 10:54 ` Krzysztof Kozlowski
  2024-08-27  9:10   ` Thierry Reding
  2024-08-16 10:54 ` [PATCH v2 08/13] memory: tegra124-emc: " Krzysztof Kozlowski
                   ` (6 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Jonathan Cameron, Krzysztof Kozlowski

Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/memory/tegra/mc.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/memory/tegra/mc.c b/drivers/memory/tegra/mc.c
index 224b488794e5..bd5b58f1fd42 100644
--- a/drivers/memory/tegra/mc.c
+++ b/drivers/memory/tegra/mc.c
@@ -450,7 +450,6 @@ static int load_one_timing(struct tegra_mc *mc,
 
 static int load_timings(struct tegra_mc *mc, struct device_node *node)
 {
-	struct device_node *child;
 	struct tegra_mc_timing *timing;
 	int child_count = of_get_child_count(node);
 	int i = 0, err;
@@ -462,14 +461,12 @@ static int load_timings(struct tegra_mc *mc, struct device_node *node)
 
 	mc->num_timings = child_count;
 
-	for_each_child_of_node(node, child) {
+	for_each_child_of_node_scoped(node, child) {
 		timing = &mc->timings[i++];
 
 		err = load_one_timing(mc, timing, child);
-		if (err) {
-			of_node_put(child);
+		if (err)
 			return err;
-		}
 	}
 
 	return 0;
@@ -477,7 +474,6 @@ static int load_timings(struct tegra_mc *mc, struct device_node *node)
 
 static int tegra_mc_setup_timings(struct tegra_mc *mc)
 {
-	struct device_node *node;
 	u32 ram_code, node_ram_code;
 	int err;
 
@@ -485,14 +481,13 @@ static int tegra_mc_setup_timings(struct tegra_mc *mc)
 
 	mc->num_timings = 0;
 
-	for_each_child_of_node(mc->dev->of_node, node) {
+	for_each_child_of_node_scoped(mc->dev->of_node, node) {
 		err = of_property_read_u32(node, "nvidia,ram-code",
 					   &node_ram_code);
 		if (err || (node_ram_code != ram_code))
 			continue;
 
 		err = load_timings(mc, node);
-		of_node_put(node);
 		if (err)
 			return err;
 		break;

-- 
2.43.0



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

* [PATCH v2 08/13] memory: tegra124-emc: simplify with scoped for each OF child loop
  2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
                   ` (6 preceding siblings ...)
  2024-08-16 10:54 ` [PATCH v2 07/13] memory: tegra-mc: simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-16 10:54 ` Krzysztof Kozlowski
  2024-08-27  9:11   ` Thierry Reding
  2024-08-16 10:54 ` [PATCH v2 09/13] memory: tegra20-emc: " Krzysztof Kozlowski
                   ` (5 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Jonathan Cameron, Krzysztof Kozlowski

Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/memory/tegra/tegra124-emc.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/memory/tegra/tegra124-emc.c b/drivers/memory/tegra/tegra124-emc.c
index 47c0c19e13fd..03f1daa2d132 100644
--- a/drivers/memory/tegra/tegra124-emc.c
+++ b/drivers/memory/tegra/tegra124-emc.c
@@ -992,7 +992,6 @@ static int tegra_emc_load_timings_from_dt(struct tegra_emc *emc,
 					  struct device_node *node)
 {
 	int child_count = of_get_child_count(node);
-	struct device_node *child;
 	struct emc_timing *timing;
 	unsigned int i = 0;
 	int err;
@@ -1004,14 +1003,12 @@ static int tegra_emc_load_timings_from_dt(struct tegra_emc *emc,
 
 	emc->num_timings = child_count;
 
-	for_each_child_of_node(node, child) {
+	for_each_child_of_node_scoped(node, child) {
 		timing = &emc->timings[i++];
 
 		err = load_one_timing_from_dt(emc, timing, child);
-		if (err) {
-			of_node_put(child);
+		if (err)
 			return err;
-		}
 	}
 
 	sort(emc->timings, emc->num_timings, sizeof(*timing), cmp_timings,

-- 
2.43.0



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

* [PATCH v2 09/13] memory: tegra20-emc: simplify with scoped for each OF child loop
  2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
                   ` (7 preceding siblings ...)
  2024-08-16 10:54 ` [PATCH v2 08/13] memory: tegra124-emc: " Krzysztof Kozlowski
@ 2024-08-16 10:54 ` Krzysztof Kozlowski
  2024-08-27  9:11   ` Thierry Reding
  2024-08-16 10:54 ` [PATCH v2 10/13] memory: tegra30-emc: " Krzysztof Kozlowski
                   ` (4 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Jonathan Cameron, Krzysztof Kozlowski

Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/memory/tegra/tegra20-emc.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/memory/tegra/tegra20-emc.c b/drivers/memory/tegra/tegra20-emc.c
index 97cf59523b0b..7193f848d17e 100644
--- a/drivers/memory/tegra/tegra20-emc.c
+++ b/drivers/memory/tegra/tegra20-emc.c
@@ -410,7 +410,6 @@ static int cmp_timings(const void *_a, const void *_b)
 static int tegra_emc_load_timings_from_dt(struct tegra_emc *emc,
 					  struct device_node *node)
 {
-	struct device_node *child;
 	struct emc_timing *timing;
 	int child_count;
 	int err;
@@ -428,15 +427,13 @@ static int tegra_emc_load_timings_from_dt(struct tegra_emc *emc,
 
 	timing = emc->timings;
 
-	for_each_child_of_node(node, child) {
+	for_each_child_of_node_scoped(node, child) {
 		if (of_node_name_eq(child, "lpddr2"))
 			continue;
 
 		err = load_one_timing_from_dt(emc, timing++, child);
-		if (err) {
-			of_node_put(child);
+		if (err)
 			return err;
-		}
 
 		emc->num_timings++;
 	}

-- 
2.43.0



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

* [PATCH v2 10/13] memory: tegra30-emc: simplify with scoped for each OF child loop
  2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
                   ` (8 preceding siblings ...)
  2024-08-16 10:54 ` [PATCH v2 09/13] memory: tegra20-emc: " Krzysztof Kozlowski
@ 2024-08-16 10:54 ` Krzysztof Kozlowski
  2024-08-19 16:01   ` Jonathan Cameron
  2024-08-27  9:11   ` Thierry Reding
  2024-08-16 10:54 ` [PATCH v2 11/13] memory: ti-aemif: simplify with dev_err_probe() Krzysztof Kozlowski
                   ` (3 subsequent siblings)
  13 siblings, 2 replies; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Krzysztof Kozlowski

Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/memory/tegra/tegra30-emc.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/memory/tegra/tegra30-emc.c b/drivers/memory/tegra/tegra30-emc.c
index d7b0a23c2d7d..921dce1b8bc6 100644
--- a/drivers/memory/tegra/tegra30-emc.c
+++ b/drivers/memory/tegra/tegra30-emc.c
@@ -979,7 +979,6 @@ static int emc_check_mc_timings(struct tegra_emc *emc)
 static int emc_load_timings_from_dt(struct tegra_emc *emc,
 				    struct device_node *node)
 {
-	struct device_node *child;
 	struct emc_timing *timing;
 	int child_count;
 	int err;
@@ -998,12 +997,10 @@ static int emc_load_timings_from_dt(struct tegra_emc *emc,
 	emc->num_timings = child_count;
 	timing = emc->timings;
 
-	for_each_child_of_node(node, child) {
+	for_each_child_of_node_scoped(node, child) {
 		err = load_one_timing_from_dt(emc, timing++, child);
-		if (err) {
-			of_node_put(child);
+		if (err)
 			return err;
-		}
 	}
 
 	sort(emc->timings, emc->num_timings, sizeof(*timing), cmp_timings,

-- 
2.43.0



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

* [PATCH v2 11/13] memory: ti-aemif: simplify with dev_err_probe()
  2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
                   ` (9 preceding siblings ...)
  2024-08-16 10:54 ` [PATCH v2 10/13] memory: tegra30-emc: " Krzysztof Kozlowski
@ 2024-08-16 10:54 ` Krzysztof Kozlowski
  2024-08-19 16:00   ` Jonathan Cameron
  2024-08-16 10:54 ` [PATCH v2 12/13] memory: ti-aemif: simplify with devm_clk_get_enabled() Krzysztof Kozlowski
                   ` (2 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Krzysztof Kozlowski

Use dev_err_probe() to avoid dmesg flood on actual defer.  This makes
the code also simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

---

Changes in v2:
1. New patch
---
 drivers/memory/ti-aemif.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/memory/ti-aemif.c b/drivers/memory/ti-aemif.c
index e192db9e0e4b..360f2705b1ff 100644
--- a/drivers/memory/ti-aemif.c
+++ b/drivers/memory/ti-aemif.c
@@ -345,10 +345,8 @@ static int aemif_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, aemif);
 
 	aemif->clk = devm_clk_get(dev, NULL);
-	if (IS_ERR(aemif->clk)) {
-		dev_err(dev, "cannot get clock 'aemif'\n");
-		return PTR_ERR(aemif->clk);
-	}
+	if (IS_ERR(aemif->clk))
+		return dev_err_probe(dev, PTR_ERR(aemif->clk), "cannot get clock 'aemif'\n");
 
 	ret = clk_prepare_enable(aemif->clk);
 	if (ret)

-- 
2.43.0



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

* [PATCH v2 12/13] memory: ti-aemif: simplify with devm_clk_get_enabled()
  2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
                   ` (10 preceding siblings ...)
  2024-08-16 10:54 ` [PATCH v2 11/13] memory: ti-aemif: simplify with dev_err_probe() Krzysztof Kozlowski
@ 2024-08-16 10:54 ` Krzysztof Kozlowski
  2024-08-19 15:59   ` Jonathan Cameron
  2024-08-16 10:54 ` [PATCH v2 13/13] memory: ti-aemif: simplify with scoped for each OF child loop Krzysztof Kozlowski
  2024-08-21 11:41 ` [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
  13 siblings, 1 reply; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Jonathan Cameron, Krzysztof Kozlowski

Use devm_clk_get_enabled() to drop clock prepare/unprepare parts and
make code simpler.

Suggested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

---

Changes in v2:
1. New patch
---
 drivers/memory/ti-aemif.c | 29 ++++++-----------------------
 1 file changed, 6 insertions(+), 23 deletions(-)

diff --git a/drivers/memory/ti-aemif.c b/drivers/memory/ti-aemif.c
index 360f2705b1ff..bb9c8132d8c0 100644
--- a/drivers/memory/ti-aemif.c
+++ b/drivers/memory/ti-aemif.c
@@ -344,14 +344,10 @@ static int aemif_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, aemif);
 
-	aemif->clk = devm_clk_get(dev, NULL);
+	aemif->clk = devm_clk_get_enabled(dev, NULL);
 	if (IS_ERR(aemif->clk))
 		return dev_err_probe(dev, PTR_ERR(aemif->clk), "cannot get clock 'aemif'\n");
 
-	ret = clk_prepare_enable(aemif->clk);
-	if (ret)
-		return ret;
-
 	aemif->clk_rate = clk_get_rate(aemif->clk) / MSEC_PER_SEC;
 
 	if (np && of_device_is_compatible(np, "ti,da850-aemif"))
@@ -360,10 +356,8 @@ static int aemif_probe(struct platform_device *pdev)
 		aemif->cs_offset = pdata->cs_offset;
 
 	aemif->base = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(aemif->base)) {
-		ret = PTR_ERR(aemif->base);
-		goto error;
-	}
+	if (IS_ERR(aemif->base))
+		return PTR_ERR(aemif->base);
 
 	if (np) {
 		/*
@@ -376,7 +370,7 @@ static int aemif_probe(struct platform_device *pdev)
 			ret = of_aemif_parse_abus_config(pdev, child_np);
 			if (ret < 0) {
 				of_node_put(child_np);
-				goto error;
+				return ret;
 			}
 		}
 	} else if (pdata && pdata->num_abus_data > 0) {
@@ -391,7 +385,7 @@ static int aemif_probe(struct platform_device *pdev)
 		if (ret < 0) {
 			dev_err(dev, "Error configuring chip select %d\n",
 				aemif->cs_data[i].cs);
-			goto error;
+			return ret;
 		}
 	}
 
@@ -405,7 +399,7 @@ static int aemif_probe(struct platform_device *pdev)
 						   dev_lookup, dev);
 			if (ret < 0) {
 				of_node_put(child_np);
-				goto error;
+				return ret;
 			}
 		}
 	} else if (pdata) {
@@ -420,21 +414,10 @@ static int aemif_probe(struct platform_device *pdev)
 	}
 
 	return 0;
-error:
-	clk_disable_unprepare(aemif->clk);
-	return ret;
-}
-
-static void aemif_remove(struct platform_device *pdev)
-{
-	struct aemif_device *aemif = platform_get_drvdata(pdev);
-
-	clk_disable_unprepare(aemif->clk);
 }
 
 static struct platform_driver aemif_driver = {
 	.probe = aemif_probe,
-	.remove_new = aemif_remove,
 	.driver = {
 		.name = "ti-aemif",
 		.of_match_table = of_match_ptr(aemif_of_match),

-- 
2.43.0



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

* [PATCH v2 13/13] memory: ti-aemif: simplify with scoped for each OF child loop
  2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
                   ` (11 preceding siblings ...)
  2024-08-16 10:54 ` [PATCH v2 12/13] memory: ti-aemif: simplify with devm_clk_get_enabled() Krzysztof Kozlowski
@ 2024-08-16 10:54 ` Krzysztof Kozlowski
  2024-08-19 15:58   ` Jonathan Cameron
  2024-08-21 11:41 ` [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
  13 siblings, 1 reply; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Krzysztof Kozlowski

Use scoped for_each_available_child_of_node_scoped() when iterating over
device nodes to make code a bit simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/memory/ti-aemif.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/memory/ti-aemif.c b/drivers/memory/ti-aemif.c
index bb9c8132d8c0..7b48303f183b 100644
--- a/drivers/memory/ti-aemif.c
+++ b/drivers/memory/ti-aemif.c
@@ -330,7 +330,6 @@ static int aemif_probe(struct platform_device *pdev)
 	int ret = -ENODEV;
 	struct device *dev = &pdev->dev;
 	struct device_node *np = dev->of_node;
-	struct device_node *child_np;
 	struct aemif_device *aemif;
 	struct aemif_platform_data *pdata;
 	struct of_dev_auxdata *dev_lookup;
@@ -366,12 +365,10 @@ static int aemif_probe(struct platform_device *pdev)
 		 * functions iterate over these nodes and update the cs data
 		 * array.
 		 */
-		for_each_available_child_of_node(np, child_np) {
+		for_each_available_child_of_node_scoped(np, child_np) {
 			ret = of_aemif_parse_abus_config(pdev, child_np);
-			if (ret < 0) {
-				of_node_put(child_np);
+			if (ret < 0)
 				return ret;
-			}
 		}
 	} else if (pdata && pdata->num_abus_data > 0) {
 		for (i = 0; i < pdata->num_abus_data; i++, aemif->num_cs++) {
@@ -394,13 +391,11 @@ static int aemif_probe(struct platform_device *pdev)
 	 * child will be probed after the AEMIF timing parameters are set.
 	 */
 	if (np) {
-		for_each_available_child_of_node(np, child_np) {
+		for_each_available_child_of_node_scoped(np, child_np) {
 			ret = of_platform_populate(child_np, NULL,
 						   dev_lookup, dev);
-			if (ret < 0) {
-				of_node_put(child_np);
+			if (ret < 0)
 				return ret;
-			}
 		}
 	} else if (pdata) {
 		for (i = 0; i < pdata->num_sub_devices; i++) {

-- 
2.43.0



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

* Re: [PATCH v2 13/13] memory: ti-aemif: simplify with scoped for each OF child loop
  2024-08-16 10:54 ` [PATCH v2 13/13] memory: ti-aemif: simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-19 15:58   ` Jonathan Cameron
  0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2024-08-19 15:58 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Alexandre Belloni, linux-samsung-soc, Maxime Coquelin, linux-pm,
	Alexandre Torgue, linux-kernel, Krzysztof Kozlowski,
	Claudiu Beznea, Thierry Reding, linux-arm-kernel, Alim Akhtar,
	Santosh Shilimkar, linux-tegra, Jonathan Hunter, linux-stm32,
	Lukasz Luba

On Fri, 16 Aug 2024 12:54:37 +0200
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:

> Use scoped for_each_available_child_of_node_scoped() when iterating over
> device nodes to make code a bit simpler.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


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

* Re: [PATCH v2 12/13] memory: ti-aemif: simplify with devm_clk_get_enabled()
  2024-08-16 10:54 ` [PATCH v2 12/13] memory: ti-aemif: simplify with devm_clk_get_enabled() Krzysztof Kozlowski
@ 2024-08-19 15:59   ` Jonathan Cameron
  0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2024-08-19 15:59 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Alexandre Belloni, linux-samsung-soc, Maxime Coquelin, linux-pm,
	Alexandre Torgue, linux-kernel, Krzysztof Kozlowski,
	Claudiu Beznea, Thierry Reding, linux-arm-kernel, Alim Akhtar,
	Santosh Shilimkar, linux-tegra, Jonathan Hunter, linux-stm32,
	Lukasz Luba

On Fri, 16 Aug 2024 12:54:36 +0200
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:

> Use devm_clk_get_enabled() to drop clock prepare/unprepare parts and
> make code simpler.
> 
> Suggested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
LGTM
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


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

* Re: [PATCH v2 11/13] memory: ti-aemif: simplify with dev_err_probe()
  2024-08-16 10:54 ` [PATCH v2 11/13] memory: ti-aemif: simplify with dev_err_probe() Krzysztof Kozlowski
@ 2024-08-19 16:00   ` Jonathan Cameron
  0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2024-08-19 16:00 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Alexandre Belloni, linux-samsung-soc, Maxime Coquelin, linux-pm,
	Alexandre Torgue, linux-kernel, Krzysztof Kozlowski,
	Claudiu Beznea, Thierry Reding, linux-arm-kernel, Alim Akhtar,
	Santosh Shilimkar, linux-tegra, Jonathan Hunter, linux-stm32,
	Lukasz Luba

On Fri, 16 Aug 2024 12:54:35 +0200
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:

> Use dev_err_probe() to avoid dmesg flood on actual defer.  This makes
> the code also simpler.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> 
> ---
> 
> Changes in v2:
> 1. New patch
> ---
>  drivers/memory/ti-aemif.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/memory/ti-aemif.c b/drivers/memory/ti-aemif.c
> index e192db9e0e4b..360f2705b1ff 100644
> --- a/drivers/memory/ti-aemif.c
> +++ b/drivers/memory/ti-aemif.c
> @@ -345,10 +345,8 @@ static int aemif_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, aemif);
>  
>  	aemif->clk = devm_clk_get(dev, NULL);
> -	if (IS_ERR(aemif->clk)) {
> -		dev_err(dev, "cannot get clock 'aemif'\n");
> -		return PTR_ERR(aemif->clk);
> -	}
> +	if (IS_ERR(aemif->clk))
> +		return dev_err_probe(dev, PTR_ERR(aemif->clk), "cannot get clock 'aemif'\n");
Bit of a long line, so maybe wrap.  Up to maintainers

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

>  
>  	ret = clk_prepare_enable(aemif->clk);
>  	if (ret)
> 



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

* Re: [PATCH v2 10/13] memory: tegra30-emc: simplify with scoped for each OF child loop
  2024-08-16 10:54 ` [PATCH v2 10/13] memory: tegra30-emc: " Krzysztof Kozlowski
@ 2024-08-19 16:01   ` Jonathan Cameron
  2024-08-27  9:11   ` Thierry Reding
  1 sibling, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2024-08-19 16:01 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Alexandre Belloni, linux-samsung-soc, Maxime Coquelin, linux-pm,
	Alexandre Torgue, linux-kernel, Krzysztof Kozlowski,
	Claudiu Beznea, Thierry Reding, linux-arm-kernel, Alim Akhtar,
	Santosh Shilimkar, linux-tegra, Jonathan Hunter, linux-stm32,
	Lukasz Luba

On Fri, 16 Aug 2024 12:54:34 +0200
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:

> Use scoped for_each_child_of_node_scoped() when iterating over device
> nodes to make code a bit simpler.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


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

* Re: [PATCH v2 06/13] memory: stm32-fmc2-ebi: simplify with dev_err_probe()
  2024-08-16 10:54 ` [PATCH v2 06/13] memory: stm32-fmc2-ebi: simplify with dev_err_probe() Krzysztof Kozlowski
@ 2024-08-19 16:02   ` Jonathan Cameron
  0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2024-08-19 16:02 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Alexandre Belloni, linux-samsung-soc, Maxime Coquelin, linux-pm,
	Alexandre Torgue, linux-kernel, Krzysztof Kozlowski,
	Claudiu Beznea, Thierry Reding, linux-arm-kernel, Alim Akhtar,
	Santosh Shilimkar, linux-tegra, Jonathan Hunter, linux-stm32,
	Lukasz Luba

On Fri, 16 Aug 2024 12:54:30 +0200
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:

> dev_err_probe() combines 'return' and error code printing, thus code is
> a bit simpler, even if it cannot actually defer.
> 
> Suggested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
LGTM
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>



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

* Re: [PATCH v2 03/13] memory: samsung: exynos5422-dmc: simplify dmc->dev usage
  2024-08-16 10:54 ` [PATCH v2 03/13] memory: samsung: exynos5422-dmc: simplify dmc->dev usage Krzysztof Kozlowski
@ 2024-08-19 16:03   ` Jonathan Cameron
  0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2024-08-19 16:03 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Alexandre Belloni, linux-samsung-soc, Maxime Coquelin, linux-pm,
	Alexandre Torgue, linux-kernel, Krzysztof Kozlowski,
	Claudiu Beznea, Thierry Reding, linux-arm-kernel, Alim Akhtar,
	Santosh Shilimkar, linux-tegra, Jonathan Hunter, linux-stm32,
	Lukasz Luba

On Fri, 16 Aug 2024 12:54:27 +0200
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:

> Store 'dmc->dev' in local 'dev' variable, to make several pieces of code
> using it shorter and easier to read.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


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

* Re: [PATCH v2 01/13] memory: atmel-ebi: use scoped device node handling to simplify error paths
  2024-08-16 10:54 ` [PATCH v2 01/13] memory: atmel-ebi: use scoped device node handling to simplify error paths Krzysztof Kozlowski
@ 2024-08-19 16:04   ` Jonathan Cameron
  2024-08-27 10:35   ` Nicolas Ferre
  1 sibling, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2024-08-19 16:04 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Alexandre Belloni, linux-samsung-soc, Maxime Coquelin, linux-pm,
	Alexandre Torgue, linux-kernel, Krzysztof Kozlowski,
	Claudiu Beznea, Thierry Reding, linux-arm-kernel, Alim Akhtar,
	Santosh Shilimkar, linux-tegra, Jonathan Hunter, linux-stm32,
	Lukasz Luba

On Fri, 16 Aug 2024 12:54:25 +0200
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:

> Obtain the device node reference with scoped/cleanup.h to reduce error
> handling and make the code a bit simpler.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
I'm not entirely keen on the increased scope for which the reference
is held but doesn't really matter.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

>


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

* Re: [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes
  2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
                   ` (12 preceding siblings ...)
  2024-08-16 10:54 ` [PATCH v2 13/13] memory: ti-aemif: simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-21 11:41 ` Krzysztof Kozlowski
  2024-08-27  9:12   ` Thierry Reding
  13 siblings, 1 reply; 29+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-21 11:41 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Jonathan Cameron

On 16/08/2024 12:54, Krzysztof Kozlowski wrote:
> Changes in v2:
> - Add tags
> - Wrap lines before of_parse_phandle() (Jonathan)
> - Few new patches (see individual changelogs)
> - Link to v1: https://lore.kernel.org/r/20240812-cleanup-h-of-node-put-memory-v1-0-5065a8f361d2@linaro.org
> 
> Make code a bit simpler and smaller by using cleanup.h when handling
> device nodes.
> 
> Best regards,

Rebased (some changes around ti-aemif) and applied.

Best regards,
Krzysztof



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

* Re: [PATCH v2 07/13] memory: tegra-mc: simplify with scoped for each OF child loop
  2024-08-16 10:54 ` [PATCH v2 07/13] memory: tegra-mc: simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-27  9:10   ` Thierry Reding
  0 siblings, 0 replies; 29+ messages in thread
From: Thierry Reding @ 2024-08-27  9:10 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Alexandre Belloni, linux-samsung-soc, Maxime Coquelin, linux-pm,
	Alexandre Torgue, linux-kernel, Jonathan Cameron,
	Krzysztof Kozlowski, Claudiu Beznea, linux-arm-kernel,
	Alim Akhtar, Santosh Shilimkar, linux-tegra, Jonathan Hunter,
	linux-stm32, Lukasz Luba

[-- Attachment #1: Type: text/plain, Size: 471 bytes --]

On Fri, Aug 16, 2024 at 12:54:31PM GMT, Krzysztof Kozlowski wrote:
> Use scoped for_each_child_of_node_scoped() when iterating over device
> nodes to make code a bit simpler.
> 
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  drivers/memory/tegra/mc.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)

Acked-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 08/13] memory: tegra124-emc: simplify with scoped for each OF child loop
  2024-08-16 10:54 ` [PATCH v2 08/13] memory: tegra124-emc: " Krzysztof Kozlowski
@ 2024-08-27  9:11   ` Thierry Reding
  0 siblings, 0 replies; 29+ messages in thread
From: Thierry Reding @ 2024-08-27  9:11 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Alexandre Belloni, linux-samsung-soc, Maxime Coquelin, linux-pm,
	Alexandre Torgue, linux-kernel, Jonathan Cameron,
	Krzysztof Kozlowski, Claudiu Beznea, linux-arm-kernel,
	Alim Akhtar, Santosh Shilimkar, linux-tegra, Jonathan Hunter,
	linux-stm32, Lukasz Luba

[-- Attachment #1: Type: text/plain, Size: 476 bytes --]

On Fri, Aug 16, 2024 at 12:54:32PM GMT, Krzysztof Kozlowski wrote:
> Use scoped for_each_child_of_node_scoped() when iterating over device
> nodes to make code a bit simpler.
> 
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  drivers/memory/tegra/tegra124-emc.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)

Acked-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 09/13] memory: tegra20-emc: simplify with scoped for each OF child loop
  2024-08-16 10:54 ` [PATCH v2 09/13] memory: tegra20-emc: " Krzysztof Kozlowski
@ 2024-08-27  9:11   ` Thierry Reding
  0 siblings, 0 replies; 29+ messages in thread
From: Thierry Reding @ 2024-08-27  9:11 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Alexandre Belloni, linux-samsung-soc, Maxime Coquelin, linux-pm,
	Alexandre Torgue, linux-kernel, Jonathan Cameron,
	Krzysztof Kozlowski, Claudiu Beznea, linux-arm-kernel,
	Alim Akhtar, Santosh Shilimkar, linux-tegra, Jonathan Hunter,
	linux-stm32, Lukasz Luba

[-- Attachment #1: Type: text/plain, Size: 475 bytes --]

On Fri, Aug 16, 2024 at 12:54:33PM GMT, Krzysztof Kozlowski wrote:
> Use scoped for_each_child_of_node_scoped() when iterating over device
> nodes to make code a bit simpler.
> 
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  drivers/memory/tegra/tegra20-emc.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)

Acked-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 10/13] memory: tegra30-emc: simplify with scoped for each OF child loop
  2024-08-16 10:54 ` [PATCH v2 10/13] memory: tegra30-emc: " Krzysztof Kozlowski
  2024-08-19 16:01   ` Jonathan Cameron
@ 2024-08-27  9:11   ` Thierry Reding
  1 sibling, 0 replies; 29+ messages in thread
From: Thierry Reding @ 2024-08-27  9:11 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Alexandre Belloni, linux-samsung-soc, Maxime Coquelin, linux-pm,
	Alexandre Torgue, linux-kernel, Krzysztof Kozlowski,
	Claudiu Beznea, linux-arm-kernel, Alim Akhtar, Santosh Shilimkar,
	linux-tegra, Jonathan Hunter, linux-stm32, Lukasz Luba

[-- Attachment #1: Type: text/plain, Size: 412 bytes --]

On Fri, Aug 16, 2024 at 12:54:34PM GMT, Krzysztof Kozlowski wrote:
> Use scoped for_each_child_of_node_scoped() when iterating over device
> nodes to make code a bit simpler.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  drivers/memory/tegra/tegra30-emc.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)

Acked-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes
  2024-08-21 11:41 ` [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
@ 2024-08-27  9:12   ` Thierry Reding
  0 siblings, 0 replies; 29+ messages in thread
From: Thierry Reding @ 2024-08-27  9:12 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Alexandre Belloni, linux-samsung-soc, Maxime Coquelin, linux-pm,
	Alexandre Torgue, linux-kernel, Jonathan Cameron, Claudiu Beznea,
	Krzysztof Kozlowski, linux-arm-kernel, Alim Akhtar,
	Santosh Shilimkar, linux-tegra, Jonathan Hunter, linux-stm32,
	Lukasz Luba

[-- Attachment #1: Type: text/plain, Size: 636 bytes --]

On Wed, Aug 21, 2024 at 01:41:54PM GMT, Krzysztof Kozlowski wrote:
> On 16/08/2024 12:54, Krzysztof Kozlowski wrote:
> > Changes in v2:
> > - Add tags
> > - Wrap lines before of_parse_phandle() (Jonathan)
> > - Few new patches (see individual changelogs)
> > - Link to v1: https://lore.kernel.org/r/20240812-cleanup-h-of-node-put-memory-v1-0-5065a8f361d2@linaro.org
> > 
> > Make code a bit simpler and smaller by using cleanup.h when handling
> > device nodes.
> > 
> > Best regards,
> 
> Rebased (some changes around ti-aemif) and applied.

Oh heh... nevermind those Acked-bys that I just sent out then. =)

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 02/13] memory: atmel-ebi: simplify with scoped for each OF child loop
  2024-08-16 10:54 ` [PATCH v2 02/13] memory: atmel-ebi: simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-27 10:30   ` Nicolas Ferre
  0 siblings, 0 replies; 29+ messages in thread
From: Nicolas Ferre @ 2024-08-27 10:30 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Krzysztof Kozlowski, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra, Jonathan Cameron

On 16/08/2024 at 12:54, Krzysztof Kozlowski wrote:
> Use scoped for_each_available_child_of_node_scoped() when iterating over
> device nodes to make code a bit simpler.
> 
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Thanks!
Regards,
   Nicolas

> ---
>   drivers/memory/atmel-ebi.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/memory/atmel-ebi.c b/drivers/memory/atmel-ebi.c
> index 8f5b3302ee30..8db970da9af9 100644
> --- a/drivers/memory/atmel-ebi.c
> +++ b/drivers/memory/atmel-ebi.c
> @@ -518,7 +518,7 @@ static int atmel_ebi_dev_disable(struct atmel_ebi *ebi, struct device_node *np)
>   static int atmel_ebi_probe(struct platform_device *pdev)
>   {
>          struct device *dev = &pdev->dev;
> -       struct device_node *child, *np = dev->of_node;
> +       struct device_node *np = dev->of_node;
>          struct atmel_ebi *ebi;
>          int ret, reg_cells;
>          struct clk *clk;
> @@ -592,7 +592,7 @@ static int atmel_ebi_probe(struct platform_device *pdev)
> 
>          reg_cells += val;
> 
> -       for_each_available_child_of_node(np, child) {
> +       for_each_available_child_of_node_scoped(np, child) {
>                  if (!of_property_present(child, "reg"))
>                          continue;
> 
> @@ -602,10 +602,8 @@ static int atmel_ebi_probe(struct platform_device *pdev)
>                                  child);
> 
>                          ret = atmel_ebi_dev_disable(ebi, child);
> -                       if (ret) {
> -                               of_node_put(child);
> +                       if (ret)
>                                  return ret;
> -                       }
>                  }
>          }
> 
> 
> --
> 2.43.0
> 



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

* Re: [PATCH v2 01/13] memory: atmel-ebi: use scoped device node handling to simplify error paths
  2024-08-16 10:54 ` [PATCH v2 01/13] memory: atmel-ebi: use scoped device node handling to simplify error paths Krzysztof Kozlowski
  2024-08-19 16:04   ` Jonathan Cameron
@ 2024-08-27 10:35   ` Nicolas Ferre
  1 sibling, 0 replies; 29+ messages in thread
From: Nicolas Ferre @ 2024-08-27 10:35 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Krzysztof Kozlowski, Alexandre Belloni,
	Claudiu Beznea, Lukasz Luba, Alim Akhtar, Maxime Coquelin,
	Alexandre Torgue, Thierry Reding, Jonathan Hunter,
	Santosh Shilimkar
  Cc: linux-kernel, linux-arm-kernel, linux-pm, linux-samsung-soc,
	linux-stm32, linux-tegra

On 16/08/2024 at 12:54, Krzysztof Kozlowski wrote:
> Obtain the device node reference with scoped/cleanup.h to reduce error
> handling and make the code a bit simpler.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Best regards,
   Nicolas

> 
> ---
> 
> Changes in v2:
> 1. Wrap line before of_parse_phandle()
> ---
>   drivers/memory/atmel-ebi.c | 29 ++++++++++-------------------
>   1 file changed, 10 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/memory/atmel-ebi.c b/drivers/memory/atmel-ebi.c
> index e8bb5f37f5cb..8f5b3302ee30 100644
> --- a/drivers/memory/atmel-ebi.c
> +++ b/drivers/memory/atmel-ebi.c
> @@ -6,6 +6,7 @@
>    * Copyright (C) 2013 Jean-Jacques Hiblot <jjhiblot@traphandler.com>
>    */
> 
> +#include <linux/cleanup.h>
>   #include <linux/clk.h>
>   #include <linux/io.h>
>   #include <linux/mfd/syscon.h>
> @@ -517,7 +518,7 @@ static int atmel_ebi_dev_disable(struct atmel_ebi *ebi, struct device_node *np)
>   static int atmel_ebi_probe(struct platform_device *pdev)
>   {
>          struct device *dev = &pdev->dev;
> -       struct device_node *child, *np = dev->of_node, *smc_np;
> +       struct device_node *child, *np = dev->of_node;
>          struct atmel_ebi *ebi;
>          int ret, reg_cells;
>          struct clk *clk;
> @@ -541,30 +542,24 @@ static int atmel_ebi_probe(struct platform_device *pdev)
> 
>          ebi->clk = clk;
> 
> -       smc_np = of_parse_phandle(dev->of_node, "atmel,smc", 0);
> +       struct device_node *smc_np __free(device_node) =
> +               of_parse_phandle(dev->of_node, "atmel,smc", 0);
> 
>          ebi->smc.regmap = syscon_node_to_regmap(smc_np);
> -       if (IS_ERR(ebi->smc.regmap)) {
> -               ret = PTR_ERR(ebi->smc.regmap);
> -               goto put_node;
> -       }
> +       if (IS_ERR(ebi->smc.regmap))
> +               return PTR_ERR(ebi->smc.regmap);
> 
>          ebi->smc.layout = atmel_hsmc_get_reg_layout(smc_np);
> -       if (IS_ERR(ebi->smc.layout)) {
> -               ret = PTR_ERR(ebi->smc.layout);
> -               goto put_node;
> -       }
> +       if (IS_ERR(ebi->smc.layout))
> +               return PTR_ERR(ebi->smc.layout);
> 
>          ebi->smc.clk = of_clk_get(smc_np, 0);
>          if (IS_ERR(ebi->smc.clk)) {
> -               if (PTR_ERR(ebi->smc.clk) != -ENOENT) {
> -                       ret = PTR_ERR(ebi->smc.clk);
> -                       goto put_node;
> -               }
> +               if (PTR_ERR(ebi->smc.clk) != -ENOENT)
> +                       return PTR_ERR(ebi->smc.clk);
> 
>                  ebi->smc.clk = NULL;
>          }
> -       of_node_put(smc_np);
>          ret = clk_prepare_enable(ebi->smc.clk);
>          if (ret)
>                  return ret;
> @@ -615,10 +610,6 @@ static int atmel_ebi_probe(struct platform_device *pdev)
>          }
> 
>          return of_platform_populate(np, NULL, NULL, dev);
> -
> -put_node:
> -       of_node_put(smc_np);
> -       return ret;
>   }
> 
>   static __maybe_unused int atmel_ebi_resume(struct device *dev)
> 
> --
> 2.43.0
> 



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

end of thread, other threads:[~2024-08-27 10:36 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-16 10:54 [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
2024-08-16 10:54 ` [PATCH v2 01/13] memory: atmel-ebi: use scoped device node handling to simplify error paths Krzysztof Kozlowski
2024-08-19 16:04   ` Jonathan Cameron
2024-08-27 10:35   ` Nicolas Ferre
2024-08-16 10:54 ` [PATCH v2 02/13] memory: atmel-ebi: simplify with scoped for each OF child loop Krzysztof Kozlowski
2024-08-27 10:30   ` Nicolas Ferre
2024-08-16 10:54 ` [PATCH v2 03/13] memory: samsung: exynos5422-dmc: simplify dmc->dev usage Krzysztof Kozlowski
2024-08-19 16:03   ` Jonathan Cameron
2024-08-16 10:54 ` [PATCH v2 04/13] memory: samsung: exynos5422-dmc: use scoped device node handling to simplify error paths Krzysztof Kozlowski
2024-08-16 10:54 ` [PATCH v2 05/13] memory: stm32-fmc2-ebi: simplify with scoped for each OF child loop Krzysztof Kozlowski
2024-08-16 10:54 ` [PATCH v2 06/13] memory: stm32-fmc2-ebi: simplify with dev_err_probe() Krzysztof Kozlowski
2024-08-19 16:02   ` Jonathan Cameron
2024-08-16 10:54 ` [PATCH v2 07/13] memory: tegra-mc: simplify with scoped for each OF child loop Krzysztof Kozlowski
2024-08-27  9:10   ` Thierry Reding
2024-08-16 10:54 ` [PATCH v2 08/13] memory: tegra124-emc: " Krzysztof Kozlowski
2024-08-27  9:11   ` Thierry Reding
2024-08-16 10:54 ` [PATCH v2 09/13] memory: tegra20-emc: " Krzysztof Kozlowski
2024-08-27  9:11   ` Thierry Reding
2024-08-16 10:54 ` [PATCH v2 10/13] memory: tegra30-emc: " Krzysztof Kozlowski
2024-08-19 16:01   ` Jonathan Cameron
2024-08-27  9:11   ` Thierry Reding
2024-08-16 10:54 ` [PATCH v2 11/13] memory: ti-aemif: simplify with dev_err_probe() Krzysztof Kozlowski
2024-08-19 16:00   ` Jonathan Cameron
2024-08-16 10:54 ` [PATCH v2 12/13] memory: ti-aemif: simplify with devm_clk_get_enabled() Krzysztof Kozlowski
2024-08-19 15:59   ` Jonathan Cameron
2024-08-16 10:54 ` [PATCH v2 13/13] memory: ti-aemif: simplify with scoped for each OF child loop Krzysztof Kozlowski
2024-08-19 15:58   ` Jonathan Cameron
2024-08-21 11:41 ` [PATCH v2 00/13] memory: simplify with scoped/cleanup.h for device nodes Krzysztof Kozlowski
2024-08-27  9:12   ` Thierry Reding

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).