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:
Peter Bigot 2020-05-28 11:20:24 -05:00 committed by Maureen Helm
commit 204612b3b2

View file

@ -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) {