Artem Bityutskiy | 2 Jan 2012 13:20
Picon

[PATCH 02/17] mtd: do use mtd->point directly

From: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>

Remove direct usage of the "mtd->point" function pointer. Instead,
test the mtd_point() return code for '-EOPNOTSUPP'.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>
---
 fs/jffs2/erase.c        |    9 ++++-----
 fs/jffs2/readinode.c    |   18 ++++++++----------
 fs/jffs2/scan.c         |    2 +-
 include/linux/mtd/mtd.h |    2 ++
 4 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
index c59d642..a01cdad 100644
--- a/fs/jffs2/erase.c
+++ b/fs/jffs2/erase.c
 <at>  <at>  -336,12 +336,11  <at>  <at>  static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl
 	uint32_t ofs;
 	size_t retlen;
 	int ret = -EIO;
+	unsigned long *wordebuf;

-	if (c->mtd->point) {
-		unsigned long *wordebuf;
-
-		ret = mtd_point(c->mtd, jeb->offset, c->sector_size, &retlen,
-				&ebuf, NULL);
+	ret = mtd_point(c->mtd, jeb->offset, c->sector_size, &retlen,
+			&ebuf, NULL);
(Continue reading)

Artem Bityutskiy | 2 Jan 2012 13:20
Picon

[PATCH 01/17] mtd: introduce mtd_has_oob helper

From: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>

We are working in the direction of making sure that MTD clients to not
use 'mtd->func' pointers directly. In some places we want to know if
OOB operations are supported by an MTD device. Introduce 'mtd_has_oob()'
helper for these purposes.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>
---
 drivers/mtd/mtdchar.c   |    2 +-
 drivers/mtd/sm_ftl.c    |    4 ++--
 include/linux/mtd/mtd.h |    5 +++++
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 83b0c82..c501eec 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
 <at>  <at>  -1004,7 +1004,7  <at>  <at>  static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
 			break;

 		case MTD_FILE_MODE_RAW:
-			if (!mtd->read_oob || !mtd->write_oob)
+			if (!mtd_has_oob(mtd))
 				return -EOPNOTSUPP;
 			mfi->mode = arg;

diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
index 4ec2af7..072ed59 100644
--- a/drivers/mtd/sm_ftl.c
(Continue reading)

Artem Bityutskiy | 2 Jan 2012 13:20
Picon

[PATCH 05/17] mtd: mtdoops: do not use mtd->panic_write directly

From: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>

Instead of checking if 'mtd->panic_write' is defined, call 'mtd_panic_write()'
and check the error code - '-EOPNOTSUPP' will be returned if the function is
not defined.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>
---
 drivers/mtd/mtdoops.c   |   17 ++++++++---------
 include/linux/mtd/mtd.h |    2 ++
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index 69532a3..c8540b8 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
 <at>  <at>  -221,10 +221,14  <at>  <at>  static void mtdoops_write(struct mtdoops_context *cxt, int panic)
 	hdr[0] = cxt->nextcount;
 	hdr[1] = MTDOOPS_KERNMSG_MAGIC;

-	if (panic)
+	if (panic) {
 		ret = mtd_panic_write(mtd, cxt->nextpage * record_size,
 				      record_size, &retlen, cxt->oops_buf);
-	else
+		if (ret == -EOPNOTSUPP) {
+			printk(KERN_ERR "mtdoops: Cannot write from panic without panic_write\n");
+			return;
+		}
+	} else
(Continue reading)

Artem Bityutskiy | 2 Jan 2012 13:20
Picon

[PATCH 06/17] mtd: do not use mtd->read_oob directly

From: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>

Instead of checking whether 'mtd->read_oob' is defined, just call
'mtd_read_oob()' and handle the '-EOPNOTSUPP' error which will be returned
if the function is undefined.

Additionally, make 'mtd_write_oob()' return '-EOPNOTSUPP' if the function
is undefined.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>
---
 drivers/mtd/mtdchar.c   |    9 ++-------
 include/linux/mtd/mtd.h |    4 ++++
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 55f0961..287ff0d 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
 <at>  <at>  -452,13 +452,8  <at>  <at>  static int mtdchar_readoob(struct file *file, struct mtd_info *mtd,
 	if (length > 4096)
 		return -EINVAL;

-	if (!mtd->read_oob)
-		ret = -EOPNOTSUPP;
-	else
-		ret = access_ok(VERIFY_WRITE, ptr,
-				length) ? 0 : -EFAULT;
-	if (ret)
-		return ret;
(Continue reading)

Artem Bityutskiy | 2 Jan 2012 13:20
Picon

[PATCH 03/17] mtd: do not use mtd->get_unmapped_area directly

From: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>

Remove direct usage of mtd->get_unmapped_area. Instead, just call
'mtd_get_unmapped_area()' which will return -EOPNOTSUPP if the function
is not implemented and test for this error code.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>
---
 drivers/mtd/mtdchar.c   |   26 +++++++++++---------------
 drivers/mtd/mtdconcat.c |    6 +-----
 include/linux/mtd/mtd.h |    2 ++
 3 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index c501eec..55f0961 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
 <at>  <at>  -1124,25 +1124,21  <at>  <at>  static unsigned long mtdchar_get_unmapped_area(struct file *file,
 {
 	struct mtd_file_info *mfi = file->private_data;
 	struct mtd_info *mtd = mfi->mtd;
+	unsigned long offset;
+	int ret;

-	if (mtd->get_unmapped_area) {
-		unsigned long offset;
-
-		if (addr != 0)
-			return (unsigned long) -EINVAL;
-
(Continue reading)

Artem Bityutskiy | 2 Jan 2012 13:20
Picon

[PATCH 07/17] mtd: do not use mtd->get_*_prot_info directly

From: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>

Instead, call 'mtd_get_*_prot_info()' and check for '-EOPNOTSUPP'. While
on it, fix the return code from '-EOPNOTSUPP' to '-EINVAL' for the case
when the mode parameter is invalid.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>
---
 drivers/mtd/mtdchar.c   |    8 +++-----
 include/linux/mtd/mtd.h |    4 ++++
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 287ff0d..49340dc 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
 <at>  <at>  -919,17 +919,15  <at>  <at>  static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
 		struct otp_info *buf = kmalloc(4096, GFP_KERNEL);
 		if (!buf)
 			return -ENOMEM;
-		ret = -EOPNOTSUPP;
 		switch (mfi->mode) {
 		case MTD_FILE_MODE_OTP_FACTORY:
-			if (mtd->get_fact_prot_info)
-				ret = mtd_get_fact_prot_info(mtd, buf, 4096);
+			ret = mtd_get_fact_prot_info(mtd, buf, 4096);
 			break;
 		case MTD_FILE_MODE_OTP_USER:
-			if (mtd->get_user_prot_info)
-				ret = mtd_get_user_prot_info(mtd, buf, 4096);
(Continue reading)

Artem Bityutskiy | 2 Jan 2012 13:20
Picon

[PATCH 09/17] mtd: mtd->write_user_prot_reg directly

From: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>

Instead, just call 'mtd_write_user_prot_reg()' and check the '-EOPNOTSUPP' return
code.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>
---
 drivers/mtd/mtdchar.c   |    4 ----
 include/linux/mtd/mtd.h |    2 ++
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 4e8e5fb..25bbbc3 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
 <at>  <at>  -310,10 +310,6  <at>  <at>  static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t c
 			ret = -EROFS;
 			break;
 		case MTD_FILE_MODE_OTP_USER:
-			if (!mtd->write_user_prot_reg) {
-				ret = -EOPNOTSUPP;
-				break;
-			}
 			ret = mtd_write_user_prot_reg(mtd, *ppos, len,
 						      &retlen, kbuf);
 			break;
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index e488cf9..7cd56d2 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
(Continue reading)

Artem Bityutskiy | 2 Jan 2012 13:20
Picon

[PATCH 08/17] mtd: do not use mtd->read_*_prot_reg directly

From: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>

Instead, call 'mtd_read_*_prot_info()' and check for -EOPNOTSUPP.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>
---
 drivers/mtd/mtdchar.c   |   18 ++++++++++--------
 include/linux/mtd/mtd.h |    4 ++++
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 49340dc..4e8e5fb 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
 <at>  <at>  -366,20 +366,22  <at>  <at>  static void mtdchar_erase_callback (struct erase_info *instr)
 static int otp_select_filemode(struct mtd_file_info *mfi, int mode)
 {
 	struct mtd_info *mtd = mfi->mtd;
+	size_t retlen;
 	int ret = 0;

+	/*
+	 * Make a fake call to mtd_read_fact_prot_reg() to check if OTP
+	 * operations are supported.
+	 */
+	if (mtd_read_fact_prot_reg(mtd, -1, -1, &retlen, NULL) == -EOPNOTSUPP)
+		return -EOPNOTSUPP;
+
 	switch (mode) {
 	case MTD_OTP_FACTORY:
(Continue reading)

Artem Bityutskiy | 2 Jan 2012 13:20
Picon

[PATCH 10/17] mtd: do not use mtd->lock_user_prot_reg directly

From: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>

Instead, check the -EOPNOTSUPP return code of 'mtd_lock_user_prot_reg()'.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>
---
 drivers/mtd/mtdchar.c   |    2 --
 include/linux/mtd/mtd.h |    2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 25bbbc3..2020a16 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
 <at>  <at>  -949,8 +949,6  <at>  <at>  static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
 			return -EINVAL;
 		if (copy_from_user(&oinfo, argp, sizeof(oinfo)))
 			return -EFAULT;
-		if (!mtd->lock_user_prot_reg)
-			return -EOPNOTSUPP;
 		ret = mtd_lock_user_prot_reg(mtd, oinfo.start, oinfo.length);
 		break;
 	}
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 7cd56d2..a994129 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
 <at>  <at>  -389,6 +389,8  <at>  <at>  static inline int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to,
 static inline int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,
 					 size_t len)
(Continue reading)

Artem Bityutskiy | 2 Jan 2012 13:20
Picon

[PATCH 11/17] mtd: harmonize mtd_writev usage

From: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>

This patch makes the 'mtd_writev()' function more usable and logical. We first
teach it to fall-back to the 'default_mtd_writev()' function if the MTD driver
does not define its own '->writev()' method. Then we make block2mtd and JFFS2
just 'mtd_writev()' instead of 'default_mtd_writev()' function. This means we
can now stop exporting 'default_mtd_writev()' and instead, export
'mtd_writev()'. This is much cleaner and more logical, as well as allows us to
get read of another direct 'mtd->writev' access in JFFS2.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy <at> linux.intel.com>
---
 drivers/mtd/devices/block2mtd.c |    2 +-
 drivers/mtd/mtdcore.c           |   26 +++++++++++++++++++++++---
 fs/jffs2/writev.c               |    6 +-----
 include/linux/mtd/mtd.h         |   16 ++--------------
 4 files changed, 27 insertions(+), 23 deletions(-)

diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index b78f231..c16f6b4 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
 <at>  <at>  -288,7 +288,7  <at>  <at>  static struct block2mtd_dev *add_device(char *devname, int erase_size)
 	dev->mtd.flags = MTD_CAP_RAM;
 	dev->mtd.erase = block2mtd_erase;
 	dev->mtd.write = block2mtd_write;
-	dev->mtd.writev = default_mtd_writev;
+	dev->mtd.writev = mtd_writev;
 	dev->mtd.sync = block2mtd_sync;
 	dev->mtd.read = block2mtd_read;
(Continue reading)


Gmane