linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc: 82xx: fix uninitialized pointers with free attr
@ 2025-11-04 11:28 Ally Heev
  2025-11-05  6:40 ` Krzysztof Kozlowski
  0 siblings, 1 reply; 2+ messages in thread
From: Ally Heev @ 2025-11-04 11:28 UTC (permalink / raw)
  To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy
  Cc: linuxppc-dev, linux-kernel, Dan Carpenter, Ally Heev

Uninitialized pointers with `__free` attribute can cause undefined
behaviour as the memory allocated to the pointer is freed automatically
when the pointer goes out of scope

powerpc/km82xx doesn't have any bugs related to this as of now, but,
it is better to initialize and assign pointers with `__free` attribute
in one statement to ensure proper scope-based cleanup

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/all/aPiG_F5EBQUjZqsl@stanley.mountain/
Signed-off-by: Ally Heev <allyheev@gmail.com>
---
Testing:
Successfully compiled the kernel with `allmodconfig`
---
 arch/powerpc/platforms/82xx/km82xx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/82xx/km82xx.c b/arch/powerpc/platforms/82xx/km82xx.c
index 99f0f0f4187672614f4f8ad46ab7906f7ad8078b..4ad223525e893c0de15540db2b2c4d239d6d841e 100644
--- a/arch/powerpc/platforms/82xx/km82xx.c
+++ b/arch/powerpc/platforms/82xx/km82xx.c
@@ -27,8 +27,8 @@
 
 static void __init km82xx_pic_init(void)
 {
-	struct device_node *np __free(device_node);
-	np = of_find_compatible_node(NULL, NULL, "fsl,pq2-pic");
+	struct device_node *np __free(device_node) = of_find_compatible_node(NULL,
+		NULL, "fsl,pq2-pic");
 
 	if (!np) {
 		pr_err("PIC init: can not find cpm-pic node\n");

---
base-commit: c9cfc122f03711a5124b4aafab3211cf4d35a2ac
change-id: 20251104-aheev-uninitialized-free-attr-km82xx-00c4cb7c3d69

Best regards,
-- 
Ally Heev <allyheev@gmail.com>



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] powerpc: 82xx: fix uninitialized pointers with free attr
  2025-11-04 11:28 [PATCH] powerpc: 82xx: fix uninitialized pointers with free attr Ally Heev
@ 2025-11-05  6:40 ` Krzysztof Kozlowski
  0 siblings, 0 replies; 2+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-05  6:40 UTC (permalink / raw)
  To: Ally Heev, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy
  Cc: linuxppc-dev, linux-kernel, Dan Carpenter

On 04/11/2025 12:28, Ally Heev wrote:
> Uninitialized pointers with `__free` attribute can cause undefined
> behaviour as the memory allocated to the pointer is freed automatically
> when the pointer goes out of scope
> 
> powerpc/km82xx doesn't have any bugs related to this as of now, but,
> it is better to initialize and assign pointers with `__free` attribute
> in one statement to ensure proper scope-based cleanup
> 
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/all/aPiG_F5EBQUjZqsl@stanley.mountain/
> Signed-off-by: Ally Heev <allyheev@gmail.com>
> ---
> Testing:
> Successfully compiled the kernel with `allmodconfig`
> ---
>  arch/powerpc/platforms/82xx/km82xx.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/82xx/km82xx.c b/arch/powerpc/platforms/82xx/km82xx.c
> index 99f0f0f4187672614f4f8ad46ab7906f7ad8078b..4ad223525e893c0de15540db2b2c4d239d6d841e 100644
> --- a/arch/powerpc/platforms/82xx/km82xx.c
> +++ b/arch/powerpc/platforms/82xx/km82xx.c
> @@ -27,8 +27,8 @@
>  
>  static void __init km82xx_pic_init(void)
>  {
> -	struct device_node *np __free(device_node);
> -	np = of_find_compatible_node(NULL, NULL, "fsl,pq2-pic");
> +	struct device_node *np __free(device_node) = of_find_compatible_node(NULL,
> +		NULL, "fsl,pq2-pic");
>  


Original patch was correct:
https://lore.kernel.org/all/20240709143553.117053-1-david.hunter.linux@gmail.com/

It is the maintainer who decided to break it while applying, not
following clear cleanup.h recommendations and not giving a chance to
object to people. :/

So now we have a fixing commit.

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-05  6:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-04 11:28 [PATCH] powerpc: 82xx: fix uninitialized pointers with free attr Ally Heev
2025-11-05  6:40 ` Krzysztof Kozlowski

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).