public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] arm: mvebu: fix null pointer when access
@ 2026-03-18  8:59 Li Jun
  2026-03-18  9:33 ` Gregory CLEMENT
  2026-03-18 13:38 ` Andrew Lunn
  0 siblings, 2 replies; 3+ messages in thread
From: Li Jun @ 2026-03-18  8:59 UTC (permalink / raw)
  To: andrew, gregory.clement, sebastian.hesselbarth, linux,
	linux-arm-kernel, linux-kernel, lijun01

the kzalloc&kstrdup may return null pointer, will cause kernel panic.

-Fix null pointer.

Signed-off-by: Li Jun <lijun01@kylinos.cn>
---
 arch/arm/mach-mvebu/board-v7.c      | 10 ++++++++++
 arch/arm/mach-mvebu/coherency.c     |  6 ++++++
 arch/arm/mach-mxs/mach-mxs.c        |  4 ++--
 arch/arm/mach-versatile/versatile.c |  6 ++++++
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-mvebu/board-v7.c b/arch/arm/mach-mvebu/board-v7.c
index 04ad651d13a0..a3b1aa48162b 100644
--- a/arch/arm/mach-mvebu/board-v7.c
+++ b/arch/arm/mach-mvebu/board-v7.c
@@ -128,11 +128,21 @@ static void __init i2c_quirk(void)
 		struct property *new_compat;
 
 		new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL);
+		if (!new_compat)
+			return -ENOMEM;
 
 		new_compat->name = kstrdup("compatible", GFP_KERNEL);
+		if (!mew_compat->name) {
+			kfree(new_compat);
+			return -ENOMEM;
+		}
 		new_compat->length = sizeof("marvell,mv78230-a0-i2c");
 		new_compat->value = kstrdup("marvell,mv78230-a0-i2c",
 						GFP_KERNEL);
+		if (!mew_compat->value) {
+			kfree(new_compat);
+			return -ENOMEM;
+		}
 
 		of_update_property(np, new_compat);
 	}
diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
index a6b621ff0b87..2c1668f3174c 100644
--- a/arch/arm/mach-mvebu/coherency.c
+++ b/arch/arm/mach-mvebu/coherency.c
@@ -191,7 +191,13 @@ static void __init armada_375_380_coherency_init(struct device_node *np)
 		struct property *p;
 
 		p = kzalloc(sizeof(*p), GFP_KERNEL);
+		if (!p)
+			return -ENOMEM;
 		p->name = kstrdup("arm,io-coherent", GFP_KERNEL);
+		if (!p->name) {
+			kfree(p);
+			return -ENOMEM;
+		}
 		of_add_property(cache_dn, p);
 	}
 }
diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c
index 6e017fa306c8..16506d9392b4 100644
--- a/arch/arm/mach-mxs/mach-mxs.c
+++ b/arch/arm/mach-mxs/mach-mxs.c
@@ -178,14 +178,14 @@ static void __init update_fec_mac_prop(enum mac_oui oui)
 
 		newmac = kzalloc(sizeof(*newmac) + 6, GFP_KERNEL);
 		if (!newmac)
-			return;
+			return -ENOMEM;
 		newmac->value = newmac + 1;
 		newmac->length = 6;
 
 		newmac->name = kstrdup("local-mac-address", GFP_KERNEL);
 		if (!newmac->name) {
 			kfree(newmac);
-			return;
+			return -ENOMEM;
 		}
 
 		/*
diff --git a/arch/arm/mach-versatile/versatile.c b/arch/arm/mach-versatile/versatile.c
index f0c80d4663ca..07f2a299c770 100644
--- a/arch/arm/mach-versatile/versatile.c
+++ b/arch/arm/mach-versatile/versatile.c
@@ -147,7 +147,13 @@ static void __init versatile_dt_pci_init(void)
 		goto out_put_node;
 
 	newprop->name = kstrdup("status", GFP_KERNEL);
+	if (!newprop->name)
+		goto out_put_node;
+
 	newprop->value = kstrdup("disabled", GFP_KERNEL);
+	if (!newprop->value)
+		goto out_put_node;
+
 	newprop->length = sizeof("disabled");
 	of_update_property(np, newprop);
 
-- 
2.25.1


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

* Re: [PATCH v4] arm: mvebu: fix null pointer when access
  2026-03-18  8:59 [PATCH v4] arm: mvebu: fix null pointer when access Li Jun
@ 2026-03-18  9:33 ` Gregory CLEMENT
  2026-03-18 13:38 ` Andrew Lunn
  1 sibling, 0 replies; 3+ messages in thread
From: Gregory CLEMENT @ 2026-03-18  9:33 UTC (permalink / raw)
  To: Li Jun, andrew, sebastian.hesselbarth, linux, linux-arm-kernel,
	linux-kernel, lijun01

Hello Li Jun,

This patch looks very broken, see
https://sashiko.dev/#/patchset/20260318085923.2610585-1-lijun01%40kylinos.cn


> the kzalloc&kstrdup may return null pointer, will cause kernel panic.
>
> -Fix null pointer.

You could improve this commit log.

>
> Signed-off-by: Li Jun <lijun01@kylinos.cn>

When you iterate you should add a changelog here.

Gregory

> ---
>  arch/arm/mach-mvebu/board-v7.c      | 10 ++++++++++
>  arch/arm/mach-mvebu/coherency.c     |  6 ++++++
>  arch/arm/mach-mxs/mach-mxs.c        |  4 ++--
>  arch/arm/mach-versatile/versatile.c |  6 ++++++
>  4 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/mach-mvebu/board-v7.c b/arch/arm/mach-mvebu/board-v7.c
> index 04ad651d13a0..a3b1aa48162b 100644
> --- a/arch/arm/mach-mvebu/board-v7.c
> +++ b/arch/arm/mach-mvebu/board-v7.c
> @@ -128,11 +128,21 @@ static void __init i2c_quirk(void)
>  		struct property *new_compat;
>  
>  		new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL);
> +		if (!new_compat)
> +			return -ENOMEM;
>  
>  		new_compat->name = kstrdup("compatible", GFP_KERNEL);
> +		if (!mew_compat->name) {
> +			kfree(new_compat);
> +			return -ENOMEM;
> +		}
>  		new_compat->length = sizeof("marvell,mv78230-a0-i2c");
>  		new_compat->value = kstrdup("marvell,mv78230-a0-i2c",
>  						GFP_KERNEL);
> +		if (!mew_compat->value) {
> +			kfree(new_compat);
> +			return -ENOMEM;
> +		}
>  
>  		of_update_property(np, new_compat);
>  	}
> diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
> index a6b621ff0b87..2c1668f3174c 100644
> --- a/arch/arm/mach-mvebu/coherency.c
> +++ b/arch/arm/mach-mvebu/coherency.c
> @@ -191,7 +191,13 @@ static void __init armada_375_380_coherency_init(struct device_node *np)
>  		struct property *p;
>  
>  		p = kzalloc(sizeof(*p), GFP_KERNEL);
> +		if (!p)
> +			return -ENOMEM;
>  		p->name = kstrdup("arm,io-coherent", GFP_KERNEL);
> +		if (!p->name) {
> +			kfree(p);
> +			return -ENOMEM;
> +		}
>  		of_add_property(cache_dn, p);
>  	}
>  }
> diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c
> index 6e017fa306c8..16506d9392b4 100644
> --- a/arch/arm/mach-mxs/mach-mxs.c
> +++ b/arch/arm/mach-mxs/mach-mxs.c
> @@ -178,14 +178,14 @@ static void __init update_fec_mac_prop(enum mac_oui oui)
>  
>  		newmac = kzalloc(sizeof(*newmac) + 6, GFP_KERNEL);
>  		if (!newmac)
> -			return;
> +			return -ENOMEM;
>  		newmac->value = newmac + 1;
>  		newmac->length = 6;
>  
>  		newmac->name = kstrdup("local-mac-address", GFP_KERNEL);
>  		if (!newmac->name) {
>  			kfree(newmac);
> -			return;
> +			return -ENOMEM;
>  		}
>  
>  		/*
> diff --git a/arch/arm/mach-versatile/versatile.c b/arch/arm/mach-versatile/versatile.c
> index f0c80d4663ca..07f2a299c770 100644
> --- a/arch/arm/mach-versatile/versatile.c
> +++ b/arch/arm/mach-versatile/versatile.c
> @@ -147,7 +147,13 @@ static void __init versatile_dt_pci_init(void)
>  		goto out_put_node;
>  
>  	newprop->name = kstrdup("status", GFP_KERNEL);
> +	if (!newprop->name)
> +		goto out_put_node;
> +
>  	newprop->value = kstrdup("disabled", GFP_KERNEL);
> +	if (!newprop->value)
> +		goto out_put_node;
> +
>  	newprop->length = sizeof("disabled");
>  	of_update_property(np, newprop);
>  
> -- 
> 2.25.1
>

-- 
Grégory CLEMENT, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [PATCH v4] arm: mvebu: fix null pointer when access
  2026-03-18  8:59 [PATCH v4] arm: mvebu: fix null pointer when access Li Jun
  2026-03-18  9:33 ` Gregory CLEMENT
@ 2026-03-18 13:38 ` Andrew Lunn
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2026-03-18 13:38 UTC (permalink / raw)
  To: Li Jun
  Cc: gregory.clement, sebastian.hesselbarth, linux, linux-arm-kernel,
	linux-kernel

On Wed, Mar 18, 2026 at 04:59:23PM +0800, Li Jun wrote:
> the kzalloc&kstrdup may return null pointer, will cause kernel panic.
> 
> -Fix null pointer.
> 
> Signed-off-by: Li Jun <lijun01@kylinos.cn>
> ---
>  arch/arm/mach-mvebu/board-v7.c      | 10 ++++++++++
>  arch/arm/mach-mvebu/coherency.c     |  6 ++++++
>  arch/arm/mach-mxs/mach-mxs.c        |  4 ++--
>  arch/arm/mach-versatile/versatile.c |  6 ++++++

4 versions in less than 24 hours....

Also, please don't mix different machine architectures together in one
patch. They have different Maintainers.

> diff --git a/arch/arm/mach-mvebu/board-v7.c b/arch/arm/mach-mvebu/board-v7.c
> index 04ad651d13a0..a3b1aa48162b 100644
> --- a/arch/arm/mach-mvebu/board-v7.c
> +++ b/arch/arm/mach-mvebu/board-v7.c
> @@ -128,11 +128,21 @@ static void __init i2c_quirk(void)
>  		struct property *new_compat;
>  
>  		new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL);
> +		if (!new_compat)
> +			return -ENOMEM;

When you compiled this, did you get any sort of warning? As you can
see above i2c_quirk() is a void function.

    Andrew

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

end of thread, other threads:[~2026-03-18 13:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-18  8:59 [PATCH v4] arm: mvebu: fix null pointer when access Li Jun
2026-03-18  9:33 ` Gregory CLEMENT
2026-03-18 13:38 ` Andrew Lunn

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