Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1343692
| From | Boris Brezillon <boris.brezillon@free-electrons.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v3 06/52] mtd: use mtd_ooblayout_xxx() helpers where appropriate |
| Date | 2016-02-26 02:20 +0100 |
| Message-ID | <r6fey-40K-17@gated-at.bofh.it> (permalink) |
| References | <r6eVb-3Cr-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
The mtd_ooblayout_xxx() helper functions have been added to avoid direct
accesses to the ecclayout field, and thus ease for future reworks.
Use these helpers in all places where the oobfree[] and eccpos[] arrays
where directly accessed.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
drivers/mtd/mtdchar.c | 107 +++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 88 insertions(+), 19 deletions(-)
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 6d19835..cd64ab7 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -472,28 +472,101 @@ static int mtdchar_readoob(struct file *file, struct mtd_info *mtd,
* nand_ecclayout flexibly (i.e. the struct may change size in new
* releases without requiring major rewrites).
*/
-static int shrink_ecclayout(const struct nand_ecclayout *from,
- struct nand_ecclayout_user *to)
+static int shrink_ecclayout(struct mtd_info *mtd,
+ struct nand_ecclayout_user *to)
{
- int i;
+ struct mtd_oob_region oobregion;
+ int i, section = 0, ret;
- if (!from || !to)
+ if (!mtd || !to)
return -EINVAL;
memset(to, 0, sizeof(*to));
- to->eccbytes = min((int)from->eccbytes, MTD_MAX_ECCPOS_ENTRIES);
- for (i = 0; i < to->eccbytes; i++)
- to->eccpos[i] = from->eccpos[i];
+ to->eccbytes = 0;
+ for (i = 0; i < MTD_MAX_ECCPOS_ENTRIES;) {
+ u32 eccpos;
+
+ ret = mtd_ooblayout_ecc(mtd, section, &oobregion);
+ if (ret < 0) {
+ if (ret != -ERANGE)
+ return ret;
+
+ break;
+ }
+
+ eccpos = oobregion.offset;
+ for (; i < MTD_MAX_ECCPOS_ENTRIES &&
+ eccpos < oobregion.offset + oobregion.length; i++) {
+ to->eccpos[i] = eccpos++;
+ to->eccbytes++;
+ }
+ }
for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES; i++) {
- if (from->oobfree[i].length == 0 &&
- from->oobfree[i].offset == 0)
+ ret = mtd_ooblayout_free(mtd, i, &oobregion);
+ if (ret < 0) {
+ if (ret != -ERANGE)
+ return ret;
+
+ break;
+ }
+
+ to->oobfree[i].offset = oobregion.offset;
+ to->oobfree[i].length = oobregion.length;
+ to->oobavail += to->oobfree[i].length;
+ }
+
+ return 0;
+}
+
+static int get_oobinfo(struct mtd_info *mtd, struct nand_oobinfo *to)
+{
+ struct mtd_oob_region oobregion;
+ int i, section = 0, ret;
+
+ if (!mtd || !to)
+ return -EINVAL;
+
+ memset(to, 0, sizeof(*to));
+
+ to->eccbytes = 0;
+ for (i = 0; i < ARRAY_SIZE(to->eccpos);) {
+ u32 eccpos;
+
+ ret = mtd_ooblayout_ecc(mtd, section, &oobregion);
+ if (ret < 0) {
+ if (ret != -ERANGE)
+ return ret;
+
break;
- to->oobavail += from->oobfree[i].length;
- to->oobfree[i] = from->oobfree[i];
+ }
+
+ if (oobregion.length + i > ARRAY_SIZE(to->eccpos))
+ return -EINVAL;
+
+ eccpos = oobregion.offset;
+ for (; eccpos < oobregion.offset + oobregion.length; i++) {
+ to->eccpos[i] = eccpos++;
+ to->eccbytes++;
+ }
}
+ for (i = 0; i < 8; i++) {
+ ret = mtd_ooblayout_free(mtd, i, &oobregion);
+ if (ret < 0) {
+ if (ret != -ERANGE)
+ return ret;
+
+ break;
+ }
+
+ to->oobfree[i][0] = oobregion.offset;
+ to->oobfree[i][1] = oobregion.length;
+ }
+
+ to->useecc = MTD_NANDECC_AUTOPLACE;
+
return 0;
}
@@ -817,14 +890,10 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
if (!mtd->ecclayout)
return -EOPNOTSUPP;
- if (mtd->ecclayout->eccbytes > ARRAY_SIZE(oi.eccpos))
- return -EINVAL;
- oi.useecc = MTD_NANDECC_AUTOPLACE;
- memcpy(&oi.eccpos, mtd->ecclayout->eccpos, sizeof(oi.eccpos));
- memcpy(&oi.oobfree, mtd->ecclayout->oobfree,
- sizeof(oi.oobfree));
- oi.eccbytes = mtd->ecclayout->eccbytes;
+ ret = get_oobinfo(mtd, &oi);
+ if (ret)
+ return ret;
if (copy_to_user(argp, &oi, sizeof(struct nand_oobinfo)))
return -EFAULT;
@@ -920,7 +989,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
if (!usrlay)
return -ENOMEM;
- shrink_ecclayout(mtd->ecclayout, usrlay);
+ shrink_ecclayout(mtd, usrlay);
if (copy_to_user(argp, usrlay, sizeof(*usrlay)))
ret = -EFAULT;
--
2.1.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v3 00/52] mtd: rework ECC layout definition Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:00 +0100
[PATCH v3 04/52] mtd: nand: simplify nand_bch_init() usage Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:00 +0100
[PATCH v3 01/52] mtd: kill the ecclayout->oobavail field Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:00 +0100
[PATCH v3 05/52] mtd: add mtd_ooblayout_xxx() helper functions Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:00 +0100
[PATCH v3 03/52] mtd: mtdswap: remove useless if (!mtd->ecclayout) test Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:00 +0100
[PATCH v3 02/52] mtd: create an mtd_oobavail() helper and make use of it Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:00 +0100
[PATCH v3 11/52] mtd: nand: lpc32xx: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 22/52] mtd: nand: bch: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 28/52] mtd: nand: cafe: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 40/52] mtd: nand: lpc32xx: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 24/52] mtd: nand: jz4740: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 20/52] mtd: docg3: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 36/52] mtd: nand: fsmc: get rid of the fsmc_nand_eccplace struct Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 21/52] mtd: nand: implement the default mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 16/52] mtd: nand: use mtd_set_ecclayout() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 19/52] mtd: create an mtd_ooblayout_ops struct to ease ECC layout definition Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 12/52] mtd: nand: omap2: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 15/52] mtd: use mtd_set_ecclayout() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 26/52] mtd: nand: bf5xx: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 27/52] mtd: nand: brcm: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 44/52] mtd: nand: s3c2410: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 13/52] mtd: onenand: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 45/52] mtd: nand: sh_flctl: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 25/52] mtd: nand: atmel: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 31/52] mtd: nand: diskonchip: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 34/52] mtd: nand: fsl_ifc: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 41/52] mtd: nand: mxc: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 42/52] mtd: nand: omap2: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 43/52] mtd: nand: pxa3xx: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 32/52] mtd: nand: docg4: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 14/52] mtd: add mtd_set_ecclayout() helper function Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 23/52] mtd: nand: sharpsl: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 39/52] mtd: nand: jz4780: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
Re: [PATCH v3 39/52] mtd: nand: jz4780: switch to mtd_ooblayout_ops Harvey Hunt <harvey.hunt@imgtec.com> - 2016-02-29 11:50 +0100
[PATCH v3 29/52] mtd: nand: davinci: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 30/52] mtd: nand: denali: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 17/52] mtd: onenand: use mtd_set_ecclayout() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 18/52] mtd: docg3: use mtd_set_ecclayout() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 33/52] mtd: nand: fsl_elbc: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 48/52] mtd: nand: vf610: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
Re: [PATCH v3 48/52] mtd: nand: vf610: switch to mtd_ooblayout_ops Stefan Agner <stefan@agner.ch> - 2016-02-26 20:50 +0100
Re: [PATCH v3 48/52] mtd: nand: vf610: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 21:50 +0100
[PATCH v3 38/52] mtd: nand: hisi504: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 06/52] mtd: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 52/52] mtd: kill the nand_ecclayout struct Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 47/52] mtd: nand: sunxi: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 51/52] mtd: nand: kill the ecc->layout field Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 49/52] mtd: onenand: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 46/52] mtd: nand: sm_common: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 37/52] mtd: nand: gpmi: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 50/52] staging: mt29f_spinand: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 35/52] mtd: nand: fsmc: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
Re: [PATCH v3 00/52] mtd: rework ECC layout definition Stefan Agner <stefan@agner.ch> - 2016-02-26 02:40 +0100
Re: [PATCH v3 00/52] mtd: rework ECC layout definition Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 03:50 +0100
csiph-web