Re: [PATCH v4] arm: mvebu: fix null pointer when access

From: Gregory CLEMENT

Date: Wed Mar 18 2026 - 05:39:04 EST


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@xxxxxxxxxx>

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