linux-remoteproc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] remoteproc: Call of_node_put() on iteration error
@ 2023-03-20 22:18 Mathieu Poirier
  2023-03-20 22:18 ` [PATCH 1/5] remoteproc: stm32: " Mathieu Poirier
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Mathieu Poirier @ 2023-03-20 22:18 UTC (permalink / raw)
  To: andersson
  Cc: shawnguo, s.hauer, kernel, festevam, linux-imx, patrice.chotard,
	mcoquelin.stm32, alexandre.torgue, arnaud.pouliquen,
	hongxing.zhu, peng.fan, shengjiu.wang, linux-remoteproc,
	linux-arm-kernel, linux-kernel

This patchset adds missing calls to of_put_node() when prematurely
exiting from a loop driven by of_phandle_iterator_next().

Some help reviewing this set would be appreciated.

Thanks,
Mathieu

Mathieu Poirier (5):
  remoteproc: stm32: Call of_node_put() on iteration error
  remoteproc: st: Call of_node_put() on iteration error
  remoteproc: rcar_rproc: Call of_node_put() on iteration error
  remoteproc: imx_rproc: Call of_node_put() on iteration error
  retmoteproc: imx_dsp_rproc: Call of_node_put() on iteration error

 drivers/remoteproc/imx_dsp_rproc.c | 12 +++++++++---
 drivers/remoteproc/imx_rproc.c     |  7 +++++--
 drivers/remoteproc/rcar_rproc.c    |  9 +++++++--
 drivers/remoteproc/st_remoteproc.c |  5 ++++-
 drivers/remoteproc/stm32_rproc.c   |  6 +++++-
 5 files changed, 30 insertions(+), 9 deletions(-)

-- 
2.25.1


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

* [PATCH 1/5] remoteproc: stm32: Call of_node_put() on iteration error
  2023-03-20 22:18 [PATCH 0/5] remoteproc: Call of_node_put() on iteration error Mathieu Poirier
@ 2023-03-20 22:18 ` Mathieu Poirier
  2023-03-21  9:00   ` Arnaud POULIQUEN
  2023-03-20 22:18 ` [PATCH 2/5] remoteproc: st: " Mathieu Poirier
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Mathieu Poirier @ 2023-03-20 22:18 UTC (permalink / raw)
  To: andersson
  Cc: shawnguo, s.hauer, kernel, festevam, linux-imx, patrice.chotard,
	mcoquelin.stm32, alexandre.torgue, arnaud.pouliquen,
	hongxing.zhu, peng.fan, shengjiu.wang, linux-remoteproc,
	linux-arm-kernel, linux-kernel

Function of_phandle_iterator_next() calls of_node_put() on the last
device_node it iterated over, but when the loop exits prematurely it has
to be called explicitly.

Fixes: 13140de09cc2 ("remoteproc: stm32: add an ST stm32_rproc driver")
Cc: stable@vger.kernel.org
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 drivers/remoteproc/stm32_rproc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c
index 7d782ed9e589..23c1690b8d73 100644
--- a/drivers/remoteproc/stm32_rproc.c
+++ b/drivers/remoteproc/stm32_rproc.c
@@ -223,11 +223,13 @@ static int stm32_rproc_prepare(struct rproc *rproc)
 	while (of_phandle_iterator_next(&it) == 0) {
 		rmem = of_reserved_mem_lookup(it.node);
 		if (!rmem) {
+			of_node_put(it.node);
 			dev_err(dev, "unable to acquire memory-region\n");
 			return -EINVAL;
 		}
 
 		if (stm32_rproc_pa_to_da(rproc, rmem->base, &da) < 0) {
+			of_node_put(it.node);
 			dev_err(dev, "memory region not valid %pa\n",
 				&rmem->base);
 			return -EINVAL;
@@ -254,8 +256,10 @@ static int stm32_rproc_prepare(struct rproc *rproc)
 							   it.node->name);
 		}
 
-		if (!mem)
+		if (!mem) {
+			of_node_put(it.node);
 			return -ENOMEM;
+		}
 
 		rproc_add_carveout(rproc, mem);
 		index++;
-- 
2.25.1


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

* [PATCH 2/5] remoteproc: st: Call of_node_put() on iteration error
  2023-03-20 22:18 [PATCH 0/5] remoteproc: Call of_node_put() on iteration error Mathieu Poirier
  2023-03-20 22:18 ` [PATCH 1/5] remoteproc: stm32: " Mathieu Poirier
@ 2023-03-20 22:18 ` Mathieu Poirier
  2023-03-21  9:01   ` Arnaud POULIQUEN
  2023-03-20 22:18 ` [PATCH 3/5] remoteproc: rcar_rproc: " Mathieu Poirier
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Mathieu Poirier @ 2023-03-20 22:18 UTC (permalink / raw)
  To: andersson
  Cc: shawnguo, s.hauer, kernel, festevam, linux-imx, patrice.chotard,
	mcoquelin.stm32, alexandre.torgue, arnaud.pouliquen,
	hongxing.zhu, peng.fan, shengjiu.wang, linux-remoteproc,
	linux-arm-kernel, linux-kernel

Function of_phandle_iterator_next() calls of_node_put() on the last
device_node it iterated over, but when the loop exits prematurely it has
to be called explicitly.

Fixes: 3df52ed7f269 ("remoteproc: st: add reserved memory support")
Cc: stable@vger.kernel.org
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 drivers/remoteproc/st_remoteproc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/st_remoteproc.c b/drivers/remoteproc/st_remoteproc.c
index a3268d95a50e..e6bd3c7a950a 100644
--- a/drivers/remoteproc/st_remoteproc.c
+++ b/drivers/remoteproc/st_remoteproc.c
@@ -129,6 +129,7 @@ static int st_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
 	while (of_phandle_iterator_next(&it) == 0) {
 		rmem = of_reserved_mem_lookup(it.node);
 		if (!rmem) {
+			of_node_put(it.node);
 			dev_err(dev, "unable to acquire memory-region\n");
 			return -EINVAL;
 		}
@@ -150,8 +151,10 @@ static int st_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
 							   it.node->name);
 		}
 
-		if (!mem)
+		if (!mem) {
+			of_node_put(it.node);
 			return -ENOMEM;
+		}
 
 		rproc_add_carveout(rproc, mem);
 		index++;
-- 
2.25.1


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

* [PATCH 3/5] remoteproc: rcar_rproc: Call of_node_put() on iteration error
  2023-03-20 22:18 [PATCH 0/5] remoteproc: Call of_node_put() on iteration error Mathieu Poirier
  2023-03-20 22:18 ` [PATCH 1/5] remoteproc: stm32: " Mathieu Poirier
  2023-03-20 22:18 ` [PATCH 2/5] remoteproc: st: " Mathieu Poirier
@ 2023-03-20 22:18 ` Mathieu Poirier
  2023-03-20 22:18 ` [PATCH 4/5] remoteproc: imx_rproc: " Mathieu Poirier
  2023-03-20 22:18 ` [PATCH 5/5] retmoteproc: imx_dsp_rproc: " Mathieu Poirier
  4 siblings, 0 replies; 14+ messages in thread
From: Mathieu Poirier @ 2023-03-20 22:18 UTC (permalink / raw)
  To: andersson
  Cc: shawnguo, s.hauer, kernel, festevam, linux-imx, patrice.chotard,
	mcoquelin.stm32, alexandre.torgue, arnaud.pouliquen,
	hongxing.zhu, peng.fan, shengjiu.wang, linux-remoteproc,
	linux-arm-kernel, linux-kernel

Function of_phandle_iterator_next() calls of_node_put() on the last
device_node it iterated over, but when the loop exits prematurely it has
to be called explicitly.

Fixes: 285892a74f13 ("remoteproc: Add Renesas rcar driver")
Cc: stable@vger.kernel.org
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 drivers/remoteproc/rcar_rproc.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/rcar_rproc.c b/drivers/remoteproc/rcar_rproc.c
index aa86154109c7..1ff2a73ade90 100644
--- a/drivers/remoteproc/rcar_rproc.c
+++ b/drivers/remoteproc/rcar_rproc.c
@@ -62,13 +62,16 @@ static int rcar_rproc_prepare(struct rproc *rproc)
 
 		rmem = of_reserved_mem_lookup(it.node);
 		if (!rmem) {
+			of_node_put(it.node);
 			dev_err(&rproc->dev,
 				"unable to acquire memory-region\n");
 			return -EINVAL;
 		}
 
-		if (rmem->base > U32_MAX)
+		if (rmem->base > U32_MAX) {
+			of_node_put(it.node);
 			return -EINVAL;
+		}
 
 		/* No need to translate pa to da, R-Car use same map */
 		da = rmem->base;
@@ -79,8 +82,10 @@ static int rcar_rproc_prepare(struct rproc *rproc)
 					   rcar_rproc_mem_release,
 					   it.node->name);
 
-		if (!mem)
+		if (!mem) {
+			of_node_put(it.node);
 			return -ENOMEM;
+		}
 
 		rproc_add_carveout(rproc, mem);
 	}
-- 
2.25.1


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

* [PATCH 4/5] remoteproc: imx_rproc: Call of_node_put() on iteration error
  2023-03-20 22:18 [PATCH 0/5] remoteproc: Call of_node_put() on iteration error Mathieu Poirier
                   ` (2 preceding siblings ...)
  2023-03-20 22:18 ` [PATCH 3/5] remoteproc: rcar_rproc: " Mathieu Poirier
@ 2023-03-20 22:18 ` Mathieu Poirier
  2023-03-21  3:00   ` Peng Fan
  2023-03-20 22:18 ` [PATCH 5/5] retmoteproc: imx_dsp_rproc: " Mathieu Poirier
  4 siblings, 1 reply; 14+ messages in thread
From: Mathieu Poirier @ 2023-03-20 22:18 UTC (permalink / raw)
  To: andersson
  Cc: shawnguo, s.hauer, kernel, festevam, linux-imx, patrice.chotard,
	mcoquelin.stm32, alexandre.torgue, arnaud.pouliquen,
	hongxing.zhu, peng.fan, shengjiu.wang, linux-remoteproc,
	linux-arm-kernel, linux-kernel

Function of_phandle_iterator_next() calls of_node_put() on the last
device_node it iterated over, but when the loop exits prematurely it has
to be called explicitly.

Fixes: b29b4249f8f0 ("remoteproc: imx_rproc: add i.MX specific parse fw hook")
Cc: stable@vger.kernel.org
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 drivers/remoteproc/imx_rproc.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 9fc978e0393c..0ab840dc7e97 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -541,6 +541,7 @@ static int imx_rproc_prepare(struct rproc *rproc)
 
 		rmem = of_reserved_mem_lookup(it.node);
 		if (!rmem) {
+			of_node_put(it.node);
 			dev_err(priv->dev, "unable to acquire memory-region\n");
 			return -EINVAL;
 		}
@@ -553,10 +554,12 @@ static int imx_rproc_prepare(struct rproc *rproc)
 					   imx_rproc_mem_alloc, imx_rproc_mem_release,
 					   it.node->name);
 
-		if (mem)
+		if (mem) {
 			rproc_coredump_add_segment(rproc, da, rmem->size);
-		else
+		} else {
+			of_node_put(it.node);
 			return -ENOMEM;
+		}
 
 		rproc_add_carveout(rproc, mem);
 	}
-- 
2.25.1


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

* [PATCH 5/5] retmoteproc: imx_dsp_rproc: Call of_node_put() on iteration error
  2023-03-20 22:18 [PATCH 0/5] remoteproc: Call of_node_put() on iteration error Mathieu Poirier
                   ` (3 preceding siblings ...)
  2023-03-20 22:18 ` [PATCH 4/5] remoteproc: imx_rproc: " Mathieu Poirier
@ 2023-03-20 22:18 ` Mathieu Poirier
  2023-03-20 23:02   ` Fabio Estevam
  2023-03-21  3:34   ` S.J. Wang
  4 siblings, 2 replies; 14+ messages in thread
From: Mathieu Poirier @ 2023-03-20 22:18 UTC (permalink / raw)
  To: andersson
  Cc: shawnguo, s.hauer, kernel, festevam, linux-imx, patrice.chotard,
	mcoquelin.stm32, alexandre.torgue, arnaud.pouliquen,
	hongxing.zhu, peng.fan, shengjiu.wang, linux-remoteproc,
	linux-arm-kernel, linux-kernel

Function of_phandle_iterator_next() calls of_node_put() on the last
device_node it iterated over, but when the loop exits prematurely it has
to be called explicitly.

Fixes: ec0e5549f358 ("remoteproc: imx_dsp_rproc: Add remoteproc driver for DSP on i.MX")
Cc: stable@vger.kernel.org
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 drivers/remoteproc/imx_dsp_rproc.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/imx_dsp_rproc.c b/drivers/remoteproc/imx_dsp_rproc.c
index b8f268d41773..21759d9e5b7b 100644
--- a/drivers/remoteproc/imx_dsp_rproc.c
+++ b/drivers/remoteproc/imx_dsp_rproc.c
@@ -650,15 +650,19 @@ static int imx_dsp_rproc_add_carveout(struct imx_dsp_rproc *priv)
 
 		rmem = of_reserved_mem_lookup(it.node);
 		if (!rmem) {
+			of_node_put(it.node);
 			dev_err(dev, "unable to acquire memory-region\n");
 			return -EINVAL;
 		}
 
-		if (imx_dsp_rproc_sys_to_da(priv, rmem->base, rmem->size, &da))
+		if (imx_dsp_rproc_sys_to_da(priv, rmem->base, rmem->size, &da)) {
+			of_node_put(it.node);
 			return -EINVAL;
+		}
 
 		cpu_addr = devm_ioremap_wc(dev, rmem->base, rmem->size);
 		if (!cpu_addr) {
+			of_node_put(it.node);
 			dev_err(dev, "failed to map memory %p\n", &rmem->base);
 			return -ENOMEM;
 		}
@@ -667,10 +671,12 @@ static int imx_dsp_rproc_add_carveout(struct imx_dsp_rproc *priv)
 		mem = rproc_mem_entry_init(dev, (void __force *)cpu_addr, (dma_addr_t)rmem->base,
 					   rmem->size, da, NULL, NULL, it.node->name);
 
-		if (mem)
+		if (mem) {
 			rproc_coredump_add_segment(rproc, da, rmem->size);
-		else
+		} else {
+			of_node_put(it.node);
 			return -ENOMEM;
+		}
 
 		rproc_add_carveout(rproc, mem);
 	}
-- 
2.25.1


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

* Re: [PATCH 5/5] retmoteproc: imx_dsp_rproc: Call of_node_put() on iteration error
  2023-03-20 22:18 ` [PATCH 5/5] retmoteproc: imx_dsp_rproc: " Mathieu Poirier
@ 2023-03-20 23:02   ` Fabio Estevam
  2023-03-21 21:19     ` Mathieu Poirier
  2023-03-21  3:34   ` S.J. Wang
  1 sibling, 1 reply; 14+ messages in thread
From: Fabio Estevam @ 2023-03-20 23:02 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: andersson, shawnguo, s.hauer, kernel, linux-imx, patrice.chotard,
	mcoquelin.stm32, alexandre.torgue, arnaud.pouliquen,
	hongxing.zhu, peng.fan, shengjiu.wang, linux-remoteproc,
	linux-arm-kernel, linux-kernel

On Mon, Mar 20, 2023 at 7:18 PM Mathieu Poirier
<mathieu.poirier@linaro.org> wrote:
>
> Function of_phandle_iterator_next() calls of_node_put() on the last
> device_node it iterated over, but when the loop exits prematurely it has
> to be called explicitly.

Typo on the Subject: s/retmoteproc/remoteproc

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

* RE: [PATCH 4/5] remoteproc: imx_rproc: Call of_node_put() on iteration error
  2023-03-20 22:18 ` [PATCH 4/5] remoteproc: imx_rproc: " Mathieu Poirier
@ 2023-03-21  3:00   ` Peng Fan
  0 siblings, 0 replies; 14+ messages in thread
From: Peng Fan @ 2023-03-21  3:00 UTC (permalink / raw)
  To: Mathieu Poirier, andersson
  Cc: shawnguo, s.hauer, kernel, festevam, dl-linux-imx,
	patrice.chotard, mcoquelin.stm32, alexandre.torgue,
	arnaud.pouliquen, Hongxing Zhu, S.J. Wang, linux-remoteproc,
	linux-arm-kernel, linux-kernel

> Subject: [PATCH 4/5] remoteproc: imx_rproc: Call of_node_put() on
> iteration error
> 
> Function of_phandle_iterator_next() calls of_node_put() on the last
> device_node it iterated over, but when the loop exits prematurely it has to
> be called explicitly.
> 
> Fixes: b29b4249f8f0 ("remoteproc: imx_rproc: add i.MX specific parse fw
> hook")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>

LGTM:
Reviewed-by: Peng Fan <peng.fan@nxp.com>

> ---
>  drivers/remoteproc/imx_rproc.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/remoteproc/imx_rproc.c
> b/drivers/remoteproc/imx_rproc.c index 9fc978e0393c..0ab840dc7e97
> 100644
> --- a/drivers/remoteproc/imx_rproc.c
> +++ b/drivers/remoteproc/imx_rproc.c
> @@ -541,6 +541,7 @@ static int imx_rproc_prepare(struct rproc *rproc)
> 
>  		rmem = of_reserved_mem_lookup(it.node);
>  		if (!rmem) {
> +			of_node_put(it.node);
>  			dev_err(priv->dev, "unable to acquire memory-
> region\n");
>  			return -EINVAL;
>  		}
> @@ -553,10 +554,12 @@ static int imx_rproc_prepare(struct rproc *rproc)
>  					   imx_rproc_mem_alloc,
> imx_rproc_mem_release,
>  					   it.node->name);
> 
> -		if (mem)
> +		if (mem) {
>  			rproc_coredump_add_segment(rproc, da, rmem-
> >size);
> -		else
> +		} else {
> +			of_node_put(it.node);
>  			return -ENOMEM;
> +		}
> 
>  		rproc_add_carveout(rproc, mem);
>  	}
> --
> 2.25.1


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

* RE: [PATCH 5/5] retmoteproc: imx_dsp_rproc: Call of_node_put() on iteration error
  2023-03-20 22:18 ` [PATCH 5/5] retmoteproc: imx_dsp_rproc: " Mathieu Poirier
  2023-03-20 23:02   ` Fabio Estevam
@ 2023-03-21  3:34   ` S.J. Wang
  1 sibling, 0 replies; 14+ messages in thread
From: S.J. Wang @ 2023-03-21  3:34 UTC (permalink / raw)
  To: Mathieu Poirier, andersson
  Cc: shawnguo, s.hauer, kernel, festevam, dl-linux-imx,
	patrice.chotard, mcoquelin.stm32, alexandre.torgue,
	arnaud.pouliquen, Hongxing Zhu, Peng Fan, linux-remoteproc,
	linux-arm-kernel, linux-kernel

> 
> Function of_phandle_iterator_next() calls of_node_put() on the last
> device_node it iterated over, but when the loop exits prematurely it has to
> be called explicitly.
> 
> Fixes: ec0e5549f358 ("remoteproc: imx_dsp_rproc: Add remoteproc driver
> for DSP on i.MX")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>

Acked-by: Shengjiu Wang <shengjiu.wang@gmail.com>

Best regards
Wang Shengjiu
> ---
>  drivers/remoteproc/imx_dsp_rproc.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/remoteproc/imx_dsp_rproc.c
> b/drivers/remoteproc/imx_dsp_rproc.c
> index b8f268d41773..21759d9e5b7b 100644
> --- a/drivers/remoteproc/imx_dsp_rproc.c
> +++ b/drivers/remoteproc/imx_dsp_rproc.c
> @@ -650,15 +650,19 @@ static int imx_dsp_rproc_add_carveout(struct
> imx_dsp_rproc *priv)
> 
>                 rmem = of_reserved_mem_lookup(it.node);
>                 if (!rmem) {
> +                       of_node_put(it.node);
>                         dev_err(dev, "unable to acquire memory-region\n");
>                         return -EINVAL;
>                 }
> 
> -               if (imx_dsp_rproc_sys_to_da(priv, rmem->base, rmem->size, &da))
> +               if (imx_dsp_rproc_sys_to_da(priv, rmem->base, rmem->size, &da))
> {
> +                       of_node_put(it.node);
>                         return -EINVAL;
> +               }
> 
>                 cpu_addr = devm_ioremap_wc(dev, rmem->base, rmem->size);
>                 if (!cpu_addr) {
> +                       of_node_put(it.node);
>                         dev_err(dev, "failed to map memory %p\n", &rmem->base);
>                         return -ENOMEM;
>                 }
> @@ -667,10 +671,12 @@ static int imx_dsp_rproc_add_carveout(struct
> imx_dsp_rproc *priv)
>                 mem = rproc_mem_entry_init(dev, (void __force *)cpu_addr,
> (dma_addr_t)rmem->base,
>                                            rmem->size, da, NULL, NULL, it.node->name);
> 
> -               if (mem)
> +               if (mem) {
>                         rproc_coredump_add_segment(rproc, da, rmem->size);
> -               else
> +               } else {
> +                       of_node_put(it.node);
>                         return -ENOMEM;
> +               }
> 
>                 rproc_add_carveout(rproc, mem);
>         }
> --
> 2.25.1


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

* Re: [PATCH 1/5] remoteproc: stm32: Call of_node_put() on iteration error
  2023-03-20 22:18 ` [PATCH 1/5] remoteproc: stm32: " Mathieu Poirier
@ 2023-03-21  9:00   ` Arnaud POULIQUEN
  2023-03-21 21:32     ` Mathieu Poirier
  0 siblings, 1 reply; 14+ messages in thread
From: Arnaud POULIQUEN @ 2023-03-21  9:00 UTC (permalink / raw)
  To: Mathieu Poirier, andersson
  Cc: shawnguo, s.hauer, kernel, festevam, linux-imx, patrice.chotard,
	mcoquelin.stm32, alexandre.torgue, arnaud.pouliquen,
	hongxing.zhu, peng.fan, shengjiu.wang, linux-remoteproc,
	linux-arm-kernel, linux-kernel

Hi Mathieu,

On 3/20/23 23:18, Mathieu Poirier wrote:
> Function of_phandle_iterator_next() calls of_node_put() on the last
> device_node it iterated over, but when the loop exits prematurely it has
> to be called explicitly> 
> Fixes: 13140de09cc2 ("remoteproc: stm32: add an ST stm32_rproc driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> ---
>  drivers/remoteproc/stm32_rproc.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c
> index 7d782ed9e589..23c1690b8d73 100644
> --- a/drivers/remoteproc/stm32_rproc.c
> +++ b/drivers/remoteproc/stm32_rproc.c
> @@ -223,11 +223,13 @@ static int stm32_rproc_prepare(struct rproc *rproc)
>  	while (of_phandle_iterator_next(&it) == 0) {
>  		rmem = of_reserved_mem_lookup(it.node);
>  		if (!rmem) {
> +			of_node_put(it.node);
>  			dev_err(dev, "unable to acquire memory-region\n");
>  			return -EINVAL;
>  		}
>  
>  		if (stm32_rproc_pa_to_da(rproc, rmem->base, &da) < 0) {
> +			of_node_put(it.node);
>  			dev_err(dev, "memory region not valid %pa\n",
>  				&rmem->base);
>  			return -EINVAL;
> @@ -254,8 +256,10 @@ static int stm32_rproc_prepare(struct rproc *rproc)
>  							   it.node->name);
>  		}
>  
> -		if (!mem)
> +		if (!mem) {
> +			of_node_put(it.node);
>  			return -ENOMEM;
> +		}

Good catch!

Looking in code I don't see that we call of_node_put() when we release the
carveouts. 
Please tell me if I'm wrong but look to me that we should also call of_node_put()
in mem->release() op, in drivers. 

This one remains valid.
reviewed-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>

Thanks,
Arnaud


>  
>  		rproc_add_carveout(rproc, mem);
>  		index++;

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

* Re: [PATCH 2/5] remoteproc: st: Call of_node_put() on iteration error
  2023-03-20 22:18 ` [PATCH 2/5] remoteproc: st: " Mathieu Poirier
@ 2023-03-21  9:01   ` Arnaud POULIQUEN
  0 siblings, 0 replies; 14+ messages in thread
From: Arnaud POULIQUEN @ 2023-03-21  9:01 UTC (permalink / raw)
  To: Mathieu Poirier, andersson
  Cc: shawnguo, s.hauer, kernel, festevam, linux-imx, patrice.chotard,
	mcoquelin.stm32, alexandre.torgue, arnaud.pouliquen,
	hongxing.zhu, peng.fan, shengjiu.wang, linux-remoteproc,
	linux-arm-kernel, linux-kernel



On 3/20/23 23:18, Mathieu Poirier wrote:
> Function of_phandle_iterator_next() calls of_node_put() on the last
> device_node it iterated over, but when the loop exits prematurely it has
> to be called explicitly.
> 
> Fixes: 3df52ed7f269 ("remoteproc: st: add reserved memory support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>

reviewed-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>

Thanks,
Arnaud

> ---
>  drivers/remoteproc/st_remoteproc.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/remoteproc/st_remoteproc.c b/drivers/remoteproc/st_remoteproc.c
> index a3268d95a50e..e6bd3c7a950a 100644
> --- a/drivers/remoteproc/st_remoteproc.c
> +++ b/drivers/remoteproc/st_remoteproc.c
> @@ -129,6 +129,7 @@ static int st_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
>  	while (of_phandle_iterator_next(&it) == 0) {
>  		rmem = of_reserved_mem_lookup(it.node);
>  		if (!rmem) {
> +			of_node_put(it.node);
>  			dev_err(dev, "unable to acquire memory-region\n");
>  			return -EINVAL;
>  		}
> @@ -150,8 +151,10 @@ static int st_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
>  							   it.node->name);
>  		}
>  
> -		if (!mem)
> +		if (!mem) {
> +			of_node_put(it.node);
>  			return -ENOMEM;
> +		}
>  
>  		rproc_add_carveout(rproc, mem);
>  		index++;

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

* Re: [PATCH 5/5] retmoteproc: imx_dsp_rproc: Call of_node_put() on iteration error
  2023-03-20 23:02   ` Fabio Estevam
@ 2023-03-21 21:19     ` Mathieu Poirier
  0 siblings, 0 replies; 14+ messages in thread
From: Mathieu Poirier @ 2023-03-21 21:19 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: andersson, shawnguo, s.hauer, kernel, linux-imx, patrice.chotard,
	mcoquelin.stm32, alexandre.torgue, arnaud.pouliquen,
	hongxing.zhu, peng.fan, shengjiu.wang, linux-remoteproc,
	linux-arm-kernel, linux-kernel

On Mon, Mar 20, 2023 at 08:02:04PM -0300, Fabio Estevam wrote:
> On Mon, Mar 20, 2023 at 7:18 PM Mathieu Poirier
> <mathieu.poirier@linaro.org> wrote:
> >
> > Function of_phandle_iterator_next() calls of_node_put() on the last
> > device_node it iterated over, but when the loop exits prematurely it has
> > to be called explicitly.
> 
> Typo on the Subject: s/retmoteproc/remoteproc

Thanks for pointing that out, I'll fix it.


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

* Re: [PATCH 1/5] remoteproc: stm32: Call of_node_put() on iteration error
  2023-03-21  9:00   ` Arnaud POULIQUEN
@ 2023-03-21 21:32     ` Mathieu Poirier
  2023-03-22  8:21       ` Arnaud POULIQUEN
  0 siblings, 1 reply; 14+ messages in thread
From: Mathieu Poirier @ 2023-03-21 21:32 UTC (permalink / raw)
  To: Arnaud POULIQUEN
  Cc: andersson, shawnguo, s.hauer, kernel, festevam, linux-imx,
	patrice.chotard, mcoquelin.stm32, alexandre.torgue,
	arnaud.pouliquen, hongxing.zhu, peng.fan, shengjiu.wang,
	linux-remoteproc, linux-arm-kernel, linux-kernel

On Tue, Mar 21, 2023 at 10:00:03AM +0100, Arnaud POULIQUEN wrote:
> Hi Mathieu,
> 
> On 3/20/23 23:18, Mathieu Poirier wrote:
> > Function of_phandle_iterator_next() calls of_node_put() on the last
> > device_node it iterated over, but when the loop exits prematurely it has
> > to be called explicitly> 
> > Fixes: 13140de09cc2 ("remoteproc: stm32: add an ST stm32_rproc driver")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> > ---
> >  drivers/remoteproc/stm32_rproc.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c
> > index 7d782ed9e589..23c1690b8d73 100644
> > --- a/drivers/remoteproc/stm32_rproc.c
> > +++ b/drivers/remoteproc/stm32_rproc.c
> > @@ -223,11 +223,13 @@ static int stm32_rproc_prepare(struct rproc *rproc)
> >  	while (of_phandle_iterator_next(&it) == 0) {
> >  		rmem = of_reserved_mem_lookup(it.node);
> >  		if (!rmem) {
> > +			of_node_put(it.node);
> >  			dev_err(dev, "unable to acquire memory-region\n");
> >  			return -EINVAL;
> >  		}
> >  
> >  		if (stm32_rproc_pa_to_da(rproc, rmem->base, &da) < 0) {
> > +			of_node_put(it.node);
> >  			dev_err(dev, "memory region not valid %pa\n",
> >  				&rmem->base);
> >  			return -EINVAL;
> > @@ -254,8 +256,10 @@ static int stm32_rproc_prepare(struct rproc *rproc)
> >  							   it.node->name);
> >  		}
> >  
> > -		if (!mem)
> > +		if (!mem) {
> > +			of_node_put(it.node);
> >  			return -ENOMEM;
> > +		}
> 
> Good catch!
> 
> Looking in code I don't see that we call of_node_put() when we release the
> carveouts. 
> Please tell me if I'm wrong but look to me that we should also call of_node_put()
> in mem->release() op, in drivers. 
>

Are you referring to entry->release(), which for stm32 is
stm32_rproc_mem_release(), in rproc_resource_cleanup()?

If so then no, it is not needed since of_phandle_iterator_next() calls
of_node_put() on the previous device_node with each iteration.

Otherwise I fail to understand the question and will ask you to clarify.

> This one remains valid.
> reviewed-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
> 

Ok

> Thanks,
> Arnaud
> 
> 
> >  
> >  		rproc_add_carveout(rproc, mem);
> >  		index++;

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

* Re: [PATCH 1/5] remoteproc: stm32: Call of_node_put() on iteration error
  2023-03-21 21:32     ` Mathieu Poirier
@ 2023-03-22  8:21       ` Arnaud POULIQUEN
  0 siblings, 0 replies; 14+ messages in thread
From: Arnaud POULIQUEN @ 2023-03-22  8:21 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: andersson, shawnguo, s.hauer, kernel, festevam, linux-imx,
	patrice.chotard, mcoquelin.stm32, alexandre.torgue,
	arnaud.pouliquen, hongxing.zhu, peng.fan, shengjiu.wang,
	linux-remoteproc, linux-arm-kernel, linux-kernel



On 3/21/23 22:32, Mathieu Poirier wrote:
> On Tue, Mar 21, 2023 at 10:00:03AM +0100, Arnaud POULIQUEN wrote:
>> Hi Mathieu,
>>
>> On 3/20/23 23:18, Mathieu Poirier wrote:
>>> Function of_phandle_iterator_next() calls of_node_put() on the last
>>> device_node it iterated over, but when the loop exits prematurely it has
>>> to be called explicitly> 
>>> Fixes: 13140de09cc2 ("remoteproc: stm32: add an ST stm32_rproc driver")
>>> Cc: stable@vger.kernel.org
>>> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
>>> ---
>>>  drivers/remoteproc/stm32_rproc.c | 6 +++++-
>>>  1 file changed, 5 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c
>>> index 7d782ed9e589..23c1690b8d73 100644
>>> --- a/drivers/remoteproc/stm32_rproc.c
>>> +++ b/drivers/remoteproc/stm32_rproc.c
>>> @@ -223,11 +223,13 @@ static int stm32_rproc_prepare(struct rproc *rproc)
>>>  	while (of_phandle_iterator_next(&it) == 0) {
>>>  		rmem = of_reserved_mem_lookup(it.node);
>>>  		if (!rmem) {
>>> +			of_node_put(it.node);
>>>  			dev_err(dev, "unable to acquire memory-region\n");
>>>  			return -EINVAL;
>>>  		}
>>>  
>>>  		if (stm32_rproc_pa_to_da(rproc, rmem->base, &da) < 0) {
>>> +			of_node_put(it.node);
>>>  			dev_err(dev, "memory region not valid %pa\n",
>>>  				&rmem->base);
>>>  			return -EINVAL;
>>> @@ -254,8 +256,10 @@ static int stm32_rproc_prepare(struct rproc *rproc)
>>>  							   it.node->name);
>>>  		}
>>>  
>>> -		if (!mem)
>>> +		if (!mem) {
>>> +			of_node_put(it.node);
>>>  			return -ENOMEM;
>>> +		}
>>
>> Good catch!
>>
>> Looking in code I don't see that we call of_node_put() when we release the
>> carveouts. 
>> Please tell me if I'm wrong but look to me that we should also call of_node_put()
>> in mem->release() op, in drivers. 
>>
> 
> Are you referring to entry->release(), which for stm32 is
> stm32_rproc_mem_release(), in rproc_resource_cleanup()?
> 
> If so then no, it is not needed since of_phandle_iterator_next() calls
> of_node_put() on the previous device_node with each iteration.
> 
> Otherwise I fail to understand the question and will ask you to clarify.

My apologize, I misread the of_phandle_iterator_next function. you can forget my
comment.

Regards,
Arnaud

> 
>> This one remains valid.
>> reviewed-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
>>
> 
> Ok
> 
>> Thanks,
>> Arnaud
>>
>>
>>>  
>>>  		rproc_add_carveout(rproc, mem);
>>>  		index++;

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

end of thread, other threads:[~2023-03-22  8:22 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-20 22:18 [PATCH 0/5] remoteproc: Call of_node_put() on iteration error Mathieu Poirier
2023-03-20 22:18 ` [PATCH 1/5] remoteproc: stm32: " Mathieu Poirier
2023-03-21  9:00   ` Arnaud POULIQUEN
2023-03-21 21:32     ` Mathieu Poirier
2023-03-22  8:21       ` Arnaud POULIQUEN
2023-03-20 22:18 ` [PATCH 2/5] remoteproc: st: " Mathieu Poirier
2023-03-21  9:01   ` Arnaud POULIQUEN
2023-03-20 22:18 ` [PATCH 3/5] remoteproc: rcar_rproc: " Mathieu Poirier
2023-03-20 22:18 ` [PATCH 4/5] remoteproc: imx_rproc: " Mathieu Poirier
2023-03-21  3:00   ` Peng Fan
2023-03-20 22:18 ` [PATCH 5/5] retmoteproc: imx_dsp_rproc: " Mathieu Poirier
2023-03-20 23:02   ` Fabio Estevam
2023-03-21 21:19     ` Mathieu Poirier
2023-03-21  3:34   ` S.J. Wang

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).