From nobody Thu Apr 9 10:36:23 2026 Received: from va-2-26.ptr.blmpb.com (va-2-26.ptr.blmpb.com [209.127.231.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8BAA373C17 for ; Sun, 15 Mar 2026 17:28:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.231.26 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773595716; cv=none; b=f6V2nPG9WpdGCZgJ6XtYU+KoVkzzuFuUtXzSswgJLNoaXRz8j8ts4bCMYSSKf8SKuMLRP7CAeMru4rkARqbi36CTM1NVE/lwmZaW/f+XHB/aMOWWQ9MRyqVND0fuctOwUhB7Y0k/k/fvT1kwtPoGFSV2OvB7YMWCj7vVDDhhR8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773595716; c=relaxed/simple; bh=DLTV3DEPiYVrighbdNLryHvZFnfJ7hnxF/o0bJ9aoog=; h=Mime-Version:Date:References:To:Subject:Message-Id:In-Reply-To: Content-Type:Cc:From; b=tIO62/2rSRhNKHmqueFhxG4iKXkwkmyzvYHSg76JoDY6m7gFuPOdFa0g006zCsW6S18K1BgNf9H7tQqNXDY/4bb7lglkO6ywUQhbl7DQGSWYS20NNr0lzlLYwVfpBRL7NES0Vd1LXnW8JJ18u7AjyLLPQ9ViuTdyfKqK7QXLkIQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.cipunited.com; spf=pass smtp.mailfrom=oss.cipunited.com; dkim=pass (2048-bit key) header.d=oss.cipunited.com header.i=@oss.cipunited.com header.b=Ef6UNyM5; arc=none smtp.client-ip=209.127.231.26 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.cipunited.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.cipunited.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oss.cipunited.com header.i=@oss.cipunited.com header.b="Ef6UNyM5" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2303200042; d=oss.cipunited.com; t=1773595708; h=from:subject:mime-version:from:date:message-id:subject:to:cc: reply-to:content-type:mime-version:in-reply-to:message-id; bh=NzlBNr0cDChkbzT0CUkDLqCb6VHS1coc88/duTE3E+s=; b=Ef6UNyM5nHmwwPYPBbh4YXQG2Sr8u/g0UovNvBrzsN6gfCJZowJbg3vZPlwrSad47mo9GE vMDrJCzR/exg9RNV5+hgFQW5Wd+xdIUkXFLISx74RJq5lxfwrA6zK06fs3m5QycE5NKUDQ d6+YCxhhdIgVNmCflPt2XQSfmUiKPil1sd9GHDxXsYhPswpWBcVuocBunVSzDlJ8jAB3/v oSdslIfrccEmDJYO3LRMHfslegBWuBvvORrzqy0zQbquMY/Pbz0rMuoLLmEvUCPOkwU4Fp KTODyTBvxXdbgDC9TD7NOqVOw5U+t+8SBeVOcWDKL6hU1L1aLa7ZXKxEP+KCjQ== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Received: from tb ([223.88.91.90]) by smtp.feishu.cn with ESMTPS; Mon, 16 Mar 2026 01:28:25 +0800 Date: Mon, 16 Mar 2026 01:28:22 +0800 X-Lms-Return-Path: References: <20260314211336.408561-1-rongrong@oss.cipunited.com> To: "Huacai Chen" , "Jiaxun Yang" , "Thomas Bogendoerfer" Subject: [PATCH v2] MIPS: Loongson64: env: Check UARTs passed by LEFI cautiously Message-Id: <20260315172824.352412-1-rongrong@oss.cipunited.com> In-Reply-To: <20260314211336.408561-1-rongrong@oss.cipunited.com> Content-Transfer-Encoding: quoted-printable Cc: "Rong Zhang" , "Yao Zi" , , , "Icenowy Zheng" , "Rong Zhang" , From: "Rong Zhang" X-Mailer: git-send-email 2.53.0 X-Original-From: Rong Zhang Content-Type: text/plain; charset="utf-8" Some firmware does not set nr_uarts properly and passes empty items. Iterate at most min(system->nr_uarts, MAX_UARTS) items to prevent out-of-bounds access, and ignore UARTs with addr 0 silently. Meanwhile, our DT only works with UPIO_MEM but theoretically firmware may pass other IO types, so explicitly check against that. Tested on Loongson-LS3A4000-7A1000-NUC-SE. Fixes: 3989ed418483 ("MIPS: Loongson64: env: Fixup serial clock-frequency w= hen using LEFI") Cc: stable@vger.kernel.org Reviewed-by: Yao Zi Signed-off-by: Rong Zhang Reviewed-by: Jiaxun Yang --- Changes in v2: - Sort new includes alphabetically (thanks Yao Zi) --- arch/mips/loongson64/env.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/mips/loongson64/env.c b/arch/mips/loongson64/env.c index 11ddf02d6a15..7abcca7ab4ed 100644 --- a/arch/mips/loongson64/env.c +++ b/arch/mips/loongson64/env.c @@ -17,7 +17,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -106,9 +108,23 @@ static void __init lefi_fixup_fdt(struct system_loongs= on *system) =20 is_loongson64g =3D (read_c0_prid() & PRID_IMP_MASK) =3D=3D PRID_IMP_LOONG= SON_64G; =20 - for (i =3D 0; i < system->nr_uarts; i++) { + for (i =3D 0; i < min(system->nr_uarts, MAX_UARTS); i++) { uartdev =3D &system->uarts[i]; =20 + /* + * Some firmware does not set nr_uarts properly and passes empty + * items. Ignore them silently. + */ + if (uartdev->uart_base =3D=3D 0) + continue; + + /* Our DT only works with UPIO_MEM. */ + if (uartdev->iotype !=3D UPIO_MEM) { + pr_warn("Ignore UART 0x%llx with iotype %u passed by firmware\n", + uartdev->uart_base, uartdev->iotype); + continue; + } + ret =3D lefi_fixup_fdt_serial(fdt_buf, uartdev->uart_base, uartdev->uartclk); /* base-commit: 267594792a71018788af69e836c52e34bb8054af --=20 2.53.0