summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2008-09-03 14:04:15 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2008-09-03 14:04:15 +0200
commitf118d1a1037d9f5540fd88763495f3676cab36d1 (patch)
tree3c950c658d353f3ca5a4b14f9f3cec8e53689282
parent9fc8c4e9bb3d1db5f0d820c0adff1c3a9c8758ee (diff)
downloadbarebox-f118d1a1037d9f5540fd88763495f3676cab36d1.tar.gz
barebox-f118d1a1037d9f5540fd88763495f3676cab36d1.tar.xz
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 <s.hauer@pengutronix.de>
-rw-r--r--commands/nand.c6
1 files 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;