[PATCH 1/2] m25p80: add additional sanity checks for erasure

Paul Fertser fercerpav at gmail.com
Thu Sep 15 07:27:36 EDT 2011


This guards for the cases where the initial offset or byte count is
not aligned with regard to erase block size, thus making it impossible
for erase to do any harm to the nearby sectors.

Signed-off-by: Paul Fertser <fercerpav at gmail.com>
---
 drivers/nor/m25p80.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/nor/m25p80.c b/drivers/nor/m25p80.c
index e6fe75e..6f650a5 100644
--- a/drivers/nor/m25p80.c
+++ b/drivers/nor/m25p80.c
@@ -206,7 +206,9 @@ static ssize_t m25p80_erase(struct cdev *cdev, size_t count, unsigned long offse
 		__func__, "at", (long long)offset, (long long)count);
 
 	/* sanity checks */
-	if (offset + count > flash->size)
+	if ((offset + count > flash->size) ||
+	    (offset % flash->erasesize) ||
+	    ((offset+count) % flash->erasesize))
 		return -EINVAL;
 
 	addr = offset;
-- 
1.7.2.3




More information about the barebox mailing list