public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: David Scidmore <dscidmore@xes-inc.com>
To: linux-mtd@lists.infradead.org
Subject: [PATCH] [MTD] mtdchar.c: ioctl always returns 0 as size written for ppc64
Date: Tue, 11 Dec 2007 17:44:30 -0600	[thread overview]
Message-ID: <475F20DE.8010507@xes-inc.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1532 bytes --]


"include/linux/mtd/mtd.h" declares "mtd_oob_ops.retlen" as size_t, which 
is 64 bits on targets with a 64 bit addressing. The MEMWRITEOOB ioctl 
calls copy_to_user() to write it back to "mtd_oob_buf.length", which is 
declared in "include/linux/mtd-abi.h" as uint32_t. Since powerpc is a 
big endian architecture, this only copies the upper 32 bits of the 
address, which is always 0.

Signed-off-by: David Scidmore <dscidmore at xes-inc.com>

------

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 22ed96c..bfc0958 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -483,6 +482,7 @@ static int mtd_ioctl(struct inode *inode, struct 
file *file,
     {
         struct mtd_oob_buf buf;
         struct mtd_oob_ops ops;
+            uint32_t retlen;
 
         if(!(file->f_mode & 2))
             return -EPERM;
@@ -522,8 +522,12 @@ static int mtd_ioctl(struct inode *inode, struct 
file *file,
         buf.start &= ~(mtd->oobsize - 1);
         ret = mtd->write_oob(mtd, buf.start, &ops);
 
-        if (copy_to_user(argp + sizeof(uint32_t), &ops.oobretlen,
-                 sizeof(uint32_t)))
+        if (ops.oobretlen > 0xFFFFFFFFU)
+            ret = -EOVERFLOW;
+        retlen = ops.oobretlen;
+        if (copy_to_user(&((struct mtd_oob_buf *)argp)->length,
+                 &retlen,
+                 sizeof(buf.length)))
             ret = -EFAULT;
 
         kfree(ops.oobbuf);


-- 
David Scidmore
Quality Manager
Extreme Engineering Solutions
608-833-1155 ext 101
www.xes-inc.com



[-- Attachment #2: mtdchar.c.patch --]
[-- Type: text/plain, Size: 842 bytes --]

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 22ed96c..bfc0958 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -483,6 +482,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
 	{
 		struct mtd_oob_buf buf;
 		struct mtd_oob_ops ops;
+	        uint32_t retlen;
 
 		if(!(file->f_mode & 2))
 			return -EPERM;
@@ -522,8 +522,12 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
 		buf.start &= ~(mtd->oobsize - 1);
 		ret = mtd->write_oob(mtd, buf.start, &ops);
 
-		if (copy_to_user(argp + sizeof(uint32_t), &ops.oobretlen,
-				 sizeof(uint32_t)))
+		if (ops.oobretlen > 0xFFFFFFFFU)
+			ret = -EOVERFLOW;
+		retlen = ops.oobretlen;
+		if (copy_to_user(&((struct mtd_oob_buf *)argp)->length,
+				 &retlen,
+				 sizeof(buf.length)))
 			ret = -EFAULT;
 
 		kfree(ops.oobbuf);

                 reply	other threads:[~2007-12-11 23:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=475F20DE.8010507@xes-inc.com \
    --to=dscidmore@xes-inc.com \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox