linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mtd: rawnand: Remove of_get_nand_on_flash_bbt() wrapper
@ 2022-01-06 13:16 Tudor Ambarus
  2022-01-06 13:16 ` [PATCH 2/2] mtd: rawnand: Rework of_get_nand_bus_width() Tudor Ambarus
  2022-01-23 15:43 ` [PATCH 1/2] mtd: rawnand: Remove of_get_nand_on_flash_bbt() wrapper Miquel Raynal
  0 siblings, 2 replies; 3+ messages in thread
From: Tudor Ambarus @ 2022-01-06 13:16 UTC (permalink / raw)
  To: miquel.raynal; +Cc: richard, vigneshr, linux-mtd, linux-kernel, Tudor Ambarus

Remove the wrapper as it hides for no reason what we really want: find an
of_property. Removing the wrapper makes the code easier to read.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/nand/raw/nand_base.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 113a2e9f43b1..b8e7f1aae032 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -5287,11 +5287,6 @@ static int of_get_nand_bus_width(struct device_node *np)
 	}
 }
 
-static bool of_get_nand_on_flash_bbt(struct device_node *np)
-{
-	return of_property_read_bool(np, "nand-on-flash-bbt");
-}
-
 static int of_get_nand_secure_regions(struct nand_chip *chip)
 {
 	struct device_node *dn = nand_get_flash_node(chip);
@@ -5375,7 +5370,7 @@ static int rawnand_dt_init(struct nand_chip *chip)
 	if (of_property_read_bool(dn, "nand-is-boot-medium"))
 		chip->options |= NAND_IS_BOOT_MEDIUM;
 
-	if (of_get_nand_on_flash_bbt(dn))
+	if (of_property_read_bool(dn, "nand-on-flash-bbt"))
 		chip->bbt_options |= NAND_BBT_USE_FLASH;
 
 	of_get_nand_ecc_user_config(nand);
-- 
2.25.1


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

* [PATCH 2/2] mtd: rawnand: Rework of_get_nand_bus_width()
  2022-01-06 13:16 [PATCH 1/2] mtd: rawnand: Remove of_get_nand_on_flash_bbt() wrapper Tudor Ambarus
@ 2022-01-06 13:16 ` Tudor Ambarus
  2022-01-23 15:43 ` [PATCH 1/2] mtd: rawnand: Remove of_get_nand_on_flash_bbt() wrapper Miquel Raynal
  1 sibling, 0 replies; 3+ messages in thread
From: Tudor Ambarus @ 2022-01-06 13:16 UTC (permalink / raw)
  To: miquel.raynal; +Cc: richard, vigneshr, linux-mtd, linux-kernel, Tudor Ambarus

of_get_nand_bus_width() had a wrong behavior because:
1/ it ignored the -ENODATA and -EOVERFLOW return values of
   of_property_read_u32(). "nand-bus-width" without value was tolerated
   while it shouldn't have been according to the devicetree bindings.
2/ returned -EIO when the nand-bus-width was neither 8 nor 16, when it
   should have returned -EINVAL instead.
3/ returned the 8 or 16 bus-width integer, but it was never used it its
   caller. A simply return 0 on success is enough.
Rework of_get_nand_bus_width() and address all the above. The execution
is now stopped in case of errors.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/nand/raw/nand_base.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index b8e7f1aae032..54153d7aa671 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -5271,20 +5271,24 @@ static void of_get_nand_ecc_legacy_user_config(struct nand_chip *chip)
 		user_conf->placement = of_get_rawnand_ecc_placement_legacy(dn);
 }
 
-static int of_get_nand_bus_width(struct device_node *np)
+static int of_get_nand_bus_width(struct nand_chip *chip)
 {
+	struct device_node *dn = nand_get_flash_node(chip);
 	u32 val;
+	int ret;
 
-	if (of_property_read_u32(np, "nand-bus-width", &val))
-		return 8;
+	ret = of_property_read_u32(dn, "nand-bus-width", &val);
+	if (ret == -EINVAL)
+		/* Buswidth defaults to 8 if the property does not exist .*/
+		return 0;
+	else if (ret)
+		return ret;
 
-	switch (val) {
-	case 8:
-	case 16:
-		return val;
-	default:
-		return -EIO;
-	}
+	if (val == 16)
+		chip->options |= NAND_BUSWIDTH_16;
+	else if (val != 8)
+		return -EINVAL;
+	return 0;
 }
 
 static int of_get_nand_secure_regions(struct nand_chip *chip)
@@ -5360,12 +5364,14 @@ static int rawnand_dt_init(struct nand_chip *chip)
 {
 	struct nand_device *nand = mtd_to_nanddev(nand_to_mtd(chip));
 	struct device_node *dn = nand_get_flash_node(chip);
+	int ret;
 
 	if (!dn)
 		return 0;
 
-	if (of_get_nand_bus_width(dn) == 16)
-		chip->options |= NAND_BUSWIDTH_16;
+	ret = of_get_nand_bus_width(chip);
+	if (ret)
+		return ret;
 
 	if (of_property_read_bool(dn, "nand-is-boot-medium"))
 		chip->options |= NAND_IS_BOOT_MEDIUM;
-- 
2.25.1


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

* Re: [PATCH 1/2] mtd: rawnand: Remove of_get_nand_on_flash_bbt() wrapper
  2022-01-06 13:16 [PATCH 1/2] mtd: rawnand: Remove of_get_nand_on_flash_bbt() wrapper Tudor Ambarus
  2022-01-06 13:16 ` [PATCH 2/2] mtd: rawnand: Rework of_get_nand_bus_width() Tudor Ambarus
@ 2022-01-23 15:43 ` Miquel Raynal
  1 sibling, 0 replies; 3+ messages in thread
From: Miquel Raynal @ 2022-01-23 15:43 UTC (permalink / raw)
  To: Tudor Ambarus; +Cc: richard, vigneshr, linux-mtd, linux-kernel

Hi Tudor,

tudor.ambarus@microchip.com wrote on Thu, 6 Jan 2022 15:16:09 +0200:

> Remove the wrapper as it hides for no reason what we really want: find an
> of_property. Removing the wrapper makes the code easier to read.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Series applies to nand/next.

Thanks,
Miquèl

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

end of thread, other threads:[~2022-01-23 15:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-06 13:16 [PATCH 1/2] mtd: rawnand: Remove of_get_nand_on_flash_bbt() wrapper Tudor Ambarus
2022-01-06 13:16 ` [PATCH 2/2] mtd: rawnand: Rework of_get_nand_bus_width() Tudor Ambarus
2022-01-23 15:43 ` [PATCH 1/2] mtd: rawnand: Remove of_get_nand_on_flash_bbt() wrapper Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).