[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <932cf31f-84ca-4298-832c-98579f8b37bd@gaisler.com>
Date: Fri, 19 Sep 2025 20:08:22 +0200
From: Andreas Larsson <andreas@...sler.com>
To: Ma Ke <make24@...as.ac.cn>, davem@...emloft.net
Cc: akpm@...ux-foundation.org, sparclinux@...r.kernel.org,
linux-kernel@...r.kernel.org, stable@...r.kernel.org
Subject: Re: [PATCH v2 RESEND] sparc: fix error handling in scan_one_device()
On 2025-07-18 11:32, Ma Ke wrote:
> Once of_device_register() failed, we should call put_device() to
> decrement reference count for cleanup. Or it could cause memory leak.
> So fix this by calling put_device(), then the name can be freed in
> kobject_cleanup().
>
> Calling path: of_device_register() -> of_device_add() -> device_add().
> As comment of device_add() says, 'if device_add() succeeds, you should
> call device_del() when you want to get rid of it. If device_add() has
> not succeeded, use only put_device() to drop the reference count'.
>
> Found by code review.
>
> Cc: stable@...r.kernel.org
> Fixes: cf44bbc26cf1 ("[SPARC]: Beginnings of generic of_device framework.")
> Signed-off-by: Ma Ke <make24@...as.ac.cn>
> ---
> Changes in v2:
> - retained kfree() manually due to the lack of a release callback function.
> ---
> arch/sparc/kernel/of_device_64.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/sparc/kernel/of_device_64.c b/arch/sparc/kernel/of_device_64.c
> index f98c2901f335..f53092b07b9e 100644
> --- a/arch/sparc/kernel/of_device_64.c
> +++ b/arch/sparc/kernel/of_device_64.c
> @@ -677,6 +677,7 @@ static struct platform_device * __init scan_one_device(struct device_node *dp,
>
> if (of_device_register(op)) {
> printk("%pOF: Could not register of device.\n", dp);
> + put_device(&op->dev);
> kfree(op);
> op = NULL;
> }
Thank you and sorry for the late feedback, but could you also fix the
same problem in arch/sparc/kernel/of_device_32.c?
Thanks,
Andreas
Powered by blists - more mailing lists