Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

MIPS: Loongson64: env: Check UARTs passed by LEFI cautiously

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@vger.kernel.org
Reviewed-by: Yao Zi <me@ziyao.cc>
Signed-off-by: Rong Zhang <rongrong@oss.cipunited.com>
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>

authored by

Rong Zhang and committed by
Thomas Bogendoerfer
35d8945b 6de23f81

+17 -1
+17 -1
arch/mips/loongson64/env.c
··· 17 17 #include <linux/dma-map-ops.h> 18 18 #include <linux/export.h> 19 19 #include <linux/libfdt.h> 20 + #include <linux/minmax.h> 20 21 #include <linux/pci_ids.h> 22 + #include <linux/serial_core.h> 21 23 #include <linux/string_choices.h> 22 24 #include <asm/bootinfo.h> 23 25 #include <loongson.h> ··· 108 106 109 107 is_loongson64g = (read_c0_prid() & PRID_IMP_MASK) == PRID_IMP_LOONGSON_64G; 110 108 111 - for (i = 0; i < system->nr_uarts; i++) { 109 + for (i = 0; i < min(system->nr_uarts, MAX_UARTS); i++) { 112 110 uartdev = &system->uarts[i]; 111 + 112 + /* 113 + * Some firmware does not set nr_uarts properly and passes empty 114 + * items. Ignore them silently. 115 + */ 116 + if (uartdev->uart_base == 0) 117 + continue; 118 + 119 + /* Our DT only works with UPIO_MEM. */ 120 + if (uartdev->iotype != UPIO_MEM) { 121 + pr_warn("Ignore UART 0x%llx with iotype %u passed by firmware\n", 122 + uartdev->uart_base, uartdev->iotype); 123 + continue; 124 + } 113 125 114 126 ret = lefi_fixup_fdt_serial(fdt_buf, uartdev->uart_base, 115 127 uartdev->uartclk);