drivers: spi_flash: add erase boundary check and correct an error
Add spi flash erase boundary check. The erase boundary must be 4K-aligned. So, the flash chip will round down an non-4K aligned address to the nearest 4K boundary automatically. As a result of this, the erase area will start from a different address (if the API caller specifies an non-4K alighed address), even though the size of the erased area is the same as what is specified by the API caller. Let's add a boundary check to make sure the starting address (from the API caller) is 4K aligned. Correct an error in the highest address check. Because of the error, the erase api call will fail if the flash's highest address byte is involved. Jira: ZEP-1277 ZEP-1278 Change-Id: I8b6be57cc8f636f94e5fe67d5a492841a8555005 Signed-off-by: Baohong Liu <baohong.liu@intel.com>
This commit is contained in:
parent
8358468fed
commit
a282872c78
|
@ -292,8 +292,8 @@ static int spi_flash_wb_erase(struct device *dev, off_t offset, size_t size)
|
|||
uint32_t new_offset = offset;
|
||||
uint32_t size_remaining = size;
|
||||
|
||||
if ((offset < 0) ||
|
||||
((size + offset) >= CONFIG_SPI_FLASH_W25QXXDV_FLASH_SIZE) ||
|
||||
if ((offset < 0) || ((offset & W25QXXDV_SECTOR_MASK) != 0) ||
|
||||
((size + offset) > CONFIG_SPI_FLASH_W25QXXDV_FLASH_SIZE) ||
|
||||
((size & W25QXXDV_SECTOR_MASK) != 0)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue