aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/mtdchar.c
diff options
context:
space:
mode:
authorBrian Norris <computersforpeace@gmail.com>2010-08-24 21:12:00 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2010-10-24 18:37:24 -0400
commitcc26c3cd3d1cf40a07f2b19ac4c53d517bee52a5 (patch)
tree664c422944f780a1cc99f872714eeb339efef7ef /drivers/mtd/mtdchar.c
parentf4a2da0cd522a3b805ff2386c14912945bf990c7 (diff)
mtd: nand: expand nand_ecc_layout, deprecate ioctl ECCGETLAYOUT
struct nand_ecclayout is too small for many new chips; OOB regions can be as large as 448 bytes and may increase more in the future. Thus, copying that struct to user-space with the ECCGETLAYOUT ioctl is not a good idea; the ioctl would have to be updated every time there's a change to the current largest size. Instead, the old nand_ecclayout is renamed to nand_ecclayout_user and a new struct nand_ecclayout is created that can accomodate larger sizes and expand without affecting the user-space. struct nand_ecclayout can still be used in board drivers without modification -- at least for now. A new function is provided to convert from the new to the old in order to allow the deprecated ioctl to continue to work with truncated data. Perhaps the ioctl, the conversion process, and the struct nand_ecclayout_user can be removed altogether in the future. Note: There are comments in nand/davinci_nand.c::nand_davinci_probe() regarding this issue; this driver (and maybe others) can be updated to account for extra space. All kernel drivers can use the expanded nand_ecclayout as a drop-in replacement and ignore its benefits. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/mtdchar.c')
-rw-r--r--drivers/mtd/mtdchar.c48
1 files changed, 45 insertions, 3 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index a825002123c8..24d35ba62b84 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -477,6 +477,39 @@ static int mtd_do_readoob(struct mtd_info *mtd, uint64_t start,
477 return ret; 477 return ret;
478} 478}
479 479
480/*
481 * Copies (and truncates, if necessary) data from the larger struct,
482 * nand_ecclayout, to the smaller, deprecated layout struct,
483 * nand_ecclayout_user. This is necessary only to suppport the deprecated
484 * API ioctl ECCGETLAYOUT while allowing all new functionality to use
485 * nand_ecclayout flexibly (i.e. the struct may change size in new
486 * releases without requiring major rewrites).
487 */
488static int shrink_ecclayout(const struct nand_ecclayout *from,
489 struct nand_ecclayout_user *to)
490{
491 int i;
492
493 if (!from || !to)
494 return -EINVAL;
495
496 memset(to, 0, sizeof(*to));
497
498 to->eccbytes = min((int)from->eccbytes, MTD_MAX_ECCPOS_ENTRIES_OLD);
499 for (i = 0; i < to->eccbytes; i++)
500 to->eccpos[i] = from->eccpos[i];
501
502 for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES; i++) {
503 if (from->oobfree[i].length == 0 &&
504 from->oobfree[i].offset == 0)
505 break;
506 to->oobavail += from->oobfree[i].length;
507 to->oobfree[i] = from->oobfree[i];
508 }
509
510 return 0;
511}
512
480static int mtd_ioctl(struct file *file, u_int cmd, u_long arg) 513static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
481{ 514{
482 struct mtd_file_info *mfi = file->private_data; 515 struct mtd_file_info *mfi = file->private_data;
@@ -812,14 +845,23 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
812 } 845 }
813#endif 846#endif
814 847
848 /* This ioctl is being deprecated - it truncates the ecc layout */
815 case ECCGETLAYOUT: 849 case ECCGETLAYOUT:
816 { 850 {
851 struct nand_ecclayout_user *usrlay;
852
817 if (!mtd->ecclayout) 853 if (!mtd->ecclayout)
818 return -EOPNOTSUPP; 854 return -EOPNOTSUPP;
819 855
820 if (copy_to_user(argp, mtd->ecclayout, 856 usrlay = kmalloc(sizeof(*usrlay), GFP_KERNEL);
821 sizeof(struct nand_ecclayout))) 857 if (!usrlay)
822 return -EFAULT; 858 return -ENOMEM;
859
860 shrink_ecclayout(mtd->ecclayout, usrlay);
861
862 if (copy_to_user(argp, usrlay, sizeof(*usrlay)))
863 ret = -EFAULT;
864 kfree(usrlay);
823 break; 865 break;
824 } 866 }
825 867