Re: [PATCH] powerpc/pseries/iommu: Add of_node_put() before break
From: Leonardo Brás <hidden>
Date: 2021-10-14 17:32:55
Also in:
lkml
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 ↗ jump to 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.cb/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(constchar *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);