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
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: [email protected]
Signed-off-by: Mathieu Poirier <[email protected]>
---
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
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: [email protected]
Signed-off-by: Mathieu Poirier <[email protected]>
---
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
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: [email protected]
Signed-off-by: Mathieu Poirier <[email protected]>
---
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
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: [email protected]
Signed-off-by: Mathieu Poirier <[email protected]>
---
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
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: [email protected]
Signed-off-by: Mathieu Poirier <[email protected]>
---
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
On Mon, Mar 20, 2023 at 7:18 PM Mathieu Poirier
<[email protected]> 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
> 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: [email protected]
> Signed-off-by: Mathieu Poirier <[email protected]>
LGTM:
Reviewed-by: Peng Fan <[email protected]>
> ---
> 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
>
> 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: [email protected]
> Signed-off-by: Mathieu Poirier <[email protected]>
Acked-by: Shengjiu Wang <[email protected]>
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
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: [email protected]
> Signed-off-by: Mathieu Poirier <[email protected]>
reviewed-by: Arnaud Pouliquen <[email protected]>
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++;
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: [email protected]
> Signed-off-by: Mathieu Poirier <[email protected]>
> ---
> 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 <[email protected]>
Thanks,
Arnaud
>
> rproc_add_carveout(rproc, mem);
> index++;
On Mon, Mar 20, 2023 at 08:02:04PM -0300, Fabio Estevam wrote:
> On Mon, Mar 20, 2023 at 7:18 PM Mathieu Poirier
> <[email protected]> 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.
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: [email protected]
> > Signed-off-by: Mathieu Poirier <[email protected]>
> > ---
> > 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 <[email protected]>
>
Ok
> Thanks,
> Arnaud
>
>
> >
> > rproc_add_carveout(rproc, mem);
> > index++;
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: [email protected]
>>> Signed-off-by: Mathieu Poirier <[email protected]>
>>> ---
>>> 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 <[email protected]>
>>
>
> Ok
>
>> Thanks,
>> Arnaud
>>
>>
>>>
>>> rproc_add_carveout(rproc, mem);
>>> index++;