lkml.org 
[lkml]   [2021]   [Oct]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] powerpc/pseries/iommu: Add of_node_put() before break
From
Date
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);


\
 
 \ /
  Last update: 2021-10-14 19:33    [W:0.051 / U:0.528 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site