Merge "common: sf_command: Add ram region validation"

This commit is contained in:
Linux Build Service Account 2021-02-08 02:43:34 -08:00 committed by Gerrit - the friendly Code Review server
commit c7465a6b38

View file

@ -19,6 +19,8 @@
#include <asm/io.h>
#include <dm/device-internal.h>
DECLARE_GLOBAL_DATA_PTR;
static struct spi_flash *flash;
/*
@ -265,6 +267,7 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
int ret = 1;
int dev = 0;
loff_t offset, len, maxsize;
unsigned long sram_end = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
if (argc < 3)
return -1;
@ -283,6 +286,16 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
argv[0], flash->size);
return 1;
}
/* Validate DDR region address */
if ((addr < CONFIG_SYS_SDRAM_BASE) || (addr > (sram_end - 1))) {
puts("Invalid RAM address \n");
return 1;
}
if ((addr + len) > sram_end) {
puts("No space available\n");
return 1;
}
buf = map_physmem(addr, len, MAP_WRBACK);
if (!buf) {