* [PATCH] powerpc/pseries/iommu: Add of_node_put() before break
@ 2021-10-14 7:56 Wan Jiabing
2021-10-14 17:32 ` Leonardo Brás
2021-11-02 10:11 ` Michael Ellerman
0 siblings, 2 replies; 3+ messages in thread
From: Wan Jiabing @ 2021-10-14 7:56 UTC (permalink / raw)
To: Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
Leonardo Bras, Alexey Kardashevskiy, Frederic Barrat,
David Gibson, Wan Jiabing, linuxppc-dev, linux-kernel
Cc: kael_w
Fix following coccicheck warning:
./arch/powerpc/platforms/pseries/iommu.c:924:1-28: WARNING: Function
for_each_node_with_property should have of_node_put() before break
Early exits from for_each_node_with_property should decrement the
node reference counter.
Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
---
arch/powerpc/platforms/pseries/iommu.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c
index 269f61d519c2..c140aa683f66 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -929,8 +929,10 @@ static void find_existing_ddw_windows_named(const char *name)
}
window = ddw_list_new_entry(pdn, dma64);
- if (!window)
+ if (!window) {
+ of_node_put(pdn);
break;
+ }
spin_lock(&dma_win_list_lock);
list_add(&window->list, &dma_win_list);
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/pseries/iommu: Add of_node_put() before break
2021-10-14 7:56 [PATCH] powerpc/pseries/iommu: Add of_node_put() before break Wan Jiabing
@ 2021-10-14 17:32 ` Leonardo Brás
2021-11-02 10:11 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Leonardo Brás @ 2021-10-14 17:32 UTC (permalink / raw)
To: Wan Jiabing, Michael Ellerman, Benjamin Herrenschmidt,
Paul Mackerras, Alexey Kardashevskiy, Frederic Barrat,
David Gibson, linuxppc-dev, linux-kernel
Cc: kael_w
Hello Wan, thank you for this patch.
On Thu, 2021-10-14 at 03:56 -0400, Wan Jiabing wrote:
> Fix following coccicheck warning:
>
> ./arch/powerpc/platforms/pseries/iommu.c:924:1-28: WARNING: Function
> for_each_node_with_property should have of_node_put() before break
>
> Early exits from for_each_node_with_property should decrement the
> node reference counter.
Yeah, it makes sense to me.
for_each_node_with_property calls of_find_node_with_property() at each
step, which ends up calling of_node_put() after using each node.
Introducing this break caused this of_node_put not to happen to the
last node, so IIUC this patch fixes a possible issue if kzalloc() fails
in ddw_list_new_entry().
Another option would be s/break/continue here, but it does not make
sense to keep trying next nodes if there is no memory to allocate for a
struct dma_win (4 pointers).
On the other hard, failing on allocating such small space should not
happen often (if it will ever happen), so a 'continue' here makes code
simpler.
Anyway, FWIW:
Reviewed-by: Leonardo Bras <leobras.c@gmail.com>
Best regards,
Leo
>
> Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
> ---
> arch/powerpc/platforms/pseries/iommu.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/platforms/pseries/iommu.c
> b/arch/powerpc/platforms/pseries/iommu.c
> index 269f61d519c2..c140aa683f66 100644
> --- a/arch/powerpc/platforms/pseries/iommu.c
> +++ b/arch/powerpc/platforms/pseries/iommu.c
> @@ -929,8 +929,10 @@ static void find_existing_ddw_windows_named(const
> char *name)
> }
>
> window = ddw_list_new_entry(pdn, dma64);
> - if (!window)
> + if (!window) {
> + of_node_put(pdn);
> break;
> + }
>
> spin_lock(&dma_win_list_lock);
> list_add(&window->list, &dma_win_list);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/pseries/iommu: Add of_node_put() before break
2021-10-14 7:56 [PATCH] powerpc/pseries/iommu: Add of_node_put() before break Wan Jiabing
2021-10-14 17:32 ` Leonardo Brás
@ 2021-11-02 10:11 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2021-11-02 10:11 UTC (permalink / raw)
To: Wan Jiabing, linux-kernel, Frederic Barrat, Michael Ellerman,
Paul Mackerras, linuxppc-dev, Leonardo Bras, David Gibson,
Alexey Kardashevskiy, Benjamin Herrenschmidt
Cc: kael_w
On Thu, 14 Oct 2021 03:56:04 -0400, Wan Jiabing wrote:
> Fix following coccicheck warning:
>
> ./arch/powerpc/platforms/pseries/iommu.c:924:1-28: WARNING: Function
> for_each_node_with_property should have of_node_put() before break
>
> Early exits from for_each_node_with_property should decrement the
> node reference counter.
>
> [...]
Applied to powerpc/next.
[1/1] powerpc/pseries/iommu: Add of_node_put() before break
https://git.kernel.org/powerpc/c/915b368f6968122fcab31fd6441ed4ba7cc7574c
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-02 11:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-14 7:56 [PATCH] powerpc/pseries/iommu: Add of_node_put() before break Wan Jiabing
2021-10-14 17:32 ` Leonardo Brás
2021-11-02 10:11 ` Michael Ellerman
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).