From nobody Mon Apr 6 18:29:07 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEC0A36EA8B for ; Wed, 18 Mar 2026 10:31:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773829890; cv=none; b=Euvkf5lfExdkEkaPJhhKZbjvdcTpsTF9DIwOz6j7U9XRn4cIySW0OXHKDxiAgJFjnPro2jQec8xoewVwxUytZAi5RXg26Kd05Y6X2xJukgiwnRBz1E4pkUOYGlvqShjaO0Tu8DFAC4p5W9si0E1x/Q+1W3Sr18h8l4H/n1tPZyU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773829890; c=relaxed/simple; bh=RRRGnwefq65VrXq/7/1NMEn0Z+Vv7bQypFRigcQC8t4=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=g2PQachlwFrxj851Y2cxl7bUufXJtT9jhAoGkqYHpnC6QGTNsWqEN0XL2fM282Ixh0D3gWQeHc8NQydlRHEhcAOQTDJfEgW+v8hOIazJVQXbqTN7I+jn0MNskpyqtNrXMvtRpzbmoDNiqqePb95nlnTBWXmQEFFjmrkdwyGK4dQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 9b4440e222b511f1a21c59e7364eecb8-20260318 X-CTIC-Tags: HR_CTE_8B, HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE HR_FROM_DIGIT_LEN, HR_FROM_NAME, HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER HR_SJ_NOR_SYM, HR_SJ_PHRASE, HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT HR_TO_DOMAIN_COUNT, HR_TO_NO_NAME, IP_TRUSTED, SRC_TRUSTED, DN_TRUSTED SA_TRUSTED, SA_EXISTED, SN_TRUSTED, SN_EXISTED, SPF_NOPASS DKIM_NOPASS, DMARC_NOPASS, CIE_GOOD, CIE_GOOD_SPF, GTI_FG_BS GTI_RG_INFO, GTI_C_BU, AMN_GOOD, ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.11,REQID:fd545c0e-4cd2-4fdc-85ec-820af47da04c,IP:10, URL:0,TC:0,Content:-25,EDM:25,RT:0,SF:-30,FILE:0,BULK:0,RULE:Release_Ham,A CTION:release,TS:-20 X-CID-INFO: VERSION:1.3.11,REQID:fd545c0e-4cd2-4fdc-85ec-820af47da04c,IP:10,UR L:0,TC:0,Content:-25,EDM:25,RT:0,SF:-30,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:-20 X-CID-META: VersionHash:89c9d04,CLOUDID:dddad63e66ba2cb0806f7727fdb4e491,BulkI D:260318183122F62IULKU,BulkQuantity:0,Recheck:0,SF:10|38|66|78|102|127|850 |898,TC:nil,Content:0|15|50,EDM:5,IP:-2,URL:0,File:nil,RT:nil,Bulk:nil,QS: nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,AR C:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 9b4440e222b511f1a21c59e7364eecb8-20260318 X-User: lijun01@kylinos.cn Received: from localhost.localdomain [(183.242.174.22)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 135981028; Wed, 18 Mar 2026 18:31:21 +0800 From: Li Jun To: andrew@lunn.ch, gregory.clement@bootlin.com, sebastian.hesselbarth@gmail.com, linux@armlinux.org.uk, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, lijun01@kylinos.cn Subject: [PATCH] arm: mach: fix missing NULL checks and memory leaks in DT property setup Date: Wed, 18 Mar 2026 18:31:18 +0800 Message-Id: <20260318103118.2731397-1-lijun01@kylinos.cn> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add proper NULL pointer checks after memory allocation calls (kzalloc and kstrdup) in ARM machine-specific device tree property manipulation code. Previously, allocation failures would result in NULL pointer dereferences when accessing the properties, or memory leaks when partial allocations succeeded. Changes: - board-v7.c: Check kzalloc/kstrdup returns, free resources on failure - coherency.c: Check kzalloc/kstrdup returns, free property on failure - versatile.c: Check kstrdup returns, free property on failure. Signed-off-by: Li Jun --- arch/arm/mach-mvebu/board-v7.c | 10 ++++++++++ arch/arm/mach-mvebu/coherency.c | 6 ++++++ arch/arm/mach-versatile/versatile.c | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/arch/arm/mach-mvebu/board-v7.c b/arch/arm/mach-mvebu/board-v7.c index 04ad651d13a0..b56ac48b1759 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; =20 new_compat =3D kzalloc(sizeof(*new_compat), GFP_KERNEL); + if (!new_compat) + return; =20 new_compat->name =3D kstrdup("compatible", GFP_KERNEL); + if (!new_compat->name) { + kfree(new_compat); + return; + } new_compat->length =3D sizeof("marvell,mv78230-a0-i2c"); new_compat->value =3D kstrdup("marvell,mv78230-a0-i2c", GFP_KERNEL); + if (!new_compat->value) { + kfree(new_compat); + return; + } =20 of_update_property(np, new_compat); } diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherenc= y.c index a6b621ff0b87..f9411e16ddbb 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(struc= t device_node *np) struct property *p; =20 p =3D kzalloc(sizeof(*p), GFP_KERNEL); + if (!p) + return; p->name =3D kstrdup("arm,io-coherent", GFP_KERNEL); + if (!p->name) { + kfree(p); + return; + } of_add_property(cache_dn, p); } } diff --git a/arch/arm/mach-versatile/versatile.c b/arch/arm/mach-versatile/= versatile.c index f0c80d4663ca..ee9238a88b8d 100644 --- a/arch/arm/mach-versatile/versatile.c +++ b/arch/arm/mach-versatile/versatile.c @@ -147,7 +147,15 @@ static void __init versatile_dt_pci_init(void) goto out_put_node; =20 newprop->name =3D kstrdup("status", GFP_KERNEL); + if (!newprop->name) { + kfree(newprop); + goto out_put_node; + } newprop->value =3D kstrdup("disabled", GFP_KERNEL); + if (!newprop->value) { + kfree(newprop); + goto out_put_node; + } newprop->length =3D sizeof("disabled"); of_update_property(np, newprop); =20 --=20 2.25.1