Re: [PATCH] MIPS: Loongson64: env: Check UARTs passed by LEFI cautiously

From: Yao Zi

Date: Sun Mar 15 2026 - 07:42:08 EST


On Sun, Mar 15, 2026 at 05:13:29AM +0800, Rong Zhang wrote:
> 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 when using LEFI")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Rong Zhang <rongrong@xxxxxxxxxxxxxxxxx>
> ---
> 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..c6b99b3740ea 100644
> --- a/arch/mips/loongson64/env.c
> +++ b/arch/mips/loongson64/env.c
> @@ -17,8 +17,10 @@
> #include <linux/dma-map-ops.h>
> #include <linux/export.h>
> #include <linux/libfdt.h>
> +#include <linux/minmax.h>
> #include <linux/pci_ids.h>
> #include <linux/string_choices.h>
> +#include <linux/serial_core.h>

Maybe putting this before string_choices.h to keep the headers sorted
at least locally? Though the order is already broken, this may minimize
the diff if someone is willing to sort them later.

> #include <asm/bootinfo.h>
> #include <loongson.h>
> #include <boot_param.h>

Reviewed-by: Yao Zi <me@xxxxxxxx>

Thanks,
Yao Zi