drivers: flash: at45: improve diagnostics/behavior of erase
Erase can only succeed if the address is sector-aligned, and the span to erase is an integer multiple of the sector size. Validate this before starting the process of erasing things. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
c11ef527b1
commit
204612b3b2
1 changed files with 6 additions and 0 deletions
|
@ -429,6 +429,12 @@ static int spi_flash_at45_erase(struct device *dev, off_t offset, size_t size)
|
|||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Diagnose region errors before starting to erase. */
|
||||
if (((offset % cfg->page_size) != 0)
|
||||
|| ((size % cfg->page_size) != 0)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
acquire(dev);
|
||||
|
||||
if (size == cfg->chip_size) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue