[PATCH 4/6] nor m25p80: align start and end to erase blocks

Sascha Hauer s.hauer at pengutronix.de
Tue Jul 31 13:59:14 EDT 2012


The erase command normally makes sure that the selected area is erased,
therefore align the parameters to eraseblock boundaries.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/nor/m25p80.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/nor/m25p80.c b/drivers/nor/m25p80.c
index 0f3bcd1..7ff4546 100644
--- a/drivers/nor/m25p80.c
+++ b/drivers/nor/m25p80.c
@@ -205,8 +205,9 @@ static ssize_t m25p80_erase(struct cdev *cdev, size_t count, loff_t offset)
 	if (offset + count > flash->size)
 		return -EINVAL;
 
-	addr = offset;
-	len = count;
+	/* Align start and len to erase blocks */
+	addr = offset & ~(flash->erasesize - 1);
+	len = ALIGN(offset + count, flash->erasesize) - addr;
 
 	/* whole-chip erase? */
 	if (len == flash->size) {
-- 
1.7.10.4




More information about the barebox mailing list