[PATCH] [MTD] [CORE]: Fix MEMGETOOBSEL and ECCGETLAYOUT ioctls

Ricard Wanderlof ricard.wanderlof at axis.com
Tue Oct 17 11:27:11 EDT 2006


Hi,

This is my first patch submission, so please correct me if I've done 
anything stupid or just plain wrong. :-)


1. The ECCGETLAYOUT ioctl copy_to_user() call has a superfluous '&' 
causing the resulting information to be garbage rather than the intended 
mtd->ecclayout.

2. The MEMGETOOBSEL misses copying mtd->ecclayout->eccbytes so the
resulting field of the returned structure contains garbage.


From: Ricard Wanderlof <ricardw at axis.com>
Signed-off-by: Ricard Wanderlof <ricardw at axis.com>


--- a/drivers/mtd/mtdchar.c	2006-10-17 17:10:45.929965640 +0200
+++ b/drivers/mtd/mtdchar.c	2006-10-17 17:12:10.000000000 +0200
@@ -616,6 +616,7 @@
  		memcpy(&oi.eccpos, mtd->ecclayout->eccpos, sizeof(oi.eccpos));
  		memcpy(&oi.oobfree, mtd->ecclayout->oobfree,
  		       sizeof(oi.oobfree));
+		oi.eccbytes = mtd->ecclayout->eccbytes;

  		if (copy_to_user(argp, &oi, sizeof(struct nand_oobinfo)))
  			return -EFAULT;
@@ -715,7 +716,7 @@
  		if (!mtd->ecclayout)
  			return -EOPNOTSUPP;

-		if (copy_to_user(argp, &mtd->ecclayout,
+		if (copy_to_user(argp, mtd->ecclayout,
  				 sizeof(struct nand_ecclayout)))
  			return -EFAULT;
  		break;

--
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30
-------------- next part --------------
--- a/drivers/mtd/mtdchar.c	2006-10-17 17:10:45.929965640 +0200
+++ b/drivers/mtd/mtdchar.c	2006-10-17 17:12:10.000000000 +0200
@@ -616,6 +616,7 @@
 		memcpy(&oi.eccpos, mtd->ecclayout->eccpos, sizeof(oi.eccpos));
 		memcpy(&oi.oobfree, mtd->ecclayout->oobfree,
 		       sizeof(oi.oobfree));
+		oi.eccbytes = mtd->ecclayout->eccbytes;
 
 		if (copy_to_user(argp, &oi, sizeof(struct nand_oobinfo)))
 			return -EFAULT;
@@ -715,7 +716,7 @@
 		if (!mtd->ecclayout)
 			return -EOPNOTSUPP;
 
-		if (copy_to_user(argp, &mtd->ecclayout,
+		if (copy_to_user(argp, mtd->ecclayout,
 				 sizeof(struct nand_ecclayout)))
 			return -EFAULT;
 		break;


More information about the linux-mtd mailing list