From f118d1a1037d9f5540fd88763495f3676cab36d1 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 3 Sep 2008 14:04:15 +0200 Subject: NAND: fix reading of bad block aware devices When reading from bad block aware devices we must make sure not to read beyond eraseblock boundaries. Signed-off-by: Sascha Hauer --- commands/nand.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/commands/nand.c b/commands/nand.c index 1e240b6da4..d3f69b801e 100644 --- a/commands/nand.c +++ b/commands/nand.c @@ -62,7 +62,8 @@ static ssize_t nand_bb_read(struct device_d *dev, void *buf, size_t count, bb->offset += bb->info.erasesize; } - now = min(count, bb->info.erasesize); + now = min(count, (size_t)(bb->info.erasesize - + (bb->offset % bb->info.erasesize))); ret = dev_read(bb->physdev, buf, now, bb->offset, flags); if (ret < 0) return ret; @@ -93,7 +94,8 @@ static ssize_t nand_bb_write(struct device_d *dev, const void *buf, size_t count bb->offset += bb->info.erasesize; } - now = min(count, bb->info.erasesize); + now = min(count, (size_t)(bb->info.erasesize - + (bb->offset % bb->info.erasesize))); ret = dev_write(bb->physdev, buf, now, bb->offset, flags); if (ret < 0) return ret; -- cgit v1.2.3