All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] mtd: Stop directly calling master ->_xxx() hooks from mtdpart code
@ 2017-06-25 16:01 Boris Brezillon
  2017-06-25 16:01 ` [PATCH v2 2/2] mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing Boris Brezillon
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Boris Brezillon @ 2017-06-25 16:01 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
	Richard Weinberger, Cyrille Pitchen, linux-mtd
  Cc: Robert Jarzmik, Kyungmin Park

The MTD layer provides several wrappers around mtd->_xxx() hooks. Call
these wrappers instead of directly dereferencing the associated ->_xxx()
pointer.

This change has been motivated by another rework letting the core
handle the case where ->_read/write_oob() are implemented but not
->_read/write(). In this case, we want mtd_read/write() to fall back to
->_read/write_oob() when ->_read/write() are NULL. The problem is,
mtdpart is directly calling the ->_xxx() instead of using the wrappers,
thus leading to a NULL pointer exception.

Even though we only need to do the change for part_read/write(), going
through those wrappers for all kind of part -> master operation
propagation is a good thing, because other wrappers might become
smarter over time, and the duplicated check overhead (parameters will
be checked at the partition and master level instead of only at the
partition level) should be negligible.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
Changes since v1:
- new patch needed to fix a NULL pointer dereference BUG
---
 drivers/mtd/mtdpart.c | 71 ++++++++++++++++++++++-----------------------------
 1 file changed, 31 insertions(+), 40 deletions(-)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index ea5e5307f667..11486ec6cab0 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -68,8 +68,7 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
 	int res;
 
 	stats = part->master->ecc_stats;
-	res = part->master->_read(part->master, from + part->offset, len,
-				  retlen, buf);
+	res = mtd_read(part->master, from + part->offset, len, retlen, buf);
 	if (unlikely(mtd_is_eccerr(res)))
 		mtd->ecc_stats.failed +=
 			part->master->ecc_stats.failed - stats.failed;
@@ -84,15 +83,15 @@ static int part_point(struct mtd_info *mtd, loff_t from, size_t len,
 {
 	struct mtd_part *part = mtd_to_part(mtd);
 
-	return part->master->_point(part->master, from + part->offset, len,
-				    retlen, virt, phys);
+	return mtd_point(part->master, from + part->offset, len, retlen, virt,
+			 phys);
 }
 
 static int part_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
 
-	return part->master->_unpoint(part->master, from + part->offset, len);
+	return mtd_unpoint(part->master, from + part->offset, len);
 }
 
 static unsigned long part_get_unmapped_area(struct mtd_info *mtd,
@@ -103,8 +102,7 @@ static unsigned long part_get_unmapped_area(struct mtd_info *mtd,
 	struct mtd_part *part = mtd_to_part(mtd);
 
 	offset += part->offset;
-	return part->master->_get_unmapped_area(part->master, len, offset,
-						flags);
+	return mtd_get_unmapped_area(part->master, len, offset, flags);
 }
 
 static int part_read_oob(struct mtd_info *mtd, loff_t from,
@@ -132,7 +130,7 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from,
 			return -EINVAL;
 	}
 
-	res = part->master->_read_oob(part->master, from + part->offset, ops);
+	res = mtd_read_oob(part->master, from + part->offset, ops);
 	if (unlikely(res)) {
 		if (mtd_is_bitflip(res))
 			mtd->ecc_stats.corrected++;
@@ -146,48 +144,43 @@ static int part_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
 		size_t len, size_t *retlen, u_char *buf)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	return part->master->_read_user_prot_reg(part->master, from, len,
-						 retlen, buf);
+	return mtd_read_user_prot_reg(part->master, from, len, retlen, buf);
 }
 
 static int part_get_user_prot_info(struct mtd_info *mtd, size_t len,
 				   size_t *retlen, struct otp_info *buf)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	return part->master->_get_user_prot_info(part->master, len, retlen,
-						 buf);
+	return mtd_get_user_prot_info(part->master, len, retlen, buf);
 }
 
 static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
 		size_t len, size_t *retlen, u_char *buf)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	return part->master->_read_fact_prot_reg(part->master, from, len,
-						 retlen, buf);
+	return mtd_read_fact_prot_reg(part->master, from, len, retlen, buf);
 }
 
 static int part_get_fact_prot_info(struct mtd_info *mtd, size_t len,
 				   size_t *retlen, struct otp_info *buf)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	return part->master->_get_fact_prot_info(part->master, len, retlen,
-						 buf);
+	return mtd_get_fact_prot_info(part->master, len, retlen, buf);
 }
 
 static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
 		size_t *retlen, const u_char *buf)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	return part->master->_write(part->master, to + part->offset, len,
-				    retlen, buf);
+	return mtd_write(part->master, to + part->offset, len, retlen, buf);
 }
 
 static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 		size_t *retlen, const u_char *buf)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	return part->master->_panic_write(part->master, to + part->offset, len,
-					  retlen, buf);
+	return mtd_panic_write(part->master, to + part->offset, len, retlen,
+			       buf);
 }
 
 static int part_write_oob(struct mtd_info *mtd, loff_t to,
@@ -199,30 +192,29 @@ static int part_write_oob(struct mtd_info *mtd, loff_t to,
 		return -EINVAL;
 	if (ops->datbuf && to + ops->len > mtd->size)
 		return -EINVAL;
-	return part->master->_write_oob(part->master, to + part->offset, ops);
+	return mtd_write_oob(part->master, to + part->offset, ops);
 }
 
 static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
 		size_t len, size_t *retlen, u_char *buf)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	return part->master->_write_user_prot_reg(part->master, from, len,
-						  retlen, buf);
+	return mtd_write_user_prot_reg(part->master, from, len, retlen, buf);
 }
 
 static int part_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,
 		size_t len)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	return part->master->_lock_user_prot_reg(part->master, from, len);
+	return mtd_lock_user_prot_reg(part->master, from, len);
 }
 
 static int part_writev(struct mtd_info *mtd, const struct kvec *vecs,
 		unsigned long count, loff_t to, size_t *retlen)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	return part->master->_writev(part->master, vecs, count,
-				     to + part->offset, retlen);
+	return mtd_writev(part->master, vecs, count, to + part->offset,
+			  retlen);
 }
 
 static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
@@ -231,7 +223,7 @@ static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
 	int ret;
 
 	instr->addr += part->offset;
-	ret = part->master->_erase(part->master, instr);
+	ret = mtd_erase(part->master, instr);
 	if (ret) {
 		if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
 			instr->fail_addr -= part->offset;
@@ -257,51 +249,51 @@ EXPORT_SYMBOL_GPL(mtd_erase_callback);
 static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	return part->master->_lock(part->master, ofs + part->offset, len);
+	return mtd_lock(part->master, ofs + part->offset, len);
 }
 
 static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	return part->master->_unlock(part->master, ofs + part->offset, len);
+	return mtd_unlock(part->master, ofs + part->offset, len);
 }
 
 static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	return part->master->_is_locked(part->master, ofs + part->offset, len);
+	return mtd_is_locked(part->master, ofs + part->offset, len);
 }
 
 static void part_sync(struct mtd_info *mtd)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	part->master->_sync(part->master);
+	mtd_sync(part->master);
 }
 
 static int part_suspend(struct mtd_info *mtd)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	return part->master->_suspend(part->master);
+	return mtd_suspend(part->master);
 }
 
 static void part_resume(struct mtd_info *mtd)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	part->master->_resume(part->master);
+	mtd_resume(part->master);
 }
 
 static int part_block_isreserved(struct mtd_info *mtd, loff_t ofs)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
 	ofs += part->offset;
-	return part->master->_block_isreserved(part->master, ofs);
+	return mtd_block_isreserved(part->master, ofs);
 }
 
 static int part_block_isbad(struct mtd_info *mtd, loff_t ofs)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
 	ofs += part->offset;
-	return part->master->_block_isbad(part->master, ofs);
+	return mtd_block_isbad(part->master, ofs);
 }
 
 static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
@@ -310,7 +302,7 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
 	int res;
 
 	ofs += part->offset;
-	res = part->master->_block_markbad(part->master, ofs);
+	res = mtd_block_markbad(part->master, ofs);
 	if (!res)
 		mtd->ecc_stats.badblocks++;
 	return res;
@@ -319,13 +311,13 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
 static int part_get_device(struct mtd_info *mtd)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	return part->master->_get_device(part->master);
+	return __get_mtd_device(part->master);
 }
 
 static void part_put_device(struct mtd_info *mtd)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
-	part->master->_put_device(part->master);
+	__put_mtd_device(part->master);
 }
 
 static int part_ooblayout_ecc(struct mtd_info *mtd, int section,
@@ -353,8 +345,7 @@ static int part_max_bad_blocks(struct mtd_info *mtd, loff_t ofs, size_t len)
 {
 	struct mtd_part *part = mtd_to_part(mtd);
 
-	return part->master->_max_bad_blocks(part->master,
-					     ofs + part->offset, len);
+	return mtd_max_bad_blocks(part->master, ofs + part->offset, len);
 }
 
 static inline void free_partition(struct mtd_part *p)
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing
  2017-06-25 16:01 [PATCH v2 1/2] mtd: Stop directly calling master ->_xxx() hooks from mtdpart code Boris Brezillon
@ 2017-06-25 16:01 ` Boris Brezillon
  2017-06-25 16:36 ` [PATCH v2 1/2] mtd: Stop directly calling master ->_xxx() hooks from mtdpart code Boris Brezillon
  2017-06-27 18:46 ` Brian Norris
  2 siblings, 0 replies; 6+ messages in thread
From: Boris Brezillon @ 2017-06-25 16:01 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
	Richard Weinberger, Cyrille Pitchen, linux-mtd
  Cc: Robert Jarzmik, Kyungmin Park

Some MTD sublayers/drivers are implementing ->_read/write_oob() and
providing dummy wrappers for their ->_read/write() implementations.
Let the core handle this case instead of duplicating the logic.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>
Acked-by: Brian Norris <computersforpeace@gmail.com>
---
Changes since v1:
- none
---
 drivers/mtd/devices/docg3.c        | 65 --------------------------------------
 drivers/mtd/mtdcore.c              | 31 ++++++++++++++++--
 drivers/mtd/nand/nand_base.c       | 56 --------------------------------
 drivers/mtd/onenand/onenand_base.c | 61 -----------------------------------
 4 files changed, 29 insertions(+), 184 deletions(-)

diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
index b833e6cc684c..81e108454f54 100644
--- a/drivers/mtd/devices/docg3.c
+++ b/drivers/mtd/devices/docg3.c
@@ -990,36 +990,6 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from,
 	goto out;
 }
 
-/**
- * doc_read - Read bytes from flash
- * @mtd: the device
- * @from: the offset from first block and first page, in bytes, aligned on page
- *        size
- * @len: the number of bytes to read (must be a multiple of 4)
- * @retlen: the number of bytes actually read
- * @buf: the filled in buffer
- *
- * Reads flash memory pages. This function does not read the OOB chunk, but only
- * the page data.
- *
- * Returns 0 if read successful, of -EIO, -EINVAL if an error occurred
- */
-static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
-	     size_t *retlen, u_char *buf)
-{
-	struct mtd_oob_ops ops;
-	size_t ret;
-
-	memset(&ops, 0, sizeof(ops));
-	ops.datbuf = buf;
-	ops.len = len;
-	ops.mode = MTD_OPS_AUTO_OOB;
-
-	ret = doc_read_oob(mtd, from, &ops);
-	*retlen = ops.retlen;
-	return ret;
-}
-
 static int doc_reload_bbt(struct docg3 *docg3)
 {
 	int block = DOC_LAYOUT_BLOCK_BBT;
@@ -1513,39 +1483,6 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
 	return ret;
 }
 
-/**
- * doc_write - Write a buffer to the chip
- * @mtd: the device
- * @to: the offset from first block and first page, in bytes, aligned on page
- *      size
- * @len: the number of bytes to write (must be a full page size, ie. 512)
- * @retlen: the number of bytes actually written (0 or 512)
- * @buf: the buffer to get bytes from
- *
- * Writes data to the chip.
- *
- * Returns 0 if write successful, -EIO if write error
- */
-static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
-		     size_t *retlen, const u_char *buf)
-{
-	struct docg3 *docg3 = mtd->priv;
-	int ret;
-	struct mtd_oob_ops ops;
-
-	doc_dbg("doc_write(to=%lld, len=%zu)\n", to, len);
-	ops.datbuf = (char *)buf;
-	ops.len = len;
-	ops.mode = MTD_OPS_PLACE_OOB;
-	ops.oobbuf = NULL;
-	ops.ooblen = 0;
-	ops.ooboffs = 0;
-
-	ret = doc_write_oob(mtd, to, &ops);
-	*retlen = ops.retlen;
-	return ret;
-}
-
 static struct docg3 *sysfs_dev2docg3(struct device *dev,
 				     struct device_attribute *attr)
 {
@@ -1876,8 +1813,6 @@ static int __init doc_set_driver_info(int chip_id, struct mtd_info *mtd)
 	mtd->writebufsize = mtd->writesize = DOC_LAYOUT_PAGE_SIZE;
 	mtd->oobsize = DOC_LAYOUT_OOB_SIZE;
 	mtd->_erase = doc_erase;
-	mtd->_read = doc_read;
-	mtd->_write = doc_write;
 	mtd->_read_oob = doc_read_oob;
 	mtd->_write_oob = doc_write_oob;
 	mtd->_block_isbad = doc_block_isbad;
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 1517da3ddd7d..e214af82b9be 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1033,7 +1033,20 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
 	 * representing the maximum number of bitflips that were corrected on
 	 * any one ecc region (if applicable; zero otherwise).
 	 */
-	ret_code = mtd->_read(mtd, from, len, retlen, buf);
+	if (mtd->_read) {
+		ret_code = mtd->_read(mtd, from, len, retlen, buf);
+	} else if (mtd->_read_oob) {
+		struct mtd_oob_ops ops = {
+			.len = len,
+			.datbuf = buf,
+		};
+
+		ret_code = mtd->_read_oob(mtd, from, &ops);
+		*retlen = ops.retlen;
+	} else {
+		return -ENOTSUPP;
+	}
+
 	if (unlikely(ret_code < 0))
 		return ret_code;
 	if (mtd->ecc_strength == 0)
@@ -1048,11 +1061,25 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
 	*retlen = 0;
 	if (to < 0 || to >= mtd->size || len > mtd->size - to)
 		return -EINVAL;
-	if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE))
+	if ((!mtd->_write && !mtd->_write_oob) ||
+	    !(mtd->flags & MTD_WRITEABLE))
 		return -EROFS;
 	if (!len)
 		return 0;
 	ledtrig_mtd_activity();
+
+	if (!mtd->_write) {
+		struct mtd_oob_ops ops = {
+			.len = len,
+			.datbuf = (u8 *)buf,
+		};
+		int ret;
+
+		ret = mtd->_write_oob(mtd, to, &ops);
+		*retlen = ops.retlen;
+		return ret;
+	}
+
 	return mtd->_write(mtd, to, len, retlen, buf);
 }
 EXPORT_SYMBOL_GPL(mtd_write);
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 85edac9b2bb5..d77c75e5c6b7 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -2190,33 +2190,6 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
 }
 
 /**
- * nand_read - [MTD Interface] MTD compatibility function for nand_do_read_ecc
- * @mtd: MTD device structure
- * @from: offset to read from
- * @len: number of bytes to read
- * @retlen: pointer to variable to store the number of read bytes
- * @buf: the databuffer to put data
- *
- * Get hold of the chip and call nand_do_read.
- */
-static int nand_read(struct mtd_info *mtd, loff_t from, size_t len,
-		     size_t *retlen, uint8_t *buf)
-{
-	struct mtd_oob_ops ops;
-	int ret;
-
-	nand_get_device(mtd, FL_READING);
-	memset(&ops, 0, sizeof(ops));
-	ops.len = len;
-	ops.datbuf = buf;
-	ops.mode = MTD_OPS_PLACE_OOB;
-	ret = nand_do_read_ops(mtd, from, &ops);
-	*retlen = ops.retlen;
-	nand_release_device(mtd);
-	return ret;
-}
-
-/**
  * nand_read_oob_std - [REPLACEABLE] the most common OOB data read function
  * @mtd: mtd info structure
  * @chip: nand chip info structure
@@ -2984,33 +2957,6 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
 }
 
 /**
- * nand_write - [MTD Interface] NAND write with ECC
- * @mtd: MTD device structure
- * @to: offset to write to
- * @len: number of bytes to write
- * @retlen: pointer to variable to store the number of written bytes
- * @buf: the data to write
- *
- * NAND write with ECC.
- */
-static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
-			  size_t *retlen, const uint8_t *buf)
-{
-	struct mtd_oob_ops ops;
-	int ret;
-
-	nand_get_device(mtd, FL_WRITING);
-	memset(&ops, 0, sizeof(ops));
-	ops.len = len;
-	ops.datbuf = (uint8_t *)buf;
-	ops.mode = MTD_OPS_PLACE_OOB;
-	ret = nand_do_write_ops(mtd, to, &ops);
-	*retlen = ops.retlen;
-	nand_release_device(mtd);
-	return ret;
-}
-
-/**
  * nand_do_write_oob - [MTD Interface] NAND write out-of-band
  * @mtd: MTD device structure
  * @to: offset to write to
@@ -5069,8 +5015,6 @@ int nand_scan_tail(struct mtd_info *mtd)
 	mtd->_erase = nand_erase;
 	mtd->_point = NULL;
 	mtd->_unpoint = NULL;
-	mtd->_read = nand_read;
-	mtd->_write = nand_write;
 	mtd->_panic_write = panic_nand_write;
 	mtd->_read_oob = nand_read_oob;
 	mtd->_write_oob = nand_write_oob;
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index 1a6d0e367b89..dbbc5b6cecc1 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -1448,38 +1448,6 @@ static int onenand_read_oob_nolock(struct mtd_info *mtd, loff_t from,
 }
 
 /**
- * onenand_read - [MTD Interface] Read data from flash
- * @param mtd		MTD device structure
- * @param from		offset to read from
- * @param len		number of bytes to read
- * @param retlen	pointer to variable to store the number of read bytes
- * @param buf		the databuffer to put data
- *
- * Read with ecc
-*/
-static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
-	size_t *retlen, u_char *buf)
-{
-	struct onenand_chip *this = mtd->priv;
-	struct mtd_oob_ops ops = {
-		.len	= len,
-		.ooblen	= 0,
-		.datbuf	= buf,
-		.oobbuf	= NULL,
-	};
-	int ret;
-
-	onenand_get_device(mtd, FL_READING);
-	ret = ONENAND_IS_4KB_PAGE(this) ?
-		onenand_mlc_read_ops_nolock(mtd, from, &ops) :
-		onenand_read_ops_nolock(mtd, from, &ops);
-	onenand_release_device(mtd);
-
-	*retlen = ops.retlen;
-	return ret;
-}
-
-/**
  * onenand_read_oob - [MTD Interface] Read main and/or out-of-band
  * @param mtd:		MTD device structure
  * @param from:		offset to read from
@@ -2129,35 +2097,6 @@ static int onenand_write_oob_nolock(struct mtd_info *mtd, loff_t to,
 }
 
 /**
- * onenand_write - [MTD Interface] write buffer to FLASH
- * @param mtd		MTD device structure
- * @param to		offset to write to
- * @param len		number of bytes to write
- * @param retlen	pointer to variable to store the number of written bytes
- * @param buf		the data to write
- *
- * Write with ECC
- */
-static int onenand_write(struct mtd_info *mtd, loff_t to, size_t len,
-	size_t *retlen, const u_char *buf)
-{
-	struct mtd_oob_ops ops = {
-		.len	= len,
-		.ooblen	= 0,
-		.datbuf	= (u_char *) buf,
-		.oobbuf	= NULL,
-	};
-	int ret;
-
-	onenand_get_device(mtd, FL_WRITING);
-	ret = onenand_write_ops_nolock(mtd, to, &ops);
-	onenand_release_device(mtd);
-
-	*retlen = ops.retlen;
-	return ret;
-}
-
-/**
  * onenand_write_oob - [MTD Interface] NAND write data and/or out-of-band
  * @param mtd:		MTD device structure
  * @param to:		offset to write
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] mtd: Stop directly calling master ->_xxx() hooks from mtdpart code
  2017-06-25 16:01 [PATCH v2 1/2] mtd: Stop directly calling master ->_xxx() hooks from mtdpart code Boris Brezillon
  2017-06-25 16:01 ` [PATCH v2 2/2] mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing Boris Brezillon
@ 2017-06-25 16:36 ` Boris Brezillon
  2017-06-27 18:46 ` Brian Norris
  2 siblings, 0 replies; 6+ messages in thread
From: Boris Brezillon @ 2017-06-25 16:36 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
	Richard Weinberger, Cyrille Pitchen, linux-mtd
  Cc: Robert Jarzmik, Kyungmin Park, Rafał Miłecki

Le Sun, 25 Jun 2017 18:01:12 +0200,
Boris Brezillon <boris.brezillon@free-electrons.com> a écrit :

> The MTD layer provides several wrappers around mtd->_xxx() hooks. Call
> these wrappers instead of directly dereferencing the associated ->_xxx()
> pointer.
> 
> This change has been motivated by another rework letting the core
> handle the case where ->_read/write_oob() are implemented but not
> ->_read/write(). In this case, we want mtd_read/write() to fall back to
> ->_read/write_oob() when ->_read/write() are NULL. The problem is,  
> mtdpart is directly calling the ->_xxx() instead of using the wrappers,
> thus leading to a NULL pointer exception.
> 
> Even though we only need to do the change for part_read/write(), going
> through those wrappers for all kind of part -> master operation
> propagation is a good thing, because other wrappers might become
> smarter over time, and the duplicated check overhead (parameters will
> be checked at the partition and master level instead of only at the
> partition level) should be negligible.

Hm, this one is conflicting with Rafal's work on part parsers, but
before I send a v3 rebased on l2-mtd/master I'd like to have feedback
on the changes done here.

> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
> Changes since v1:
> - new patch needed to fix a NULL pointer dereference BUG
> ---
>  drivers/mtd/mtdpart.c | 71 ++++++++++++++++++++++-----------------------------
>  1 file changed, 31 insertions(+), 40 deletions(-)
> 
> diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
> index ea5e5307f667..11486ec6cab0 100644
> --- a/drivers/mtd/mtdpart.c
> +++ b/drivers/mtd/mtdpart.c
> @@ -68,8 +68,7 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
>  	int res;
>  
>  	stats = part->master->ecc_stats;
> -	res = part->master->_read(part->master, from + part->offset, len,
> -				  retlen, buf);
> +	res = mtd_read(part->master, from + part->offset, len, retlen, buf);
>  	if (unlikely(mtd_is_eccerr(res)))
>  		mtd->ecc_stats.failed +=
>  			part->master->ecc_stats.failed - stats.failed;
> @@ -84,15 +83,15 @@ static int part_point(struct mtd_info *mtd, loff_t from, size_t len,
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
>  
> -	return part->master->_point(part->master, from + part->offset, len,
> -				    retlen, virt, phys);
> +	return mtd_point(part->master, from + part->offset, len, retlen, virt,
> +			 phys);
>  }
>  
>  static int part_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
>  
> -	return part->master->_unpoint(part->master, from + part->offset, len);
> +	return mtd_unpoint(part->master, from + part->offset, len);
>  }
>  
>  static unsigned long part_get_unmapped_area(struct mtd_info *mtd,
> @@ -103,8 +102,7 @@ static unsigned long part_get_unmapped_area(struct mtd_info *mtd,
>  	struct mtd_part *part = mtd_to_part(mtd);
>  
>  	offset += part->offset;
> -	return part->master->_get_unmapped_area(part->master, len, offset,
> -						flags);
> +	return mtd_get_unmapped_area(part->master, len, offset, flags);
>  }
>  
>  static int part_read_oob(struct mtd_info *mtd, loff_t from,
> @@ -132,7 +130,7 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from,
>  			return -EINVAL;
>  	}
>  
> -	res = part->master->_read_oob(part->master, from + part->offset, ops);
> +	res = mtd_read_oob(part->master, from + part->offset, ops);
>  	if (unlikely(res)) {
>  		if (mtd_is_bitflip(res))
>  			mtd->ecc_stats.corrected++;
> @@ -146,48 +144,43 @@ static int part_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
>  		size_t len, size_t *retlen, u_char *buf)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	return part->master->_read_user_prot_reg(part->master, from, len,
> -						 retlen, buf);
> +	return mtd_read_user_prot_reg(part->master, from, len, retlen, buf);
>  }
>  
>  static int part_get_user_prot_info(struct mtd_info *mtd, size_t len,
>  				   size_t *retlen, struct otp_info *buf)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	return part->master->_get_user_prot_info(part->master, len, retlen,
> -						 buf);
> +	return mtd_get_user_prot_info(part->master, len, retlen, buf);
>  }
>  
>  static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
>  		size_t len, size_t *retlen, u_char *buf)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	return part->master->_read_fact_prot_reg(part->master, from, len,
> -						 retlen, buf);
> +	return mtd_read_fact_prot_reg(part->master, from, len, retlen, buf);
>  }
>  
>  static int part_get_fact_prot_info(struct mtd_info *mtd, size_t len,
>  				   size_t *retlen, struct otp_info *buf)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	return part->master->_get_fact_prot_info(part->master, len, retlen,
> -						 buf);
> +	return mtd_get_fact_prot_info(part->master, len, retlen, buf);
>  }
>  
>  static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
>  		size_t *retlen, const u_char *buf)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	return part->master->_write(part->master, to + part->offset, len,
> -				    retlen, buf);
> +	return mtd_write(part->master, to + part->offset, len, retlen, buf);
>  }
>  
>  static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
>  		size_t *retlen, const u_char *buf)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	return part->master->_panic_write(part->master, to + part->offset, len,
> -					  retlen, buf);
> +	return mtd_panic_write(part->master, to + part->offset, len, retlen,
> +			       buf);
>  }
>  
>  static int part_write_oob(struct mtd_info *mtd, loff_t to,
> @@ -199,30 +192,29 @@ static int part_write_oob(struct mtd_info *mtd, loff_t to,
>  		return -EINVAL;
>  	if (ops->datbuf && to + ops->len > mtd->size)
>  		return -EINVAL;
> -	return part->master->_write_oob(part->master, to + part->offset, ops);
> +	return mtd_write_oob(part->master, to + part->offset, ops);
>  }
>  
>  static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
>  		size_t len, size_t *retlen, u_char *buf)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	return part->master->_write_user_prot_reg(part->master, from, len,
> -						  retlen, buf);
> +	return mtd_write_user_prot_reg(part->master, from, len, retlen, buf);
>  }
>  
>  static int part_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,
>  		size_t len)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	return part->master->_lock_user_prot_reg(part->master, from, len);
> +	return mtd_lock_user_prot_reg(part->master, from, len);
>  }
>  
>  static int part_writev(struct mtd_info *mtd, const struct kvec *vecs,
>  		unsigned long count, loff_t to, size_t *retlen)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	return part->master->_writev(part->master, vecs, count,
> -				     to + part->offset, retlen);
> +	return mtd_writev(part->master, vecs, count, to + part->offset,
> +			  retlen);
>  }
>  
>  static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
> @@ -231,7 +223,7 @@ static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
>  	int ret;
>  
>  	instr->addr += part->offset;
> -	ret = part->master->_erase(part->master, instr);
> +	ret = mtd_erase(part->master, instr);
>  	if (ret) {
>  		if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
>  			instr->fail_addr -= part->offset;
> @@ -257,51 +249,51 @@ EXPORT_SYMBOL_GPL(mtd_erase_callback);
>  static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	return part->master->_lock(part->master, ofs + part->offset, len);
> +	return mtd_lock(part->master, ofs + part->offset, len);
>  }
>  
>  static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	return part->master->_unlock(part->master, ofs + part->offset, len);
> +	return mtd_unlock(part->master, ofs + part->offset, len);
>  }
>  
>  static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	return part->master->_is_locked(part->master, ofs + part->offset, len);
> +	return mtd_is_locked(part->master, ofs + part->offset, len);
>  }
>  
>  static void part_sync(struct mtd_info *mtd)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	part->master->_sync(part->master);
> +	mtd_sync(part->master);
>  }
>  
>  static int part_suspend(struct mtd_info *mtd)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	return part->master->_suspend(part->master);
> +	return mtd_suspend(part->master);
>  }
>  
>  static void part_resume(struct mtd_info *mtd)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	part->master->_resume(part->master);
> +	mtd_resume(part->master);
>  }
>  
>  static int part_block_isreserved(struct mtd_info *mtd, loff_t ofs)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
>  	ofs += part->offset;
> -	return part->master->_block_isreserved(part->master, ofs);
> +	return mtd_block_isreserved(part->master, ofs);
>  }
>  
>  static int part_block_isbad(struct mtd_info *mtd, loff_t ofs)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
>  	ofs += part->offset;
> -	return part->master->_block_isbad(part->master, ofs);
> +	return mtd_block_isbad(part->master, ofs);
>  }
>  
>  static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
> @@ -310,7 +302,7 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
>  	int res;
>  
>  	ofs += part->offset;
> -	res = part->master->_block_markbad(part->master, ofs);
> +	res = mtd_block_markbad(part->master, ofs);
>  	if (!res)
>  		mtd->ecc_stats.badblocks++;
>  	return res;
> @@ -319,13 +311,13 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
>  static int part_get_device(struct mtd_info *mtd)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	return part->master->_get_device(part->master);
> +	return __get_mtd_device(part->master);
>  }
>  
>  static void part_put_device(struct mtd_info *mtd)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
> -	part->master->_put_device(part->master);
> +	__put_mtd_device(part->master);
>  }
>  
>  static int part_ooblayout_ecc(struct mtd_info *mtd, int section,
> @@ -353,8 +345,7 @@ static int part_max_bad_blocks(struct mtd_info *mtd, loff_t ofs, size_t len)
>  {
>  	struct mtd_part *part = mtd_to_part(mtd);
>  
> -	return part->master->_max_bad_blocks(part->master,
> -					     ofs + part->offset, len);
> +	return mtd_max_bad_blocks(part->master, ofs + part->offset, len);
>  }
>  
>  static inline void free_partition(struct mtd_part *p)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] mtd: Stop directly calling master ->_xxx() hooks from mtdpart code
  2017-06-25 16:01 [PATCH v2 1/2] mtd: Stop directly calling master ->_xxx() hooks from mtdpart code Boris Brezillon
  2017-06-25 16:01 ` [PATCH v2 2/2] mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing Boris Brezillon
  2017-06-25 16:36 ` [PATCH v2 1/2] mtd: Stop directly calling master ->_xxx() hooks from mtdpart code Boris Brezillon
@ 2017-06-27 18:46 ` Brian Norris
  2017-06-27 19:19   ` Boris Brezillon
  2 siblings, 1 reply; 6+ messages in thread
From: Brian Norris @ 2017-06-27 18:46 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: David Woodhouse, Marek Vasut, Richard Weinberger,
	Cyrille Pitchen, linux-mtd, Robert Jarzmik, Kyungmin Park

On Sun, Jun 25, 2017 at 06:01:12PM +0200, Boris Brezillon wrote:
> The MTD layer provides several wrappers around mtd->_xxx() hooks. Call
> these wrappers instead of directly dereferencing the associated ->_xxx()
> pointer.
> 
> This change has been motivated by another rework letting the core
> handle the case where ->_read/write_oob() are implemented but not
> ->_read/write(). In this case, we want mtd_read/write() to fall back to
> ->_read/write_oob() when ->_read/write() are NULL. The problem is,
> mtdpart is directly calling the ->_xxx() instead of using the wrappers,
> thus leading to a NULL pointer exception.
> 
> Even though we only need to do the change for part_read/write(), going
> through those wrappers for all kind of part -> master operation
> propagation is a good thing, because other wrappers might become
> smarter over time, and the duplicated check overhead (parameters will
> be checked at the partition and master level instead of only at the
> partition level) should be negligible.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
> Changes since v1:
> - new patch needed to fix a NULL pointer dereference BUG

I think I like this patch on the whole. A few notes below.

> ---
>  drivers/mtd/mtdpart.c | 71 ++++++++++++++++++++++-----------------------------
>  1 file changed, 31 insertions(+), 40 deletions(-)
> 
> diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
> index ea5e5307f667..11486ec6cab0 100644
> --- a/drivers/mtd/mtdpart.c
> +++ b/drivers/mtd/mtdpart.c
> @@ -68,8 +68,7 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
>  	int res;
>  
>  	stats = part->master->ecc_stats;
> -	res = part->master->_read(part->master, from + part->offset, len,
> -				  retlen, buf);
> +	res = mtd_read(part->master, from + part->offset, len, retlen, buf);
>  	if (unlikely(mtd_is_eccerr(res)))
>  		mtd->ecc_stats.failed +=
>  			part->master->ecc_stats.failed - stats.failed;

The parent-to-child ECC stat handling is different here than it is
below, in part_read_oob().

...

> @@ -132,7 +130,7 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from,
>  			return -EINVAL;
>  	}
>  
> -	res = part->master->_read_oob(part->master, from + part->offset, ops);
> +	res = mtd_read_oob(part->master, from + part->offset, ops);
>  	if (unlikely(res)) {
>  		if (mtd_is_bitflip(res))
>  			mtd->ecc_stats.corrected++;

Notice how we only count a single increment here.

That seems wrong, doesn't it? But then, do we guarantee that
->_read_oob() implementations follow the same stat recording guarantees
that ->_read() implementations do (or should)? Might double check that
before trying to fiddle here any more than you are.

I'm not sure if that affects your next patch at all. It's not a
criticism of this patch either, but I just noticed it when reviewing.

[...]

I was also wondering whether this patch couldn't go a step further, and
remove conditions like this:

	if (parent->_panic_write)
		slave->mtd._panic_write = part_panic_write; 

Since part_panic_write() should call mtd_panic_write() on the parent
(master), which would do its own -EOPNOTSUPP check. But then I suppose
that might invert the order of the checks, causing (for example) -EINVAL
for out-of-bounds panic write instead of -EOPNOTSUPP. So maybe that's
better left alone.

Brian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] mtd: Stop directly calling master ->_xxx() hooks from mtdpart code
  2017-06-27 18:46 ` Brian Norris
@ 2017-06-27 19:19   ` Boris Brezillon
  2017-06-27 19:52     ` Boris Brezillon
  0 siblings, 1 reply; 6+ messages in thread
From: Boris Brezillon @ 2017-06-27 19:19 UTC (permalink / raw)
  To: Brian Norris
  Cc: David Woodhouse, Marek Vasut, Richard Weinberger,
	Cyrille Pitchen, linux-mtd, Robert Jarzmik, Kyungmin Park

Le Tue, 27 Jun 2017 11:46:14 -0700,
Brian Norris <computersforpeace@gmail.com> a écrit :

> On Sun, Jun 25, 2017 at 06:01:12PM +0200, Boris Brezillon wrote:
> > The MTD layer provides several wrappers around mtd->_xxx() hooks. Call
> > these wrappers instead of directly dereferencing the associated ->_xxx()
> > pointer.
> > 
> > This change has been motivated by another rework letting the core
> > handle the case where ->_read/write_oob() are implemented but not  
> > ->_read/write(). In this case, we want mtd_read/write() to fall back to
> > ->_read/write_oob() when ->_read/write() are NULL. The problem is,  
> > mtdpart is directly calling the ->_xxx() instead of using the wrappers,
> > thus leading to a NULL pointer exception.
> > 
> > Even though we only need to do the change for part_read/write(), going
> > through those wrappers for all kind of part -> master operation
> > propagation is a good thing, because other wrappers might become
> > smarter over time, and the duplicated check overhead (parameters will
> > be checked at the partition and master level instead of only at the
> > partition level) should be negligible.
> > 
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> > ---
> > Changes since v1:
> > - new patch needed to fix a NULL pointer dereference BUG  
> 
> I think I like this patch on the whole. A few notes below.

Ok, cool. I was afraid someone would complain about the induced
overhead.

> 
> > ---
> >  drivers/mtd/mtdpart.c | 71 ++++++++++++++++++++++-----------------------------
> >  1 file changed, 31 insertions(+), 40 deletions(-)
> > 
> > diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
> > index ea5e5307f667..11486ec6cab0 100644
> > --- a/drivers/mtd/mtdpart.c
> > +++ b/drivers/mtd/mtdpart.c
> > @@ -68,8 +68,7 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
> >  	int res;
> >  
> >  	stats = part->master->ecc_stats;
> > -	res = part->master->_read(part->master, from + part->offset, len,
> > -				  retlen, buf);
> > +	res = mtd_read(part->master, from + part->offset, len, retlen, buf);
> >  	if (unlikely(mtd_is_eccerr(res)))
> >  		mtd->ecc_stats.failed +=
> >  			part->master->ecc_stats.failed - stats.failed;  
> 
> The parent-to-child ECC stat handling is different here than it is
> below, in part_read_oob().
> 
> ...
> 
> > @@ -132,7 +130,7 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from,
> >  			return -EINVAL;
> >  	}
> >  
> > -	res = part->master->_read_oob(part->master, from + part->offset, ops);
> > +	res = mtd_read_oob(part->master, from + part->offset, ops);
> >  	if (unlikely(res)) {
> >  		if (mtd_is_bitflip(res))
> >  			mtd->ecc_stats.corrected++;  
> 
> Notice how we only count a single increment here.
> 
> That seems wrong, doesn't it?

Indeed, it does, but this patch does not change the current
behavior ;-).

> But then, do we guarantee that
> ->_read_oob() implementations follow the same stat recording guarantees  
> that ->_read() implementations do (or should)? Might double check that
> before trying to fiddle here any more than you are.

Well, if you want my opinion, all this ecc_stats dance on MTD parts is
already fragile, because, AFAICT, nothing guarantees that someone else
is not reading another partition of the same device while we are
extracting the stats, which means that those numbers might already be
inconsistent when we do the calculation to extract the number of
bitflips and failures related to the partition. So, I'm not sure we
really care about these numbers.

If we want things to be perfectly reliable, we should return the stats
attached to a specific read request and then atomically update the
global stats (see the discussion I had we Sacha a while ago [1]).

Anyway, I'm fine making the logic consistent between part_read() and
part_read_oob() if you like, but that should be done in a separate
patch IMO.

> 
> I'm not sure if that affects your next patch at all. It's not a
> criticism of this patch either, but I just noticed it when reviewing.

Nope, because part_read() will still be used for the standard read path,
and the core will only fall back to ->_read_oob() when doing the read
on the master device.

> 
> [...]
> 
> I was also wondering whether this patch couldn't go a step further, and
> remove conditions like this:
> 
> 	if (parent->_panic_write)
> 		slave->mtd._panic_write = part_panic_write; 
> 
> Since part_panic_write() should call mtd_panic_write() on the parent
> (master), which would do its own -EOPNOTSUPP check. But then I suppose
> that might invert the order of the checks, causing (for example) -EINVAL
> for out-of-bounds panic write instead of -EOPNOTSUPP. So maybe that's
> better left alone.

I considered doing that but was too lazy to check if all helpers were
properly checking the pointer value before dereferencing it :).

> 
> Brian

[1]https://patchwork.ozlabs.org/patch/614493/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] mtd: Stop directly calling master ->_xxx() hooks from mtdpart code
  2017-06-27 19:19   ` Boris Brezillon
@ 2017-06-27 19:52     ` Boris Brezillon
  0 siblings, 0 replies; 6+ messages in thread
From: Boris Brezillon @ 2017-06-27 19:52 UTC (permalink / raw)
  To: Brian Norris
  Cc: David Woodhouse, Marek Vasut, Richard Weinberger,
	Cyrille Pitchen, linux-mtd, Robert Jarzmik, Kyungmin Park

Le Tue, 27 Jun 2017 21:19:38 +0200,
Boris Brezillon <boris.brezillon@free-electrons.com> a écrit :

> > 
> > [...]
> > 
> > I was also wondering whether this patch couldn't go a step further, and
> > remove conditions like this:
> > 
> > 	if (parent->_panic_write)
> > 		slave->mtd._panic_write = part_panic_write; 
> > 
> > Since part_panic_write() should call mtd_panic_write() on the parent
> > (master), which would do its own -EOPNOTSUPP check. But then I suppose
> > that might invert the order of the checks, causing (for example) -EINVAL
> > for out-of-bounds panic write instead of -EOPNOTSUPP. So maybe that's
> > better left alone.  
> 
> I considered doing that but was too lazy to check if all helpers were
> properly checking the pointer value before dereferencing it :).

I just checked, and it seems we can unconditionally set part hooks and
rely on default mtd_xxx() helpers to detect when the feature is not
supported by the master.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-06-27 19:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-25 16:01 [PATCH v2 1/2] mtd: Stop directly calling master ->_xxx() hooks from mtdpart code Boris Brezillon
2017-06-25 16:01 ` [PATCH v2 2/2] mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing Boris Brezillon
2017-06-25 16:36 ` [PATCH v2 1/2] mtd: Stop directly calling master ->_xxx() hooks from mtdpart code Boris Brezillon
2017-06-27 18:46 ` Brian Norris
2017-06-27 19:19   ` Boris Brezillon
2017-06-27 19:52     ` Boris Brezillon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.