]> git.openpandora.org Git - pandora-u-boot.git/commitdiff
stm32mp: fix array bounds checks
authorPatrice Chotard <patrice.chotard@foss.st.com>
Tue, 10 Feb 2026 14:57:35 +0000 (15:57 +0100)
committerPatrice Chotard <patrice.chotard@foss.st.com>
Tue, 24 Feb 2026 13:12:34 +0000 (14:12 +0100)
Fix index check against array size. If that index is equal
to the array size, we'll access one-past-the-end of the array.

Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
arch/arm/mach-stm32mp/stm32mp2/cpu.c

index e081dc605b84a69f86364da913fa21df62038a51..a8a6bcf8ab41c6bc37b4a5523f85d4a775fc9b7b 100644 (file)
@@ -148,7 +148,7 @@ static void setup_boot_mode(void)
                  __func__, boot_ctx, boot_mode, instance, forced_mode);
        switch (boot_mode & TAMP_BOOT_DEVICE_MASK) {
        case BOOT_SERIAL_UART:
-               if (instance > ARRAY_SIZE(serial_addr))
+               if (instance >= ARRAY_SIZE(serial_addr))
                        break;
                /* serial : search associated node in devicetree */
                sprintf(cmd, "serial@%x", serial_addr[instance]);
@@ -178,7 +178,7 @@ static void setup_boot_mode(void)
                break;
        case BOOT_FLASH_SD:
        case BOOT_FLASH_EMMC:
-               if (instance > ARRAY_SIZE(sdmmc_addr))
+               if (instance >= ARRAY_SIZE(sdmmc_addr))
                        break;
                /* search associated sdmmc node in devicetree */
                sprintf(cmd, "mmc@%x", sdmmc_addr[instance]);