From nobody Mon Apr 6 14:58:46 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 F343239935E for ; Thu, 19 Mar 2026 05:58:15 +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=1773899899; cv=none; b=o6f5G2g2zCpPEH1IRKfFAb8zKUEobqwVquvF9NIVP1hsfm62F2GAcionkCCbaGh9216XRqMWKtVqJAuUN3C04TvGmYu29VJGOsEM4IjaRmqQOXjcrrTkUPPBv6YqI52y7ofC/9XT5fj6Avrv9DD2C76crN0L0hYmxJnZBUhsBC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773899899; c=relaxed/simple; bh=chqpIEeO9giAalpM5qpeZ96z69Yj3pWsLbOzd4I38pc=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=XAtMVSmGDqIkFOU1U/+RnoleaRPKx9+F4K0EEDV4Q6NWQaIVkHARRwOjummHSW//4QoL+rVvWi193/yNwYZXzZ43F6erFIe/yseN81+pLyOUkly2GB2nENChkSp+vW3Meu2qsks+zU0n9o22D/aCd7wINo9R4BLVsiE95YdKSHU= 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: 9ba07d64235811f1a21c59e7364eecb8-20260319 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.11,REQID:02e35328-799f-4286-bdaf-a4ad7cc8024c,IP:0,U RL:0,TC:0,Content:-25,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:0 X-CID-META: VersionHash:89c9d04,CLOUDID:7f257c5a75804d8fa4d269a7dfa215cc,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:102|850|898,TC:nil,Content:0|15|50,EDM:5 ,IP:nil,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,ARC: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: 9ba07d64235811f1a21c59e7364eecb8-20260319 X-User: lijun01@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 327897219; Thu, 19 Mar 2026 13:58:10 +0800 From: Li Jun To: chenhuacai@kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, lijun01@kylinos.cn Subject: [PATCH v3] Loongarch: env: fix missing NULL checks for kstrdup Date: Thu, 19 Mar 2026 13:58:01 +0800 Message-Id: <20260319055801.4187615-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" 1.Replacing `of_find_node_by_path("/")` with `of_root` avoids multiple calls to `of_node_put()`. 2.Fixes potential kernel oops during early boot when memory allocation fails while parsing CPU model from device tree. --Replacing `of_find_node_by_path("/")` with `of_root`, Fix missing NULL checks. Signed-off-by: Li Jun --- arch/loongarch/kernel/env.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/loongarch/kernel/env.c b/arch/loongarch/kernel/env.c index 841206fde3ab..2afc9b09f139 100644 --- a/arch/loongarch/kernel/env.c +++ b/arch/loongarch/kernel/env.c @@ -15,6 +15,7 @@ #include #include #include +#include =20 u64 efi_system_table; struct loongson_system_configuration loongson_sysconf; @@ -42,16 +43,15 @@ static int __init init_cpu_fullname(void) int cpu, ret; char *cpuname; const char *model; - struct device_node *root; =20 /* Parsing cpuname from DTS model property */ - root =3D of_find_node_by_path("/"); - ret =3D of_property_read_string(root, "model", &model); + ret =3D of_property_read_string(of_root, "model", &model); if (ret =3D=3D 0) { cpuname =3D kstrdup(model, GFP_KERNEL); + if (!cpuname) + return -ENOMEM; loongson_sysconf.cpuname =3D strsep(&cpuname, " "); } - of_node_put(root); =20 if (loongson_sysconf.cpuname && !strncmp(loongson_sysconf.cpuname, "Loong= son", 8)) { for (cpu =3D 0; cpu < NR_CPUS; cpu++) --=20 2.34.1