[PATCH] powerpc/pseries/iommu: Add of_node_put() before break

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

STALE1762d LANDED

Landed in mainline as 915b368f6968 on 2021-10-22.

3 messages, 3 authors, 2021-11-02 · open the first message on its own page

[PATCH] powerpc/pseries/iommu: Add of_node_put() before break

From: Wan Jiabing <hidden>
Date: 2021-10-14 07:57:19

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 <redacted>
---
 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

Re: [PATCH] powerpc/pseries/iommu: Add of_node_put() before break

From: Leonardo Brás <hidden>
Date: 2021-10-14 17:32:55

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 <redacted>


Best regards,
Leo
quoted hunk
Signed-off-by: Wan Jiabing <redacted>
---
 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);

Re: [PATCH] powerpc/pseries/iommu: Add of_node_put() before break

From: Michael Ellerman <hidden>
Date: 2021-11-02 11:40:27

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help