[MTD] [NAND] S3C2410: Deal with unaligned lengths in S3C2440 buffer read/write

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Mon Jun 8 07:59:02 EDT 2009


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=dea2aa6fd7d46c43c840ad77905f3c161d5bc59d
Commit:     dea2aa6fd7d46c43c840ad77905f3c161d5bc59d
Parent:     9db41f9edcb87ae050fcb171c44be7f212728d54
Author:     Ben Dooks <ben-linux at fluff.org>
AuthorDate: Sat May 30 18:30:18 2009 +0100
Committer:  Ben Dooks <ben-linux at fluff.org>
CommitDate: Mon Jun 8 12:10:36 2009 +0100

    [MTD] [NAND] S3C2410: Deal with unaligned lengths in S3C2440 buffer read/write
    
    Add code to deal with fractional lengths, as reported by
    Werner Almesberger. Re-work of his original patch.
    
    Signed-off-by: Ben Dooks <ben-linux at fluff.org>
---
 drivers/mtd/nand/s3c2410.c |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index d315b51..8a7f960 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -584,7 +584,16 @@ static void s3c2410_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 static void s3c2440_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 {
 	struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
-	readsl(info->regs + S3C2440_NFDATA, buf, len / 4);
+
+	readsl(info->regs + S3C2440_NFDATA, buf, len >> 2);
+
+	/* cleanup if we've got less than a word to do */
+	if (len & 3) {
+		buf += len & ~3;
+
+		for (; len & 3; len--)
+			*buf++ = readb(info->regs + S3C2440_NFDATA);
+	}
 }
 
 static void s3c2410_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
@@ -596,7 +605,16 @@ static void s3c2410_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int
 static void s3c2440_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
 {
 	struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
-	writesl(info->regs + S3C2440_NFDATA, buf, len / 4);
+
+	writesl(info->regs + S3C2440_NFDATA, buf, len >> 2);
+
+	/* cleanup any fractional write */
+	if (len & 3) {
+		buf += len & ~3;
+
+		for (; len & 3; len--, buf++)
+			writeb(*buf, info->regs + S3C2440_NFDATA);
+	}
 }
 
 /* cpufreq driver support */



More information about the linux-mtd-cvs mailing list