public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] powerpc: 82xx: fix uninitialized pointers with free attribute
@ 2025-11-16 14:25 Ally Heev
  2025-11-22 13:03 ` Krzysztof Kozlowski
  2025-12-02 16:01 ` Christophe Leroy (CS GROUP)
  0 siblings, 2 replies; 3+ messages in thread
From: Ally Heev @ 2025-11-16 14:25 UTC (permalink / raw)
  To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy, Krzysztof Kozlowski
  Cc: linuxppc-dev, linux-kernel, Dan Carpenter, Ally Heev

Uninitialized pointers with `__free` attribute can cause undefined
behavior 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>
---
Changes in v2:
- updated commit description
- Link to v1: https://lore.kernel.org/r/20251104-aheev-uninitialized-free-attr-km82xx-v1-1-903be69f2cd4@gmail.com
---
 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] 3+ messages in thread

* Re: [PATCH v2] powerpc: 82xx: fix uninitialized pointers with free attribute
  2025-11-16 14:25 [PATCH v2] powerpc: 82xx: fix uninitialized pointers with free attribute Ally Heev
@ 2025-11-22 13:03 ` Krzysztof Kozlowski
  2025-12-02 16:01 ` Christophe Leroy (CS GROUP)
  1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-22 13:03 UTC (permalink / raw)
  To: Ally Heev, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy
  Cc: linuxppc-dev, linux-kernel, Dan Carpenter

On 16/11/2025 15:25, Ally Heev wrote:
> Uninitialized pointers with `__free` attribute can cause undefined
> behavior 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>
> ---
> Changes in v2:
> - updated commit description
> - Link to v1: https://lore.kernel.org/r/20251104-aheev-uninitialized-free-attr-km82xx-v1-1-903be69f2cd4@gmail.com
> ---


This is the correct approach and the original patch should have never
been amended while applying.

Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>

Best regards,
Krzysztof

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

* Re: [PATCH v2] powerpc: 82xx: fix uninitialized pointers with free attribute
  2025-11-16 14:25 [PATCH v2] powerpc: 82xx: fix uninitialized pointers with free attribute Ally Heev
  2025-11-22 13:03 ` Krzysztof Kozlowski
@ 2025-12-02 16:01 ` Christophe Leroy (CS GROUP)
  1 sibling, 0 replies; 3+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2025-12-02 16:01 UTC (permalink / raw)
  To: Ally Heev, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Krzysztof Kozlowski
  Cc: linuxppc-dev, linux-kernel, Dan Carpenter



Le 16/11/2025 à 15:25, Ally Heev a écrit :
> [Vous ne recevez pas souvent de courriers de allyheev@gmail.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]
> 
> Uninitialized pointers with `__free` attribute can cause undefined
> behavior 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://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2FaPiG_F5EBQUjZqsl%40stanley.mountain%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cffef37bc0fba4c2c5d4d08de251c0ccd%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638988999594823658%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=spMNfEUgHH43vUqoyG3EAs99MzCC5bMnlWUvsBa0o6Y%3D&reserved=0
> Signed-off-by: Ally Heev <allyheev@gmail.com>

Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>

Fixes: 4aa5cc1e0012 ("powerpc-km82xx.c: replace of_node_put() with __free")

> ---
> Changes in v2:
> - updated commit description
> - Link to v1: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fr%2F20251104-aheev-uninitialized-free-attr-km82xx-v1-1-903be69f2cd4%40gmail.com&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cffef37bc0fba4c2c5d4d08de251c0ccd%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638988999594847235%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=ehJtEL%2F3GHIwW2mPuiD730V%2FDgkuDvudK2gM%2F72QIDE%3D&reserved=0
> ---
>   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	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-02 16:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-16 14:25 [PATCH v2] powerpc: 82xx: fix uninitialized pointers with free attribute Ally Heev
2025-11-22 13:03 ` Krzysztof Kozlowski
2025-12-02 16:01 ` Christophe Leroy (CS GROUP)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox