Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1259927 > unrolled thread

[PATCH v2 00/11] mtd: migrate 'of_node' handling to core, not in mtd_part_parser_data

Started byBrian Norris <computersforpeace@gmail.com>
First post2015-10-31 04:40 +0100
Last post2015-11-12 14:30 +0100
Articles 12 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v2 00/11] mtd: migrate 'of_node' handling to core, not in mtd_part_parser_data Brian Norris <computersforpeace@gmail.com> - 2015-10-31 04:40 +0100
    [PATCH v2 05/11] mtd: spi-nor: convert to spi_nor_{get,set}_flash_node() Brian Norris <computersforpeace@gmail.com> - 2015-10-31 04:40 +0100
    [PATCH v2 06/11] mtd: nand: drop unnecessary partition parser data Brian Norris <computersforpeace@gmail.com> - 2015-10-31 04:40 +0100
      Re: [PATCH v2 06/11] mtd: nand: drop unnecessary partition parser  data Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-11-01 23:40 +0100
        Re: [PATCH v2 06/11] mtd: nand: drop unnecessary partition parser  data Brian Norris <computersforpeace@gmail.com> - 2015-11-02 22:10 +0100
          Re: [PATCH v2 06/11] mtd: nand: drop unnecessary partition parser  data Brian Norris <computersforpeace@gmail.com> - 2015-11-12 00:50 +0100
    Re: [PATCH v2 00/11] mtd: migrate 'of_node' handling to core, not  in mtd_part_parser_data Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-11-01 09:10 +0100
    [PATCH v2 12/11] mtd: nand: convert to nand_get_flash_node() Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-11-02 00:10 +0100
      Re: [PATCH v2 12/11] mtd: nand: convert to nand_get_flash_node() Brian Norris <computersforpeace@gmail.com> - 2015-11-12 01:00 +0100
    [PATCH v2 13/11] mtd: assign mtd->dev.of_node when creating partition devices Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-11-02 01:40 +0100
      Re: [PATCH v2 13/11] mtd: assign mtd->dev.of_node when creating  partition devices Brian Norris <computersforpeace@gmail.com> - 2015-11-12 01:20 +0100
        Re: [PATCH v2 13/11] mtd: assign mtd->dev.of_node when creating  partition devices Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-11-12 14:30 +0100

#1259927 — [PATCH v2 00/11] mtd: migrate 'of_node' handling to core, not in mtd_part_parser_data

FromBrian Norris <computersforpeace@gmail.com>
Date2015-10-31 04:40 +0100
Subject[PATCH v2 00/11] mtd: migrate 'of_node' handling to core, not in mtd_part_parser_data
Message-ID<qpvbj-69C-5@gated-at.bofh.it>
Hi,

I noticed that, for MTD drivers that want to support DT partition parsing
(essentially all recent ones), it's a bit awkward to set the tell MTD which DT
node to use. I also noticed that this info is duplicated in a few places;
namely, some sub-subsystems (like SPI NOR and NAND) need their own field to
track the DT node, so let's have the propagate the 'MTD' DT node down for us.

Besides simplifying the boilerplate throughout MTD, this series also has the
side effect of producing 'of_node' symlinks in sysfs. e.g.:

  # ls -al /sys/class/mtd/mtd0/of_node
  lrwxrwxrwx 1 root root 0 Oct 26 19:17 /sys/class/mtd/mtd0/of_node -> ../../../../firmware/devicetree/base/spi@ff130000/flash@0

For NAND, this potentially has some other bigger initial side effects, since
nand_dt_init() handles a bit more automagically for drivers that defined their
->flash_node. But these drivers should probably convert anyway. So, please test
your favorite driver!

v1 -> v2:
 * add helper functions for getting/setting the MTD/SPI-NOR/NAND DT node
 * fix some build errors
 * drop spi_nor's flash_node field (just use the MTD of_node)

Regards,
Brian

Brian Norris (11):
  mtd: add get/set of_node/flash_node helpers
  mtd: ofpart: grab device tree node directly from master device node
  mtd: {nand,spi-nor}: assign MTD of_node
  mtd: nand: convert to nand_set_flash_node()
  mtd: spi-nor: convert to spi_nor_{get,set}_flash_node()
  mtd: nand: drop unnecessary partition parser data
  mtd: spi-nor: drop unnecessary partition parser data
  mtd: spi-nor: drop flash_node field
  mtd: drop unnecessary partition parser data
  mtd: ofpart: drop 'of_node' partition parser data
  mtd: physmap_of: assign parent for the concatenated MTD

 drivers/mtd/devices/m25p80.c                  | 10 +++-------
 drivers/mtd/devices/mtd_dataflash.c           |  5 ++---
 drivers/mtd/devices/spear_smi.c               |  6 ++----
 drivers/mtd/devices/st_spi_fsm.c              |  5 ++---
 drivers/mtd/maps/lantiq-flash.c               |  5 ++---
 drivers/mtd/maps/physmap_of.c                 |  6 +++---
 drivers/mtd/nand/atmel_nand.c                 |  7 +++----
 drivers/mtd/nand/brcmnand/brcmnand.c          |  5 ++---
 drivers/mtd/nand/davinci_nand.c               | 10 +++-------
 drivers/mtd/nand/fsl_elbc_nand.c              |  5 ++---
 drivers/mtd/nand/fsl_ifc_nand.c               |  5 ++---
 drivers/mtd/nand/fsl_upm.c                    |  5 ++---
 drivers/mtd/nand/fsmc_nand.c                  |  9 ++++-----
 drivers/mtd/nand/gpio.c                       |  8 +++-----
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c        |  5 ++---
 drivers/mtd/nand/hisi504_nand.c               |  5 ++---
 drivers/mtd/nand/lpc32xx_mlc.c                |  7 +++----
 drivers/mtd/nand/lpc32xx_slc.c                |  7 +++----
 drivers/mtd/nand/mpc5121_nfc.c                |  5 ++---
 drivers/mtd/nand/mxc_nand.c                   |  5 ++---
 drivers/mtd/nand/nand_base.c                  |  3 +++
 drivers/mtd/nand/ndfc.c                       |  5 ++---
 drivers/mtd/nand/omap2.c                      |  6 ++----
 drivers/mtd/nand/orion_nand.c                 |  6 ++----
 drivers/mtd/nand/plat_nand.c                  |  5 ++---
 drivers/mtd/nand/pxa3xx_nand.c                | 10 +++++-----
 drivers/mtd/nand/sh_flctl.c                   |  6 ++----
 drivers/mtd/nand/socrates_nand.c              |  5 ++---
 drivers/mtd/nand/sunxi_nand.c                 |  6 ++----
 drivers/mtd/nand/vf610_nfc.c                  |  8 ++------
 drivers/mtd/ofpart.c                          | 12 ++++--------
 drivers/mtd/onenand/omap2.c                   |  8 +++-----
 drivers/mtd/spi-nor/fsl-quadspi.c             |  6 ++----
 drivers/mtd/spi-nor/nxp-spifi.c               |  6 ++----
 drivers/mtd/spi-nor/spi-nor.c                 |  2 +-
 drivers/staging/mt29f_spinand/mt29f_spinand.c |  5 ++---
 include/linux/mtd/mtd.h                       | 11 +++++++++++
 include/linux/mtd/nand.h                      | 11 +++++++++++
 include/linux/mtd/partitions.h                |  2 --
 include/linux/mtd/spi-nor.h                   | 13 +++++++++++--
 40 files changed, 120 insertions(+), 141 deletions(-)

-- 
2.6.0.rc2.230.g3dd15c0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1259928 — [PATCH v2 05/11] mtd: spi-nor: convert to spi_nor_{get,set}_flash_node()

FromBrian Norris <computersforpeace@gmail.com>
Date2015-10-31 04:40 +0100
Subject[PATCH v2 05/11] mtd: spi-nor: convert to spi_nor_{get,set}_flash_node()
Message-ID<qpvbk-69C-33@gated-at.bofh.it>
In reply to#1259927
Used semantic patch with 'make coccicheck MODE=patch COCCI=script.cocci':

---8<----
virtual patch

@@
struct spi_nor b;
struct spi_nor *c;
expression d;
@@
(
-(b).flash_node = (d)
+spi_nor_set_flash_node(&b, d)
|
-(c)->flash_node = (d)
+spi_nor_set_flash_node(c, d)
)
---8<----

And a manual conversion for the one use of spi_nor_get_flash_node().

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
v2: new

 drivers/mtd/devices/m25p80.c      | 2 +-
 drivers/mtd/spi-nor/fsl-quadspi.c | 2 +-
 drivers/mtd/spi-nor/nxp-spifi.c   | 2 +-
 drivers/mtd/spi-nor/spi-nor.c     | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 4b5d7a4655fd..556b4554007f 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -199,7 +199,7 @@ static int m25p_probe(struct spi_device *spi)
 	nor->read_reg = m25p80_read_reg;
 
 	nor->dev = &spi->dev;
-	nor->flash_node = spi->dev.of_node;
+	spi_nor_set_flash_node(nor, spi->dev.of_node);
 	nor->priv = flash;
 
 	spi_set_drvdata(spi, flash);
diff --git a/drivers/mtd/spi-nor/fsl-quadspi.c b/drivers/mtd/spi-nor/fsl-quadspi.c
index 7b10ed413983..8f4d9204d2b2 100644
--- a/drivers/mtd/spi-nor/fsl-quadspi.c
+++ b/drivers/mtd/spi-nor/fsl-quadspi.c
@@ -1013,7 +1013,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
 		mtd = &nor->mtd;
 
 		nor->dev = dev;
-		nor->flash_node = np;
+		spi_nor_set_flash_node(nor, np);
 		nor->priv = q;
 
 		/* fill the hooks */
diff --git a/drivers/mtd/spi-nor/nxp-spifi.c b/drivers/mtd/spi-nor/nxp-spifi.c
index 9e82098ae644..4524b2886946 100644
--- a/drivers/mtd/spi-nor/nxp-spifi.c
+++ b/drivers/mtd/spi-nor/nxp-spifi.c
@@ -330,7 +330,7 @@ static int nxp_spifi_setup_flash(struct nxp_spifi *spifi,
 	writel(ctrl, spifi->io_base + SPIFI_CTRL);
 
 	spifi->nor.dev   = spifi->dev;
-	spifi->nor.flash_node = np;
+	spi_nor_set_flash_node(&spifi->nor, np);
 	spifi->nor.priv  = spifi;
 	spifi->nor.read  = nxp_spifi_read;
 	spifi->nor.write = nxp_spifi_write;
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 1d3107ccee61..924d455dadb5 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -1151,7 +1151,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
 	const struct flash_info *info = NULL;
 	struct device *dev = nor->dev;
 	struct mtd_info *mtd = &nor->mtd;
-	struct device_node *np = nor->flash_node;
+	struct device_node *np = spi_nor_get_flash_node(nor);
 	int ret;
 	int i;
 
-- 
2.6.0.rc2.230.g3dd15c0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1259929 — [PATCH v2 06/11] mtd: nand: drop unnecessary partition parser data

FromBrian Norris <computersforpeace@gmail.com>
Date2015-10-31 04:40 +0100
Subject[PATCH v2 06/11] mtd: nand: drop unnecessary partition parser data
Message-ID<qpvbj-69C-7@gated-at.bofh.it>
In reply to#1259927
All of these drivers set up a parser data struct just to communicate DT
partition data. This field has been deprecated and is instead supported
by telling nand_scan_ident() about the 'flash_node'.

This patch:
 * sets chip->flash_node for those drivers that didn't already (but used
   OF partitioning)
 * drops the parser data
 * switches to the simpler mtd_device_register() where possible, now
   that we've eliminated one of the auxiliary parameters

Now that we've assigned chip->flash_node for these drivers, we can
probably rely on nand_dt_init() to do more of the DT parsing for us, but
for now, I don't want to fiddle with each of these drivers. The parsing
is done in duplicate for now on some drivers. I don't think this should
break things. (Famous last words.)

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
v2: fix compile errors, use new helpers to set the DT node

 drivers/mtd/nand/atmel_nand.c                 |  7 +++----
 drivers/mtd/nand/brcmnand/brcmnand.c          |  3 +--
 drivers/mtd/nand/davinci_nand.c               | 10 +++-------
 drivers/mtd/nand/fsl_elbc_nand.c              |  5 ++---
 drivers/mtd/nand/fsl_ifc_nand.c               |  5 ++---
 drivers/mtd/nand/fsl_upm.c                    |  5 ++---
 drivers/mtd/nand/fsmc_nand.c                  |  7 +++----
 drivers/mtd/nand/gpio.c                       |  8 +++-----
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c        |  5 ++---
 drivers/mtd/nand/hisi504_nand.c               |  5 ++---
 drivers/mtd/nand/lpc32xx_mlc.c                |  7 +++----
 drivers/mtd/nand/lpc32xx_slc.c                |  7 +++----
 drivers/mtd/nand/mpc5121_nfc.c                |  5 ++---
 drivers/mtd/nand/mxc_nand.c                   |  5 ++---
 drivers/mtd/nand/ndfc.c                       |  5 ++---
 drivers/mtd/nand/omap2.c                      |  6 ++----
 drivers/mtd/nand/orion_nand.c                 |  6 ++----
 drivers/mtd/nand/plat_nand.c                  |  5 ++---
 drivers/mtd/nand/pxa3xx_nand.c                | 10 +++++-----
 drivers/mtd/nand/sh_flctl.c                   |  6 ++----
 drivers/mtd/nand/socrates_nand.c              |  5 ++---
 drivers/mtd/nand/sunxi_nand.c                 |  4 +---
 drivers/mtd/nand/vf610_nfc.c                  |  6 +-----
 drivers/staging/mt29f_spinand/mt29f_spinand.c |  5 ++---
 24 files changed, 54 insertions(+), 88 deletions(-)

diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 583cdd9bb971..6ecc1c1ab437 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -2093,7 +2093,6 @@ static int atmel_nand_probe(struct platform_device *pdev)
 	struct mtd_info *mtd;
 	struct nand_chip *nand_chip;
 	struct resource *mem;
-	struct mtd_part_parser_data ppdata = {};
 	int res, irq;
 
 	/* Allocate memory for the device structure (and zero it) */
@@ -2117,6 +2116,7 @@ static int atmel_nand_probe(struct platform_device *pdev)
 	nand_chip = &host->nand_chip;
 	host->dev = &pdev->dev;
 	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
+		nand_set_flash_node(nand_chip, pdev->dev.of_node);
 		/* Only when CONFIG_OF is enabled of_node can be parsed */
 		res = atmel_of_init_port(host, pdev->dev.of_node);
 		if (res)
@@ -2259,9 +2259,8 @@ static int atmel_nand_probe(struct platform_device *pdev)
 	}
 
 	mtd->name = "atmel_nand";
-	ppdata.of_node = pdev->dev.of_node;
-	res = mtd_device_parse_register(mtd, NULL, &ppdata,
-			host->board.parts, host->board.num_parts);
+	res = mtd_device_register(mtd, host->board.parts,
+				  host->board.num_parts);
 	if (!res)
 		return res;
 
diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c
index 7bd4102fde42..a37659de025c 100644
--- a/drivers/mtd/nand/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/brcmnand/brcmnand.c
@@ -1914,7 +1914,6 @@ static int brcmnand_init_cs(struct brcmnand_host *host)
 	struct nand_chip *chip;
 	int ret;
 	u16 cfg_offs;
-	struct mtd_part_parser_data ppdata = { .of_node = dn };
 
 	ret = of_property_read_u32(dn, "reg", &host->cs);
 	if (ret) {
@@ -1993,7 +1992,7 @@ static int brcmnand_init_cs(struct brcmnand_host *host)
 	if (nand_scan_tail(mtd))
 		return -ENXIO;
 
-	return mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+	return mtd_device_register(mtd, NULL, 0);
 }
 
 static void brcmnand_save_restore_cs_config(struct brcmnand_host *host,
diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c
index c72313d66cf6..8e351af31e53 100644
--- a/drivers/mtd/nand/davinci_nand.c
+++ b/drivers/mtd/nand/davinci_nand.c
@@ -684,6 +684,7 @@ static int nand_davinci_probe(struct platform_device *pdev)
 
 	info->mtd.priv		= &info->chip;
 	info->mtd.dev.parent	= &pdev->dev;
+	nand_set_flash_node(&info->chip, pdev->dev.of_node);
 
 	info->chip.IO_ADDR_R	= vaddr;
 	info->chip.IO_ADDR_W	= vaddr;
@@ -839,13 +840,8 @@ syndrome_done:
 	if (pdata->parts)
 		ret = mtd_device_parse_register(&info->mtd, NULL, NULL,
 					pdata->parts, pdata->nr_parts);
-	else {
-		struct mtd_part_parser_data	ppdata;
-
-		ppdata.of_node = pdev->dev.of_node;
-		ret = mtd_device_parse_register(&info->mtd, NULL, &ppdata,
-						NULL, 0);
-	}
+	else
+		ret = mtd_device_register(&info->mtd, NULL, 0);
 	if (ret < 0)
 		goto err;
 
diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
index dcb1f7f4873f..850546dc98c8 100644
--- a/drivers/mtd/nand/fsl_elbc_nand.c
+++ b/drivers/mtd/nand/fsl_elbc_nand.c
@@ -748,6 +748,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
 	/* Fill in fsl_elbc_mtd structure */
 	priv->mtd.priv = chip;
 	priv->mtd.dev.parent = priv->dev;
+	chip->flash_node = priv->dev->of_node;
 
 	/* set timeout to maximum */
 	priv->fmr = 15 << FMR_CWTO_SHIFT;
@@ -823,9 +824,7 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev)
 	int bank;
 	struct device *dev;
 	struct device_node *node = pdev->dev.of_node;
-	struct mtd_part_parser_data ppdata;
 
-	ppdata.of_node = pdev->dev.of_node;
 	if (!fsl_lbc_ctrl_dev || !fsl_lbc_ctrl_dev->regs)
 		return -ENODEV;
 	lbc = fsl_lbc_ctrl_dev->regs;
@@ -911,7 +910,7 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev)
 
 	/* First look for RedBoot table or partitions on the command
 	 * line, these take precedence over device tree information */
-	mtd_device_parse_register(&priv->mtd, part_probe_types, &ppdata,
+	mtd_device_parse_register(&priv->mtd, part_probe_types, NULL,
 				  NULL, 0);
 
 	printk(KERN_INFO "eLBC NAND device at 0x%llx, bank %d\n",
diff --git a/drivers/mtd/nand/fsl_ifc_nand.c b/drivers/mtd/nand/fsl_ifc_nand.c
index 7f4ac8c19001..8ae2a237ed4d 100644
--- a/drivers/mtd/nand/fsl_ifc_nand.c
+++ b/drivers/mtd/nand/fsl_ifc_nand.c
@@ -883,6 +883,7 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
 	/* Fill in fsl_ifc_mtd structure */
 	priv->mtd.priv = chip;
 	priv->mtd.dev.parent = priv->dev;
+	chip->flash_node = priv->dev->of_node;
 
 	/* fill in nand_chip structure */
 	/* set up function call table */
@@ -1030,9 +1031,7 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)
 	int ret;
 	int bank;
 	struct device_node *node = dev->dev.of_node;
-	struct mtd_part_parser_data ppdata;
 
-	ppdata.of_node = dev->dev.of_node;
 	if (!fsl_ifc_ctrl_dev || !fsl_ifc_ctrl_dev->regs)
 		return -ENODEV;
 	ifc = fsl_ifc_ctrl_dev->regs;
@@ -1128,7 +1127,7 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)
 
 	/* First look for RedBoot table or partitions on the command
 	 * line, these take precedence over device tree information */
-	mtd_device_parse_register(&priv->mtd, part_probe_types, &ppdata,
+	mtd_device_parse_register(&priv->mtd, part_probe_types, NULL,
 						NULL, 0);
 
 	dev_info(priv->dev, "IFC NAND device at 0x%llx, bank %d\n",
diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c
index d326369980c4..ffe416c08914 100644
--- a/drivers/mtd/nand/fsl_upm.c
+++ b/drivers/mtd/nand/fsl_upm.c
@@ -159,7 +159,6 @@ static int fun_chip_init(struct fsl_upm_nand *fun,
 {
 	int ret;
 	struct device_node *flash_np;
-	struct mtd_part_parser_data ppdata;
 
 	fun->chip.IO_ADDR_R = fun->io_base;
 	fun->chip.IO_ADDR_W = fun->io_base;
@@ -182,6 +181,7 @@ static int fun_chip_init(struct fsl_upm_nand *fun,
 	if (!flash_np)
 		return -ENODEV;
 
+	fun->chip.flash_node = flash_np;
 	fun->mtd.name = kasprintf(GFP_KERNEL, "0x%llx.%s", (u64)io_res->start,
 				  flash_np->name);
 	if (!fun->mtd.name) {
@@ -193,8 +193,7 @@ static int fun_chip_init(struct fsl_upm_nand *fun,
 	if (ret)
 		goto err;
 
-	ppdata.of_node = flash_np;
-	ret = mtd_device_parse_register(&fun->mtd, NULL, &ppdata, NULL, 0);
+	ret = mtd_device_register(&fun->mtd, NULL, 0);
 err:
 	of_node_put(flash_np);
 	if (ret)
diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c
index 6f9e422e947e..59fc6d0c3910 100644
--- a/drivers/mtd/nand/fsmc_nand.c
+++ b/drivers/mtd/nand/fsmc_nand.c
@@ -926,7 +926,6 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
 {
 	struct fsmc_nand_platform_data *pdata = dev_get_platdata(&pdev->dev);
 	struct device_node __maybe_unused *np = pdev->dev.of_node;
-	struct mtd_part_parser_data ppdata = {};
 	struct fsmc_nand_data *host;
 	struct mtd_info *mtd;
 	struct nand_chip *nand;
@@ -1016,6 +1015,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
 	nand = &host->nand;
 	mtd->priv = nand;
 	nand->priv = host;
+	nand_set_flash_node(nand, np);
 
 	host->mtd.dev.parent = &pdev->dev;
 	nand->IO_ADDR_R = host->data_va;
@@ -1175,9 +1175,8 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
 	 * Check for partition info passed
 	 */
 	host->mtd.name = "nand";
-	ppdata.of_node = np;
-	ret = mtd_device_parse_register(&host->mtd, NULL, &ppdata,
-					host->partitions, host->nr_partitions);
+	ret = mtd_device_register(&host->mtd, host->partitions,
+				  host->nr_partitions);
 	if (ret)
 		goto err_probe;
 
diff --git a/drivers/mtd/nand/gpio.c b/drivers/mtd/nand/gpio.c
index 9ab97f934c37..289a48c2ca50 100644
--- a/drivers/mtd/nand/gpio.c
+++ b/drivers/mtd/nand/gpio.c
@@ -209,7 +209,6 @@ static int gpio_nand_probe(struct platform_device *pdev)
 	struct gpiomtd *gpiomtd;
 	struct nand_chip *chip;
 	struct resource *res;
-	struct mtd_part_parser_data ppdata = {};
 	int ret = 0;
 
 	if (!pdev->dev.of_node && !dev_get_platdata(&pdev->dev))
@@ -268,6 +267,7 @@ static int gpio_nand_probe(struct platform_device *pdev)
 		chip->dev_ready = gpio_nand_devready;
 	}
 
+	chip->flash_node	= pdev->dev.of_node;
 	chip->IO_ADDR_W		= chip->IO_ADDR_R;
 	chip->ecc.mode		= NAND_ECC_SOFT;
 	chip->options		= gpiomtd->plat.options;
@@ -291,10 +291,8 @@ static int gpio_nand_probe(struct platform_device *pdev)
 		gpiomtd->plat.adjust_parts(&gpiomtd->plat,
 					   gpiomtd->mtd_info.size);
 
-	ppdata.of_node = pdev->dev.of_node;
-	ret = mtd_device_parse_register(&gpiomtd->mtd_info, NULL, &ppdata,
-					gpiomtd->plat.parts,
-					gpiomtd->plat.num_parts);
+	ret = mtd_device_register(&gpiomtd->mtd_info, gpiomtd->plat.parts,
+				  gpiomtd->plat.num_parts);
 	if (!ret)
 		return 0;
 
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
index 2064adac1d17..90e49ccade45 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
@@ -1888,7 +1888,6 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)
 {
 	struct mtd_info  *mtd = &this->mtd;
 	struct nand_chip *chip = &this->nand;
-	struct mtd_part_parser_data ppdata = {};
 	int ret;
 
 	/* init current chip */
@@ -1901,6 +1900,7 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)
 
 	/* init the nand_chip{}, we don't support a 16-bit NAND Flash bus. */
 	chip->priv		= this;
+	chip->flash_node	= this->pdev->dev.of_node;
 	chip->select_chip	= gpmi_select_chip;
 	chip->cmd_ctrl		= gpmi_cmd_ctrl;
 	chip->dev_ready		= gpmi_dev_ready;
@@ -1954,8 +1954,7 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)
 	if (ret)
 		goto err_out;
 
-	ppdata.of_node = this->pdev->dev.of_node;
-	ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+	ret = mtd_device_register(mtd, NULL, 0);
 	if (ret)
 		goto err_out;
 	return 0;
diff --git a/drivers/mtd/nand/hisi504_nand.c b/drivers/mtd/nand/hisi504_nand.c
index 0cb2e886937d..0aad4acab9d6 100644
--- a/drivers/mtd/nand/hisi504_nand.c
+++ b/drivers/mtd/nand/hisi504_nand.c
@@ -704,7 +704,6 @@ static int hisi_nfc_probe(struct platform_device *pdev)
 	struct mtd_info   *mtd;
 	struct resource	  *res;
 	struct device_node *np = dev->of_node;
-	struct mtd_part_parser_data ppdata;
 
 	host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
 	if (!host)
@@ -742,6 +741,7 @@ static int hisi_nfc_probe(struct platform_device *pdev)
 	mtd->dev.parent         = &pdev->dev;
 
 	chip->priv		= host;
+	nand_set_flash_node(chip, np);
 	chip->cmdfunc		= hisi_nfc_cmdfunc;
 	chip->select_chip	= hisi_nfc_select_chip;
 	chip->read_byte		= hisi_nfc_read_byte;
@@ -805,8 +805,7 @@ static int hisi_nfc_probe(struct platform_device *pdev)
 		goto err_res;
 	}
 
-	ppdata.of_node = np;
-	ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+	ret = mtd_device_register(mtd, NULL, 0);
 	if (ret) {
 		dev_err(dev, "Err MTD partition=%d\n", ret);
 		goto err_mtd;
diff --git a/drivers/mtd/nand/lpc32xx_mlc.c b/drivers/mtd/nand/lpc32xx_mlc.c
index 347510978484..3ccad8ce70fa 100644
--- a/drivers/mtd/nand/lpc32xx_mlc.c
+++ b/drivers/mtd/nand/lpc32xx_mlc.c
@@ -647,7 +647,6 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 	struct nand_chip *nand_chip;
 	struct resource *rc;
 	int res;
-	struct mtd_part_parser_data ppdata = {};
 
 	/* Allocate memory for the device structure (and zero it) */
 	host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
@@ -682,6 +681,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 	host->pdata = dev_get_platdata(&pdev->dev);
 
 	nand_chip->priv = host;		/* link the private data structures */
+	nand_chip->flash_node = pdev->dev.of_node;
 	mtd->priv = nand_chip;
 	mtd->dev.parent = &pdev->dev;
 
@@ -786,9 +786,8 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 
 	mtd->name = DRV_NAME;
 
-	ppdata.of_node = pdev->dev.of_node;
-	res = mtd_device_parse_register(mtd, NULL, &ppdata, host->ncfg->parts,
-					host->ncfg->num_parts);
+	res = mtd_device_register(mtd, host->ncfg->parts,
+				  host->ncfg->num_parts);
 	if (!res)
 		return res;
 
diff --git a/drivers/mtd/nand/lpc32xx_slc.c b/drivers/mtd/nand/lpc32xx_slc.c
index 4f3d4eb17da0..9cb82066c522 100644
--- a/drivers/mtd/nand/lpc32xx_slc.c
+++ b/drivers/mtd/nand/lpc32xx_slc.c
@@ -763,7 +763,6 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 	struct mtd_info *mtd;
 	struct nand_chip *chip;
 	struct resource *rc;
-	struct mtd_part_parser_data ppdata = {};
 	int res;
 
 	rc = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -803,6 +802,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 	mtd = &host->mtd;
 	chip = &host->nand_chip;
 	chip->priv = host;
+	chip->flash_node = pdev->dev.of_node;
 	mtd->priv = chip;
 	mtd->owner = THIS_MODULE;
 	mtd->dev.parent = &pdev->dev;
@@ -908,9 +908,8 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 	}
 
 	mtd->name = "nxp_lpc3220_slc";
-	ppdata.of_node = pdev->dev.of_node;
-	res = mtd_device_parse_register(mtd, NULL, &ppdata, host->ncfg->parts,
-					host->ncfg->num_parts);
+	res = mtd_device_register(mtd, host->ncfg->parts,
+				  host->ncfg->num_parts);
 	if (!res)
 		return res;
 
diff --git a/drivers/mtd/nand/mpc5121_nfc.c b/drivers/mtd/nand/mpc5121_nfc.c
index d6bbde4a5331..0fdfc42f75f8 100644
--- a/drivers/mtd/nand/mpc5121_nfc.c
+++ b/drivers/mtd/nand/mpc5121_nfc.c
@@ -639,7 +639,6 @@ static int mpc5121_nfc_probe(struct platform_device *op)
 	int resettime = 0;
 	int retval = 0;
 	int rev, len;
-	struct mtd_part_parser_data ppdata;
 
 	/*
 	 * Check SoC revision. This driver supports only NFC
@@ -661,6 +660,7 @@ static int mpc5121_nfc_probe(struct platform_device *op)
 	mtd->priv = chip;
 	mtd->dev.parent = dev;
 	chip->priv = prv;
+	nand_set_flash_node(chip, dn);
 	prv->dev = dev;
 
 	/* Read NFC configuration from Reset Config Word */
@@ -703,7 +703,6 @@ static int mpc5121_nfc_probe(struct platform_device *op)
 	}
 
 	mtd->name = "MPC5121 NAND";
-	ppdata.of_node = dn;
 	chip->dev_ready = mpc5121_nfc_dev_ready;
 	chip->cmdfunc = mpc5121_nfc_command;
 	chip->read_byte = mpc5121_nfc_read_byte;
@@ -815,7 +814,7 @@ static int mpc5121_nfc_probe(struct platform_device *op)
 	dev_set_drvdata(dev, mtd);
 
 	/* Register device in MTD */
-	retval = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+	retval = mtd_device_register(mtd, NULL, 0);
 	if (retval) {
 		dev_err(dev, "Error adding MTD device!\n");
 		goto error;
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index 136e73a3e07e..0fc4f3a2412d 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -1524,6 +1524,7 @@ static int mxcnd_probe(struct platform_device *pdev)
 	this->chip_delay = 5;
 
 	this->priv = host;
+	this->flash_node = pdev->dev.of_node,
 	this->dev_ready = mxc_nand_dev_ready;
 	this->cmdfunc = mxc_nand_command;
 	this->read_byte = mxc_nand_read_byte;
@@ -1683,9 +1684,7 @@ static int mxcnd_probe(struct platform_device *pdev)
 
 	/* Register the partitions */
 	mtd_device_parse_register(mtd, part_probes,
-			&(struct mtd_part_parser_data){
-				.of_node = pdev->dev.of_node,
-			},
+			NULL,
 			host->pdata.parts,
 			host->pdata.nr_parts);
 
diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c
index 4f0d62f9d22c..69658584061b 100644
--- a/drivers/mtd/nand/ndfc.c
+++ b/drivers/mtd/nand/ndfc.c
@@ -147,7 +147,6 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
 {
 	struct device_node *flash_np;
 	struct nand_chip *chip = &ndfc->chip;
-	struct mtd_part_parser_data ppdata;
 	int ret;
 
 	chip->IO_ADDR_R = ndfc->ndfcbase + NDFC_DATA;
@@ -174,8 +173,8 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
 	flash_np = of_get_next_child(node, NULL);
 	if (!flash_np)
 		return -ENODEV;
+	nand_set_flash_node(chip, flash_np);
 
-	ppdata.of_node = flash_np;
 	ndfc->mtd.name = kasprintf(GFP_KERNEL, "%s.%s",
 			dev_name(&ndfc->ofdev->dev), flash_np->name);
 	if (!ndfc->mtd.name) {
@@ -187,7 +186,7 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
 	if (ret)
 		goto err;
 
-	ret = mtd_device_parse_register(&ndfc->mtd, NULL, &ppdata, NULL, 0);
+	ret = mtd_device_register(&ndfc->mtd, NULL, 0);
 
 err:
 	of_node_put(flash_np);
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index 93f664cd1c90..33718dc2be58 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -1663,7 +1663,6 @@ static int omap_nand_probe(struct platform_device *pdev)
 	unsigned			sig;
 	unsigned			oob_index;
 	struct resource			*res;
-	struct mtd_part_parser_data	ppdata = {};
 
 	pdata = dev_get_platdata(&pdev->dev);
 	if (pdata == NULL) {
@@ -1688,6 +1687,7 @@ static int omap_nand_probe(struct platform_device *pdev)
 	mtd->dev.parent		= &pdev->dev;
 	nand_chip		= &info->nand;
 	nand_chip->ecc.priv	= NULL;
+	nand_chip->flash_node	= pdata->of_node;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	nand_chip->IO_ADDR_R = devm_ioremap_resource(&pdev->dev, res);
@@ -2037,9 +2037,7 @@ scan_tail:
 		goto return_error;
 	}
 
-	ppdata.of_node = pdata->of_node;
-	mtd_device_parse_register(mtd, NULL, &ppdata, pdata->parts,
-				  pdata->nr_parts);
+	mtd_device_register(mtd, pdata->parts, pdata->nr_parts);
 
 	platform_set_drvdata(pdev, mtd);
 
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index ee83749fb1d3..0728ddc32914 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -76,7 +76,6 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 static int __init orion_nand_probe(struct platform_device *pdev)
 {
 	struct mtd_info *mtd;
-	struct mtd_part_parser_data ppdata = {};
 	struct nand_chip *nc;
 	struct orion_nand_data *board;
 	struct resource *res;
@@ -127,6 +126,7 @@ static int __init orion_nand_probe(struct platform_device *pdev)
 	mtd->dev.parent = &pdev->dev;
 
 	nc->priv = board;
+	nc->flash_node = pdev->dev.of_node;
 	nc->IO_ADDR_R = nc->IO_ADDR_W = io_base;
 	nc->cmd_ctrl = orion_nand_cmd_ctrl;
 	nc->read_buf = orion_nand_read_buf;
@@ -161,9 +161,7 @@ static int __init orion_nand_probe(struct platform_device *pdev)
 	}
 
 	mtd->name = "orion_nand";
-	ppdata.of_node = pdev->dev.of_node;
-	ret = mtd_device_parse_register(mtd, NULL, &ppdata,
-			board->parts, board->nr_parts);
+	ret = mtd_device_register(mtd, board->parts, board->nr_parts);
 	if (ret) {
 		nand_release(mtd);
 		goto no_dev;
diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index 65b9dbbe6d6a..034beccc863c 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -30,7 +30,6 @@ struct plat_nand_data {
 static int plat_nand_probe(struct platform_device *pdev)
 {
 	struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev);
-	struct mtd_part_parser_data ppdata;
 	struct plat_nand_data *data;
 	struct resource *res;
 	const char **part_types;
@@ -58,6 +57,7 @@ static int plat_nand_probe(struct platform_device *pdev)
 		return PTR_ERR(data->io_base);
 
 	data->chip.priv = &data;
+	data->chip.flash_node = pdev->dev.of_node;
 	data->mtd.priv = &data->chip;
 	data->mtd.dev.parent = &pdev->dev;
 
@@ -94,8 +94,7 @@ static int plat_nand_probe(struct platform_device *pdev)
 
 	part_types = pdata->chip.part_probe_types;
 
-	ppdata.of_node = pdev->dev.of_node;
-	err = mtd_device_parse_register(&data->mtd, part_types, &ppdata,
+	err = mtd_device_parse_register(&data->mtd, part_types, NULL,
 					pdata->chip.partitions,
 					pdata->chip.nr_partitions);
 
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index e453ae9a17fa..37df51df422e 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -1697,6 +1697,7 @@ KEEP_CONFIG:
 
 static int alloc_nand_resource(struct platform_device *pdev)
 {
+	struct device_node *np = pdev->dev.of_node;
 	struct pxa3xx_nand_platform_data *pdata;
 	struct pxa3xx_nand_info *info;
 	struct pxa3xx_nand_host *host;
@@ -1725,6 +1726,8 @@ static int alloc_nand_resource(struct platform_device *pdev)
 		host->info_data = info;
 		mtd->priv = host;
 		mtd->dev.parent = &pdev->dev;
+		/* FIXME: all chips use the same device tree partitions */
+		nand_set_flash_node(chip, np);
 
 		chip->ecc.read_page	= pxa3xx_nand_read_page_hwecc;
 		chip->ecc.write_page	= pxa3xx_nand_write_page_hwecc;
@@ -1886,7 +1889,6 @@ static int pxa3xx_nand_probe_dt(struct platform_device *pdev)
 static int pxa3xx_nand_probe(struct platform_device *pdev)
 {
 	struct pxa3xx_nand_platform_data *pdata;
-	struct mtd_part_parser_data ppdata = {};
 	struct pxa3xx_nand_info *info;
 	int ret, cs, probe_success, dma_available;
 
@@ -1933,10 +1935,8 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
 			continue;
 		}
 
-		ppdata.of_node = pdev->dev.of_node;
-		ret = mtd_device_parse_register(mtd, NULL,
-						&ppdata, pdata->parts[cs],
-						pdata->nr_parts[cs]);
+		ret = mtd_device_register(mtd, pdata->parts[cs],
+					  pdata->nr_parts[cs]);
 		if (!ret)
 			probe_success = 1;
 	}
diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c
index bcba1a924c75..ec2ade986b4e 100644
--- a/drivers/mtd/nand/sh_flctl.c
+++ b/drivers/mtd/nand/sh_flctl.c
@@ -1086,7 +1086,6 @@ static int flctl_probe(struct platform_device *pdev)
 	struct sh_flctl_platform_data *pdata;
 	int ret;
 	int irq;
-	struct mtd_part_parser_data ppdata = {};
 
 	flctl = devm_kzalloc(&pdev->dev, sizeof(struct sh_flctl), GFP_KERNEL);
 	if (!flctl)
@@ -1123,6 +1122,7 @@ static int flctl_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, flctl);
 	flctl_mtd = &flctl->mtd;
 	nand = &flctl->chip;
+	nand->flash_node = pdev->dev.of_node;
 	flctl_mtd->priv = nand;
 	flctl_mtd->dev.parent = &pdev->dev;
 	flctl->pdev = pdev;
@@ -1163,9 +1163,7 @@ static int flctl_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_chip;
 
-	ppdata.of_node = pdev->dev.of_node;
-	ret = mtd_device_parse_register(flctl_mtd, NULL, &ppdata, pdata->parts,
-			pdata->nr_parts);
+	ret = mtd_device_register(flctl_mtd, pdata->parts, pdata->nr_parts);
 
 	return 0;
 
diff --git a/drivers/mtd/nand/socrates_nand.c b/drivers/mtd/nand/socrates_nand.c
index b94f53427f0f..f93598578734 100644
--- a/drivers/mtd/nand/socrates_nand.c
+++ b/drivers/mtd/nand/socrates_nand.c
@@ -147,7 +147,6 @@ static int socrates_nand_probe(struct platform_device *ofdev)
 	struct mtd_info *mtd;
 	struct nand_chip *nand_chip;
 	int res;
-	struct mtd_part_parser_data ppdata;
 
 	/* Allocate memory for the device structure (and zero it) */
 	host = devm_kzalloc(&ofdev->dev, sizeof(*host), GFP_KERNEL);
@@ -165,10 +164,10 @@ static int socrates_nand_probe(struct platform_device *ofdev)
 	host->dev = &ofdev->dev;
 
 	nand_chip->priv = host;		/* link the private data structures */
+	nand_chip->flash_node = ofdev->dev.of_node;
 	mtd->priv = nand_chip;
 	mtd->name = "socrates_nand";
 	mtd->dev.parent = &ofdev->dev;
-	ppdata.of_node = ofdev->dev.of_node;
 
 	/*should never be accessed directly */
 	nand_chip->IO_ADDR_R = (void *)0xdeadbeef;
@@ -200,7 +199,7 @@ static int socrates_nand_probe(struct platform_device *ofdev)
 		goto out;
 	}
 
-	res = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+	res = mtd_device_register(mtd, NULL, 0);
 	if (!res)
 		return res;
 
diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
index df62c637c25e..10afcb15e18f 100644
--- a/drivers/mtd/nand/sunxi_nand.c
+++ b/drivers/mtd/nand/sunxi_nand.c
@@ -1232,7 +1232,6 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,
 {
 	const struct nand_sdr_timings *timings;
 	struct sunxi_nand_chip *chip;
-	struct mtd_part_parser_data ppdata;
 	struct mtd_info *mtd;
 	struct nand_chip *nand;
 	int nsels;
@@ -1366,8 +1365,7 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,
 		return ret;
 	}
 
-	ppdata.of_node = np;
-	ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+	ret = mtd_device_register(mtd, NULL, 0);
 	if (ret) {
 		dev_err(dev, "failed to register mtd device: %d\n", ret);
 		nand_release(mtd);
diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index 7b952abf4722..b6df4c6d60ca 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -811,11 +811,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, mtd);
 
 	/* Register device in MTD */
-	return mtd_device_parse_register(mtd, NULL,
-		&(struct mtd_part_parser_data){
-			.of_node = chip->flash_node,
-		},
-		NULL, 0);
+	return mtd_device_register(mtd, NULL, 0);
 
 error:
 	of_node_put(chip->flash_node);
diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.c b/drivers/staging/mt29f_spinand/mt29f_spinand.c
index 405b643189fd..bd9b5b0946f5 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
@@ -853,7 +853,6 @@ static int spinand_probe(struct spi_device *spi_nand)
 	struct nand_chip *chip;
 	struct spinand_info *info;
 	struct spinand_state *state;
-	struct mtd_part_parser_data ppdata;
 
 	info  = devm_kzalloc(&spi_nand->dev, sizeof(struct spinand_info),
 			GFP_KERNEL);
@@ -897,6 +896,7 @@ static int spinand_probe(struct spi_device *spi_nand)
 		pr_info("%s: disable ecc failed!\n", __func__);
 #endif
 
+	chip->flash_node = spi_nand->dev.of_node;
 	chip->priv	= info;
 	chip->read_buf	= spinand_read_buf;
 	chip->write_buf	= spinand_write_buf;
@@ -919,8 +919,7 @@ static int spinand_probe(struct spi_device *spi_nand)
 	if (nand_scan(mtd, 1))
 		return -ENXIO;
 
-	ppdata.of_node = spi_nand->dev.of_node;
-	return mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+	return mtd_device_register(mtd, NULL, 0);
 }
 
 /*
-- 
2.6.0.rc2.230.g3dd15c0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1260251 — Re: [PATCH v2 06/11] mtd: nand: drop unnecessary partition parser data

FromBoris Brezillon <boris.brezillon@free-electrons.com>
Date2015-11-01 23:40 +0100
SubjectRe: [PATCH v2 06/11] mtd: nand: drop unnecessary partition parser data
Message-ID<qq9s6-5Gg-15@gated-at.bofh.it>
In reply to#1259929
On Fri, 30 Oct 2015 20:33:25 -0700
Brian Norris <computersforpeace@gmail.com> wrote:

> All of these drivers set up a parser data struct just to communicate DT
> partition data. This field has been deprecated and is instead supported
> by telling nand_scan_ident() about the 'flash_node'.
> 
> This patch:
>  * sets chip->flash_node for those drivers that didn't already (but used
>    OF partitioning)
>  * drops the parser data
>  * switches to the simpler mtd_device_register() where possible, now
>    that we've eliminated one of the auxiliary parameters
> 
> Now that we've assigned chip->flash_node for these drivers, we can
> probably rely on nand_dt_init() to do more of the DT parsing for us, but
> for now, I don't want to fiddle with each of these drivers. The parsing
> is done in duplicate for now on some drivers. I don't think this should
> break things. (Famous last words.)
> 
> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
> Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
> v2: fix compile errors, use new helpers to set the DT node
> 
>  drivers/mtd/nand/atmel_nand.c                 |  7 +++----
>  drivers/mtd/nand/brcmnand/brcmnand.c          |  3 +--
>  drivers/mtd/nand/davinci_nand.c               | 10 +++-------
>  drivers/mtd/nand/fsl_elbc_nand.c              |  5 ++---
>  drivers/mtd/nand/fsl_ifc_nand.c               |  5 ++---
>  drivers/mtd/nand/fsl_upm.c                    |  5 ++---
>  drivers/mtd/nand/fsmc_nand.c                  |  7 +++----
>  drivers/mtd/nand/gpio.c                       |  8 +++-----
>  drivers/mtd/nand/gpmi-nand/gpmi-nand.c        |  5 ++---
>  drivers/mtd/nand/hisi504_nand.c               |  5 ++---
>  drivers/mtd/nand/lpc32xx_mlc.c                |  7 +++----
>  drivers/mtd/nand/lpc32xx_slc.c                |  7 +++----
>  drivers/mtd/nand/mpc5121_nfc.c                |  5 ++---
>  drivers/mtd/nand/mxc_nand.c                   |  5 ++---
>  drivers/mtd/nand/ndfc.c                       |  5 ++---
>  drivers/mtd/nand/omap2.c                      |  6 ++----
>  drivers/mtd/nand/orion_nand.c                 |  6 ++----
>  drivers/mtd/nand/plat_nand.c                  |  5 ++---
>  drivers/mtd/nand/pxa3xx_nand.c                | 10 +++++-----
>  drivers/mtd/nand/sh_flctl.c                   |  6 ++----
>  drivers/mtd/nand/socrates_nand.c              |  5 ++---
>  drivers/mtd/nand/sunxi_nand.c                 |  4 +---
>  drivers/mtd/nand/vf610_nfc.c                  |  6 +-----
>  drivers/staging/mt29f_spinand/mt29f_spinand.c |  5 ++---
>  24 files changed, 54 insertions(+), 88 deletions(-)
> 
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index 583cdd9bb971..6ecc1c1ab437 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -2093,7 +2093,6 @@ static int atmel_nand_probe(struct platform_device *pdev)
>  	struct mtd_info *mtd;
>  	struct nand_chip *nand_chip;
>  	struct resource *mem;
> -	struct mtd_part_parser_data ppdata = {};
>  	int res, irq;
>  
>  	/* Allocate memory for the device structure (and zero it) */
> @@ -2117,6 +2116,7 @@ static int atmel_nand_probe(struct platform_device *pdev)
>  	nand_chip = &host->nand_chip;
>  	host->dev = &pdev->dev;
>  	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
> +		nand_set_flash_node(nand_chip, pdev->dev.of_node);
>  		/* Only when CONFIG_OF is enabled of_node can be parsed */
>  		res = atmel_of_init_port(host, pdev->dev.of_node);
>  		if (res)
> @@ -2259,9 +2259,8 @@ static int atmel_nand_probe(struct platform_device *pdev)
>  	}
>  
>  	mtd->name = "atmel_nand";
> -	ppdata.of_node = pdev->dev.of_node;
> -	res = mtd_device_parse_register(mtd, NULL, &ppdata,
> -			host->board.parts, host->board.num_parts);
> +	res = mtd_device_register(mtd, host->board.parts,
> +				  host->board.num_parts);
>  	if (!res)
>  		return res;
>  
> diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c
> index 7bd4102fde42..a37659de025c 100644
> --- a/drivers/mtd/nand/brcmnand/brcmnand.c
> +++ b/drivers/mtd/nand/brcmnand/brcmnand.c
> @@ -1914,7 +1914,6 @@ static int brcmnand_init_cs(struct brcmnand_host *host)
>  	struct nand_chip *chip;
>  	int ret;
>  	u16 cfg_offs;
> -	struct mtd_part_parser_data ppdata = { .of_node = dn };
>  
>  	ret = of_property_read_u32(dn, "reg", &host->cs);
>  	if (ret) {
> @@ -1993,7 +1992,7 @@ static int brcmnand_init_cs(struct brcmnand_host *host)
>  	if (nand_scan_tail(mtd))
>  		return -ENXIO;
>  
> -	return mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
> +	return mtd_device_register(mtd, NULL, 0);
>  }
>  
>  static void brcmnand_save_restore_cs_config(struct brcmnand_host *host,
> diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c
> index c72313d66cf6..8e351af31e53 100644
> --- a/drivers/mtd/nand/davinci_nand.c
> +++ b/drivers/mtd/nand/davinci_nand.c
> @@ -684,6 +684,7 @@ static int nand_davinci_probe(struct platform_device *pdev)
>  
>  	info->mtd.priv		= &info->chip;
>  	info->mtd.dev.parent	= &pdev->dev;
> +	nand_set_flash_node(&info->chip, pdev->dev.of_node);
>  
>  	info->chip.IO_ADDR_R	= vaddr;
>  	info->chip.IO_ADDR_W	= vaddr;
> @@ -839,13 +840,8 @@ syndrome_done:
>  	if (pdata->parts)
>  		ret = mtd_device_parse_register(&info->mtd, NULL, NULL,
>  					pdata->parts, pdata->nr_parts);
> -	else {
> -		struct mtd_part_parser_data	ppdata;
> -
> -		ppdata.of_node = pdev->dev.of_node;
> -		ret = mtd_device_parse_register(&info->mtd, NULL, &ppdata,
> -						NULL, 0);
> -	}
> +	else
> +		ret = mtd_device_register(&info->mtd, NULL, 0);
>  	if (ret < 0)
>  		goto err;
>  
> diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
> index dcb1f7f4873f..850546dc98c8 100644
> --- a/drivers/mtd/nand/fsl_elbc_nand.c
> +++ b/drivers/mtd/nand/fsl_elbc_nand.c
> @@ -748,6 +748,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
>  	/* Fill in fsl_elbc_mtd structure */
>  	priv->mtd.priv = chip;
>  	priv->mtd.dev.parent = priv->dev;
> +	chip->flash_node = priv->dev->of_node;

Shouldn't we use the nand_set_flash_node() helper here? Here is a diff replacing
all 'chip->flash_node =' occurrences by nand_set_flash_node():

---->8----

diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
index 850546d..bd6d493 100644
--- a/drivers/mtd/nand/fsl_elbc_nand.c
+++ b/drivers/mtd/nand/fsl_elbc_nand.c
@@ -748,7 +748,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
 	/* Fill in fsl_elbc_mtd structure */
 	priv->mtd.priv = chip;
 	priv->mtd.dev.parent = priv->dev;
-	chip->flash_node = priv->dev->of_node;
+	nand_set_flash_node(chip, priv->dev->of_node);
 
 	/* set timeout to maximum */
 	priv->fmr = 15 << FMR_CWTO_SHIFT;
diff --git a/drivers/mtd/nand/fsl_ifc_nand.c b/drivers/mtd/nand/fsl_ifc_nand.c
index 8ae2a23..f260831 100644
--- a/drivers/mtd/nand/fsl_ifc_nand.c
+++ b/drivers/mtd/nand/fsl_ifc_nand.c
@@ -883,7 +883,7 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
 	/* Fill in fsl_ifc_mtd structure */
 	priv->mtd.priv = chip;
 	priv->mtd.dev.parent = priv->dev;
-	chip->flash_node = priv->dev->of_node;
+	nand_set_flash_node(chip, priv->dev->of_node);
 
 	/* fill in nand_chip structure */
 	/* set up function call table */
diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c
index ffe416c..b3f4a01 100644
--- a/drivers/mtd/nand/fsl_upm.c
+++ b/drivers/mtd/nand/fsl_upm.c
@@ -181,7 +181,7 @@ static int fun_chip_init(struct fsl_upm_nand *fun,
 	if (!flash_np)
 		return -ENODEV;
 
-	fun->chip.flash_node = flash_np;
+	nand_set_flash_node(&fun->chip, flash_np);
 	fun->mtd.name = kasprintf(GFP_KERNEL, "0x%llx.%s", (u64)io_res->start,
 				  flash_np->name);
 	if (!fun->mtd.name) {
diff --git a/drivers/mtd/nand/gpio.c b/drivers/mtd/nand/gpio.c
index 289a48c..d57a07a 100644
--- a/drivers/mtd/nand/gpio.c
+++ b/drivers/mtd/nand/gpio.c
@@ -267,7 +267,7 @@ static int gpio_nand_probe(struct platform_device *pdev)
 		chip->dev_ready = gpio_nand_devready;
 	}
 
-	chip->flash_node	= pdev->dev.of_node;
+	nand_set_flash_node(chip, pdev->dev.of_node);
 	chip->IO_ADDR_W		= chip->IO_ADDR_R;
 	chip->ecc.mode		= NAND_ECC_SOFT;
 	chip->options		= gpiomtd->plat.options;
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
index 90e49cc..5a9b696 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
@@ -1900,7 +1900,7 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)
 
 	/* init the nand_chip{}, we don't support a 16-bit NAND Flash bus. */
 	chip->priv		= this;
-	chip->flash_node	= this->pdev->dev.of_node;
+	nand_set_flash_node(chip, this->pdev->dev.of_node);
 	chip->select_chip	= gpmi_select_chip;
 	chip->cmd_ctrl		= gpmi_cmd_ctrl;
 	chip->dev_ready		= gpmi_dev_ready;
diff --git a/drivers/mtd/nand/lpc32xx_mlc.c b/drivers/mtd/nand/lpc32xx_mlc.c
index 3ccad8c..57c4b71 100644
--- a/drivers/mtd/nand/lpc32xx_mlc.c
+++ b/drivers/mtd/nand/lpc32xx_mlc.c
@@ -681,7 +681,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 	host->pdata = dev_get_platdata(&pdev->dev);
 
 	nand_chip->priv = host;		/* link the private data structures */
-	nand_chip->flash_node = pdev->dev.of_node;
+	nand_set_flash_node(nand_chip, pdev->dev.of_node);
 	mtd->priv = nand_chip;
 	mtd->dev.parent = &pdev->dev;
 
diff --git a/drivers/mtd/nand/lpc32xx_slc.c b/drivers/mtd/nand/lpc32xx_slc.c
index 9cb8206..277626e 100644
--- a/drivers/mtd/nand/lpc32xx_slc.c
+++ b/drivers/mtd/nand/lpc32xx_slc.c
@@ -802,7 +802,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 	mtd = &host->mtd;
 	chip = &host->nand_chip;
 	chip->priv = host;
-	chip->flash_node = pdev->dev.of_node;
+	nand_set_flash_node(chip, pdev->dev.of_node);
 	mtd->priv = chip;
 	mtd->owner = THIS_MODULE;
 	mtd->dev.parent = &pdev->dev;
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index 0fc4f3a..7922d31 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -1524,7 +1524,7 @@ static int mxcnd_probe(struct platform_device *pdev)
 	this->chip_delay = 5;
 
 	this->priv = host;
-	this->flash_node = pdev->dev.of_node,
+	nand_set_flash_node(this, pdev->dev.of_node),
 	this->dev_ready = mxc_nand_dev_ready;
 	this->cmdfunc = mxc_nand_command;
 	this->read_byte = mxc_nand_read_byte;
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index 33718dc..e307576 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -1687,7 +1687,7 @@ static int omap_nand_probe(struct platform_device *pdev)
 	mtd->dev.parent		= &pdev->dev;
 	nand_chip		= &info->nand;
 	nand_chip->ecc.priv	= NULL;
-	nand_chip->flash_node	= pdata->of_node;
+	nand_set_flash_node(nand_chip, pdata->of_node);
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	nand_chip->IO_ADDR_R = devm_ioremap_resource(&pdev->dev, res);
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index 0728ddc..5c21416 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -126,7 +126,7 @@ static int __init orion_nand_probe(struct platform_device *pdev)
 	mtd->dev.parent = &pdev->dev;
 
 	nc->priv = board;
-	nc->flash_node = pdev->dev.of_node;
+	nand_set_flash_node(nc, pdev->dev.of_node);
 	nc->IO_ADDR_R = nc->IO_ADDR_W = io_base;
 	nc->cmd_ctrl = orion_nand_cmd_ctrl;
 	nc->read_buf = orion_nand_read_buf;
diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index 034becc..06ac6c6 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -57,7 +57,7 @@ static int plat_nand_probe(struct platform_device *pdev)
 		return PTR_ERR(data->io_base);
 
 	data->chip.priv = &data;
-	data->chip.flash_node = pdev->dev.of_node;
+	nand_set_flash_node(&data->chip, pdev->dev.of_node);
 	data->mtd.priv = &data->chip;
 	data->mtd.dev.parent = &pdev->dev;
 
diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c
index ec2ade9..57dc525 100644
--- a/drivers/mtd/nand/sh_flctl.c
+++ b/drivers/mtd/nand/sh_flctl.c
@@ -1122,7 +1122,7 @@ static int flctl_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, flctl);
 	flctl_mtd = &flctl->mtd;
 	nand = &flctl->chip;
-	nand->flash_node = pdev->dev.of_node;
+	nand_set_flash_node(nand, pdev->dev.of_node);
 	flctl_mtd->priv = nand;
 	flctl_mtd->dev.parent = &pdev->dev;
 	flctl->pdev = pdev;
diff --git a/drivers/mtd/nand/socrates_nand.c b/drivers/mtd/nand/socrates_nand.c
index f935985..bde4043 100644
--- a/drivers/mtd/nand/socrates_nand.c
+++ b/drivers/mtd/nand/socrates_nand.c
@@ -164,7 +164,7 @@ static int socrates_nand_probe(struct platform_device *ofdev)
 	host->dev = &ofdev->dev;
 
 	nand_chip->priv = host;		/* link the private data structures */
-	nand_chip->flash_node = ofdev->dev.of_node;
+	nand_set_flash_node(nand_chip, ofdev->dev.of_node);
 	mtd->priv = nand_chip;
 	mtd->name = "socrates_nand";
 	mtd->dev.parent = &ofdev->dev;
diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.c b/drivers/staging/mt29f_spinand/mt29f_spinand.c
index bd9b5b0..49807de 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
@@ -896,7 +896,7 @@ static int spinand_probe(struct spi_device *spi_nand)
 		pr_info("%s: disable ecc failed!\n", __func__);
 #endif
 
-	chip->flash_node = spi_nand->dev.of_node;
+	nand_set_flash_node(chip, spi_nand->dev.of_node);
 	chip->priv	= info;
 	chip->read_buf	= spinand_read_buf;
 	chip->write_buf	= spinand_write_buf;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1260974 — Re: [PATCH v2 06/11] mtd: nand: drop unnecessary partition parser data

FromBrian Norris <computersforpeace@gmail.com>
Date2015-11-02 22:10 +0100
SubjectRe: [PATCH v2 06/11] mtd: nand: drop unnecessary partition parser data
Message-ID<qquwz-1Uo-21@gated-at.bofh.it>
In reply to#1260251
On Sun, Nov 01, 2015 at 11:32:37PM +0100, Boris Brezillon wrote:
> On Fri, 30 Oct 2015 20:33:25 -0700
> Brian Norris <computersforpeace@gmail.com> wrote:
> 
[...]
> > diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
> > index dcb1f7f4873f..850546dc98c8 100644
> > --- a/drivers/mtd/nand/fsl_elbc_nand.c
> > +++ b/drivers/mtd/nand/fsl_elbc_nand.c
> > @@ -748,6 +748,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
> >  	/* Fill in fsl_elbc_mtd structure */
> >  	priv->mtd.priv = chip;
> >  	priv->mtd.dev.parent = priv->dev;
> > +	chip->flash_node = priv->dev->of_node;
> 
> Shouldn't we use the nand_set_flash_node() helper here? Here is a diff replacing
> all 'chip->flash_node =' occurrences by nand_set_flash_node():

Hmm, I don't know why I overlooked those. I think maybe I did the
initial replacement before this patch and forgot to do the same
replacement on my subsequent work. I guess that's what happens when I
rebase/rework too much...

Thanks for the diff. I'll probably squash it into v3 if/when that comes.

Brian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1267543 — Re: [PATCH v2 06/11] mtd: nand: drop unnecessary partition parser data

FromBrian Norris <computersforpeace@gmail.com>
Date2015-11-12 00:50 +0100
SubjectRe: [PATCH v2 06/11] mtd: nand: drop unnecessary partition parser data
Message-ID<qtNjj-19f-7@gated-at.bofh.it>
In reply to#1260974
On Mon, Nov 02, 2015 at 01:00:01PM -0800, Brian Norris wrote:
> On Sun, Nov 01, 2015 at 11:32:37PM +0100, Boris Brezillon wrote:
> > On Fri, 30 Oct 2015 20:33:25 -0700
> > Brian Norris <computersforpeace@gmail.com> wrote:
> > 
> [...]
> > > diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
> > > index dcb1f7f4873f..850546dc98c8 100644
> > > --- a/drivers/mtd/nand/fsl_elbc_nand.c
> > > +++ b/drivers/mtd/nand/fsl_elbc_nand.c
> > > @@ -748,6 +748,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
> > >  	/* Fill in fsl_elbc_mtd structure */
> > >  	priv->mtd.priv = chip;
> > >  	priv->mtd.dev.parent = priv->dev;
> > > +	chip->flash_node = priv->dev->of_node;
> > 
> > Shouldn't we use the nand_set_flash_node() helper here? Here is a diff replacing
> > all 'chip->flash_node =' occurrences by nand_set_flash_node():
> 
> Hmm, I don't know why I overlooked those. I think maybe I did the
> initial replacement before this patch and forgot to do the same
> replacement on my subsequent work. I guess that's what happens when I
> rebase/rework too much...
> 
> Thanks for the diff. I'll probably squash it into v3 if/when that comes.

Pushed my patch 6 + your diff to l2-mtd.git/next. Thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1260094 — Re: [PATCH v2 00/11] mtd: migrate 'of_node' handling to core, not in mtd_part_parser_data

FromBoris Brezillon <boris.brezillon@free-electrons.com>
Date2015-11-01 09:10 +0100
SubjectRe: [PATCH v2 00/11] mtd: migrate 'of_node' handling to core, not in mtd_part_parser_data
Message-ID<qpVSa-5LP-5@gated-at.bofh.it>
In reply to#1259927
On Fri, 30 Oct 2015 20:33:19 -0700
Brian Norris <computersforpeace@gmail.com> wrote:

> Hi,
> 
> I noticed that, for MTD drivers that want to support DT partition parsing
> (essentially all recent ones), it's a bit awkward to set the tell MTD which DT
> node to use. I also noticed that this info is duplicated in a few places;
> namely, some sub-subsystems (like SPI NOR and NAND) need their own field to
> track the DT node, so let's have the propagate the 'MTD' DT node down for us.
> 
> Besides simplifying the boilerplate throughout MTD, this series also has the
> side effect of producing 'of_node' symlinks in sysfs. e.g.:
> 
>   # ls -al /sys/class/mtd/mtd0/of_node
>   lrwxrwxrwx 1 root root 0 Oct 26 19:17 /sys/class/mtd/mtd0/of_node -> ../../../../firmware/devicetree/base/spi@ff130000/flash@0
> 
> For NAND, this potentially has some other bigger initial side effects, since
> nand_dt_init() handles a bit more automagically for drivers that defined their
> ->flash_node. But these drivers should probably convert anyway. So, please test
> your favorite driver!

Looks all good to me,

Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>

> 
> v1 -> v2:
>  * add helper functions for getting/setting the MTD/SPI-NOR/NAND DT node
>  * fix some build errors
>  * drop spi_nor's flash_node field (just use the MTD of_node)
> 
> Regards,
> Brian
> 
> Brian Norris (11):
>   mtd: add get/set of_node/flash_node helpers
>   mtd: ofpart: grab device tree node directly from master device node
>   mtd: {nand,spi-nor}: assign MTD of_node
>   mtd: nand: convert to nand_set_flash_node()
>   mtd: spi-nor: convert to spi_nor_{get,set}_flash_node()
>   mtd: nand: drop unnecessary partition parser data
>   mtd: spi-nor: drop unnecessary partition parser data
>   mtd: spi-nor: drop flash_node field
>   mtd: drop unnecessary partition parser data
>   mtd: ofpart: drop 'of_node' partition parser data
>   mtd: physmap_of: assign parent for the concatenated MTD
> 
>  drivers/mtd/devices/m25p80.c                  | 10 +++-------
>  drivers/mtd/devices/mtd_dataflash.c           |  5 ++---
>  drivers/mtd/devices/spear_smi.c               |  6 ++----
>  drivers/mtd/devices/st_spi_fsm.c              |  5 ++---
>  drivers/mtd/maps/lantiq-flash.c               |  5 ++---
>  drivers/mtd/maps/physmap_of.c                 |  6 +++---
>  drivers/mtd/nand/atmel_nand.c                 |  7 +++----
>  drivers/mtd/nand/brcmnand/brcmnand.c          |  5 ++---
>  drivers/mtd/nand/davinci_nand.c               | 10 +++-------
>  drivers/mtd/nand/fsl_elbc_nand.c              |  5 ++---
>  drivers/mtd/nand/fsl_ifc_nand.c               |  5 ++---
>  drivers/mtd/nand/fsl_upm.c                    |  5 ++---
>  drivers/mtd/nand/fsmc_nand.c                  |  9 ++++-----
>  drivers/mtd/nand/gpio.c                       |  8 +++-----
>  drivers/mtd/nand/gpmi-nand/gpmi-nand.c        |  5 ++---
>  drivers/mtd/nand/hisi504_nand.c               |  5 ++---
>  drivers/mtd/nand/lpc32xx_mlc.c                |  7 +++----
>  drivers/mtd/nand/lpc32xx_slc.c                |  7 +++----
>  drivers/mtd/nand/mpc5121_nfc.c                |  5 ++---
>  drivers/mtd/nand/mxc_nand.c                   |  5 ++---
>  drivers/mtd/nand/nand_base.c                  |  3 +++
>  drivers/mtd/nand/ndfc.c                       |  5 ++---
>  drivers/mtd/nand/omap2.c                      |  6 ++----
>  drivers/mtd/nand/orion_nand.c                 |  6 ++----
>  drivers/mtd/nand/plat_nand.c                  |  5 ++---
>  drivers/mtd/nand/pxa3xx_nand.c                | 10 +++++-----
>  drivers/mtd/nand/sh_flctl.c                   |  6 ++----
>  drivers/mtd/nand/socrates_nand.c              |  5 ++---
>  drivers/mtd/nand/sunxi_nand.c                 |  6 ++----
>  drivers/mtd/nand/vf610_nfc.c                  |  8 ++------
>  drivers/mtd/ofpart.c                          | 12 ++++--------
>  drivers/mtd/onenand/omap2.c                   |  8 +++-----
>  drivers/mtd/spi-nor/fsl-quadspi.c             |  6 ++----
>  drivers/mtd/spi-nor/nxp-spifi.c               |  6 ++----
>  drivers/mtd/spi-nor/spi-nor.c                 |  2 +-
>  drivers/staging/mt29f_spinand/mt29f_spinand.c |  5 ++---
>  include/linux/mtd/mtd.h                       | 11 +++++++++++
>  include/linux/mtd/nand.h                      | 11 +++++++++++
>  include/linux/mtd/partitions.h                |  2 --
>  include/linux/mtd/spi-nor.h                   | 13 +++++++++++--
>  40 files changed, 120 insertions(+), 141 deletions(-)
> 



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1260255 — [PATCH v2 12/11] mtd: nand: convert to nand_get_flash_node()

FromBoris Brezillon <boris.brezillon@free-electrons.com>
Date2015-11-02 00:10 +0100
Subject[PATCH v2 12/11] mtd: nand: convert to nand_get_flash_node()
Message-ID<qq9V7-65A-13@gated-at.bofh.it>
In reply to#1259927
Used semantic patch with 'make coccicheck MODE=patch COCCI=script.cocci':

---8<----
virtual patch

@@
struct nand_chip c;
struct nand_chip *cp;
@@
(
-(cp)->flash_node
+nand_get_flash_node(cp)
|
-(c).flash_node
+nand_get_flash_node(&c)
)
---8<----

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
Hi Brian,

I think this patch could be part of your series too.

Best Regards,

Boris

 drivers/mtd/nand/brcmnand/brcmnand.c | 2 +-
 drivers/mtd/nand/nand_base.c         | 6 +++---
 drivers/mtd/nand/vf610_nfc.c         | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c
index a37659d..2a437c7 100644
--- a/drivers/mtd/nand/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/brcmnand/brcmnand.c
@@ -1816,7 +1816,7 @@ static int brcmnand_setup_dev(struct brcmnand_host *host)
 
 	memset(cfg, 0, sizeof(*cfg));
 
-	ret = of_property_read_u32(chip->flash_node,
+	ret = of_property_read_u32(nand_get_flash_node(chip),
 				   "brcm,nand-oob-sector-size",
 				   &oob_sector);
 	if (ret) {
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 939ab3d..4ac4efe 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3989,11 +3989,11 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
 	struct nand_flash_dev *type;
 	int ret;
 
-	if (chip->flash_node) {
+	if (nand_get_flash_node(chip)) {
 		/* MTD can automatically handle DT partitions, etc. */
-		mtd_set_of_node(mtd, chip->flash_node);
+		mtd_set_of_node(mtd, nand_get_flash_node(chip));
 
-		ret = nand_dt_init(mtd, chip, chip->flash_node);
+		ret = nand_dt_init(mtd, chip, nand_get_flash_node(chip));
 		if (ret)
 			return ret;
 	}
diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index b6df4c6..1c86c6b 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -707,7 +707,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
 	for_each_available_child_of_node(nfc->dev->of_node, child) {
 		if (of_device_is_compatible(child, "fsl,vf610-nfc-nandcs")) {
 
-			if (chip->flash_node) {
+			if (nand_get_flash_node(chip)) {
 				dev_err(nfc->dev,
 					"Only one NAND chip supported!\n");
 				err = -EINVAL;
@@ -718,7 +718,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
 		}
 	}
 
-	if (!chip->flash_node) {
+	if (!nand_get_flash_node(chip)) {
 		dev_err(nfc->dev, "NAND chip sub-node missing!\n");
 		err = -ENODEV;
 		goto err_clk;
@@ -814,7 +814,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
 	return mtd_device_register(mtd, NULL, 0);
 
 error:
-	of_node_put(chip->flash_node);
+	of_node_put(nand_get_flash_node(chip));
 err_clk:
 	clk_disable_unprepare(nfc->clk);
 	return err;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1267546 — Re: [PATCH v2 12/11] mtd: nand: convert to nand_get_flash_node()

FromBrian Norris <computersforpeace@gmail.com>
Date2015-11-12 01:00 +0100
SubjectRe: [PATCH v2 12/11] mtd: nand: convert to nand_get_flash_node()
Message-ID<qtNsZ-1cw-7@gated-at.bofh.it>
In reply to#1260255
On Mon, Nov 02, 2015 at 12:03:38AM +0100, Boris Brezillon wrote:
> Used semantic patch with 'make coccicheck MODE=patch COCCI=script.cocci':
> 
> ---8<----
> virtual patch
> 
> @@
> struct nand_chip c;
> struct nand_chip *cp;
> @@
> (
> -(cp)->flash_node
> +nand_get_flash_node(cp)
> |
> -(c).flash_node
> +nand_get_flash_node(&c)
> )
> ---8<----
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
> Hi Brian,
> 
> I think this patch could be part of your series too.
> 
> Best Regards,
> 
> Boris

Thanks! Pushed to l2-mtd.git/next
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1260274 — [PATCH v2 13/11] mtd: assign mtd->dev.of_node when creating partition devices

FromBoris Brezillon <boris.brezillon@free-electrons.com>
Date2015-11-02 01:40 +0100
Subject[PATCH v2 13/11] mtd: assign mtd->dev.of_node when creating partition devices
Message-ID<qqbke-6S5-13@gated-at.bofh.it>
In reply to#1259927
MTD partitions may have been created from a DT definition, and in this case
the ->of_node of the struct device embedded in mtd_info should point to
the DT node that was used to create the partition.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
Hi Brian,

Yet another patch that IMO should go into your "mtd: migrate 'of_node'
handling to core, not in mtd_part_parser_data" series.

Best Regards,

Boris

 drivers/mtd/mtdcore.c          | 17 +++++++++++++----
 drivers/mtd/mtdpart.c          |  3 +++
 drivers/mtd/ofpart.c           |  1 +
 include/linux/mtd/partitions.h |  1 +
 4 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index b1eea48..6101288 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -32,6 +32,7 @@
 #include <linux/err.h>
 #include <linux/ioctl.h>
 #include <linux/init.h>
+#include <linux/of.h>
 #include <linux/proc_fs.h>
 #include <linux/idr.h>
 #include <linux/backing-dev.h>
@@ -584,11 +585,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
 			      const struct mtd_partition *parts,
 			      int nr_parts)
 {
-	int ret;
+	int ret, i;
 	struct mtd_partition *real_parts = NULL;
 
 	ret = parse_mtd_partitions(mtd, types, &real_parts, parser_data);
-	if (ret <= 0 && nr_parts && parts) {
+	if (ret > 0) {
+		nr_parts = ret;
+	} else if (nr_parts && parts) {
 		real_parts = kmemdup(parts, sizeof(*parts) * nr_parts,
 				     GFP_KERNEL);
 		if (!real_parts)
@@ -604,7 +607,7 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
 		ret = 0;
 	}
 
-	ret = mtd_add_device_partitions(mtd, real_parts, ret);
+	ret = mtd_add_device_partitions(mtd, real_parts, nr_parts);
 	if (ret)
 		goto out;
 
@@ -623,7 +626,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
 	}
 
 out:
-	kfree(real_parts);
+	if (real_parts) {
+		for (i = 0; i < nr_parts; i++)
+			of_node_put(real_parts[i].of_node);
+
+		kfree(real_parts);
+	}
+
 	return ret;
 }
 EXPORT_SYMBOL_GPL(mtd_device_parse_register);
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index f8ba153..95f3a0d 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -29,6 +29,7 @@
 #include <linux/kmod.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
+#include <linux/of.h>
 #include <linux/err.h>
 #include <linux/kconfig.h>
 
@@ -319,6 +320,7 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
 
 static inline void free_partition(struct mtd_part *p)
 {
+	of_node_put(mtd_get_of_node(&p->mtd));
 	kfree(p->mtd.name);
 	kfree(p);
 }
@@ -391,6 +393,7 @@ static struct mtd_part *allocate_partition(struct mtd_info *master,
 	slave->mtd.dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) ?
 				&master->dev :
 				master->dev.parent;
+	mtd_set_of_node(&slave->mtd, of_node_get(part->of_node));
 
 	slave->mtd._read = part_read;
 	slave->mtd._write = part_write;
diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c
index f78d2ae..5c64e04 100644
--- a/drivers/mtd/ofpart.c
+++ b/drivers/mtd/ofpart.c
@@ -111,6 +111,7 @@ static int parse_ofpart_partitions(struct mtd_info *master,
 		if (of_get_property(pp, "lock", &len))
 			(*pparts)[i].mask_flags |= MTD_POWERUP_LOCK;
 
+		(*pparts)[i].of_node = of_node_get(pp);
 		i++;
 	}
 
diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
index 773975a..282644c 100644
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -42,6 +42,7 @@ struct mtd_partition {
 	uint64_t offset;		/* offset within the master MTD space */
 	uint32_t mask_flags;		/* master MTD flags to mask out for this partition */
 	struct nand_ecclayout *ecclayout;	/* out of band layout for this partition (NAND only) */
+	struct device_node *of_node;	/* OF node attached to the partition */
 };
 
 #define MTDPART_OFS_RETAIN	(-3)
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1267548 — Re: [PATCH v2 13/11] mtd: assign mtd->dev.of_node when creating partition devices

FromBrian Norris <computersforpeace@gmail.com>
Date2015-11-12 01:20 +0100
SubjectRe: [PATCH v2 13/11] mtd: assign mtd->dev.of_node when creating partition devices
Message-ID<qtNMl-1zI-3@gated-at.bofh.it>
In reply to#1260274
On Mon, Nov 02, 2015 at 01:38:41AM +0100, Boris Brezillon wrote:
> MTD partitions may have been created from a DT definition, and in this case
> the ->of_node of the struct device embedded in mtd_info should point to
> the DT node that was used to create the partition.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>

I like the idea of this patch, but I'm not sure about all of its
details.

> ---
> Hi Brian,
> 
> Yet another patch that IMO should go into your "mtd: migrate 'of_node'
> handling to core, not in mtd_part_parser_data" series.
> 
> Best Regards,
> 
> Boris
> 
>  drivers/mtd/mtdcore.c          | 17 +++++++++++++----
>  drivers/mtd/mtdpart.c          |  3 +++
>  drivers/mtd/ofpart.c           |  1 +
>  include/linux/mtd/partitions.h |  1 +
>  4 files changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index b1eea48..6101288 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -32,6 +32,7 @@
>  #include <linux/err.h>
>  #include <linux/ioctl.h>
>  #include <linux/init.h>
> +#include <linux/of.h>
>  #include <linux/proc_fs.h>
>  #include <linux/idr.h>
>  #include <linux/backing-dev.h>
> @@ -584,11 +585,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
>  			      const struct mtd_partition *parts,
>  			      int nr_parts)
>  {
> -	int ret;
> +	int ret, i;
>  	struct mtd_partition *real_parts = NULL;
>  
>  	ret = parse_mtd_partitions(mtd, types, &real_parts, parser_data);
> -	if (ret <= 0 && nr_parts && parts) {
> +	if (ret > 0) {
> +		nr_parts = ret;
> +	} else if (nr_parts && parts) {
>  		real_parts = kmemdup(parts, sizeof(*parts) * nr_parts,
>  				     GFP_KERNEL);
>  		if (!real_parts)
> @@ -604,7 +607,7 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
>  		ret = 0;
>  	}
>  
> -	ret = mtd_add_device_partitions(mtd, real_parts, ret);
> +	ret = mtd_add_device_partitions(mtd, real_parts, nr_parts);
>  	if (ret)
>  		goto out;
>  
> @@ -623,7 +626,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
>  	}
>  
>  out:
> -	kfree(real_parts);
> +	if (real_parts) {
> +		for (i = 0; i < nr_parts; i++)
> +			of_node_put(real_parts[i].of_node);
> +
> +		kfree(real_parts);
> +	}
> +
>  	return ret;
>  }
>  EXPORT_SYMBOL_GPL(mtd_device_parse_register);
> diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
> index f8ba153..95f3a0d 100644
> --- a/drivers/mtd/mtdpart.c
> +++ b/drivers/mtd/mtdpart.c
> @@ -29,6 +29,7 @@
>  #include <linux/kmod.h>
>  #include <linux/mtd/mtd.h>
>  #include <linux/mtd/partitions.h>
> +#include <linux/of.h>
>  #include <linux/err.h>
>  #include <linux/kconfig.h>
>  
> @@ -319,6 +320,7 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
>  
>  static inline void free_partition(struct mtd_part *p)
>  {
> +	of_node_put(mtd_get_of_node(&p->mtd));
>  	kfree(p->mtd.name);
>  	kfree(p);
>  }
> @@ -391,6 +393,7 @@ static struct mtd_part *allocate_partition(struct mtd_info *master,
>  	slave->mtd.dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) ?
>  				&master->dev :
>  				master->dev.parent;
> +	mtd_set_of_node(&slave->mtd, of_node_get(part->of_node));
>  
>  	slave->mtd._read = part_read;
>  	slave->mtd._write = part_write;
> diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c
> index f78d2ae..5c64e04 100644
> --- a/drivers/mtd/ofpart.c
> +++ b/drivers/mtd/ofpart.c
> @@ -111,6 +111,7 @@ static int parse_ofpart_partitions(struct mtd_info *master,
>  		if (of_get_property(pp, "lock", &len))
>  			(*pparts)[i].mask_flags |= MTD_POWERUP_LOCK;
>  
> +		(*pparts)[i].of_node = of_node_get(pp);

I don't think we should mix up too much of the error handling between
ofpart.c and mtdcore.c (right now, you do of_node_get() here but the
of_node_put() is forced into mtdcore.c). I think the problem here is the
same as the problem with Linus' patch here:

http://lists.infradead.org/pipermail/linux-mtd/2015-November/063219.html

It's just too easy to leak resources when MTD parsers don't have their
own cleanup functions (like C++ destructors, or the driver model's
remove() function, or so many other resource models). If we had a
cleanup function, then we could just put the release handling there.

But actually, I don't think we need to 'get' the property here; we only
need to 'get' it when we're putting it somewhere that will actually use
it long term. i.e., when it actually gets assigned to the
mtd.dev.of_node field and is headed for sysfs.

IOW, I think we can grab the reference in add_mtd_device() and drop it
in del_mtd_device(). This would handle both the partition and
non-partition case the same.

I have a patch to do that (for the non-partition case) queued up. I'll
push it out soon, then I expect you can make this patch a lot simpler.

Brian

>  		i++;
>  	}
>  
> diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
> index 773975a..282644c 100644
> --- a/include/linux/mtd/partitions.h
> +++ b/include/linux/mtd/partitions.h
> @@ -42,6 +42,7 @@ struct mtd_partition {
>  	uint64_t offset;		/* offset within the master MTD space */
>  	uint32_t mask_flags;		/* master MTD flags to mask out for this partition */
>  	struct nand_ecclayout *ecclayout;	/* out of band layout for this partition (NAND only) */
> +	struct device_node *of_node;	/* OF node attached to the partition */
>  };
>  
>  #define MTDPART_OFS_RETAIN	(-3)
> -- 
> 2.1.4
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1267916 — Re: [PATCH v2 13/11] mtd: assign mtd->dev.of_node when creating partition devices

FromBoris Brezillon <boris.brezillon@free-electrons.com>
Date2015-11-12 14:30 +0100
SubjectRe: [PATCH v2 13/11] mtd: assign mtd->dev.of_node when creating partition devices
Message-ID<qu06S-ZA-29@gated-at.bofh.it>
In reply to#1267548
Hi Brian,

On Wed, 11 Nov 2015 16:15:50 -0800
Brian Norris <computersforpeace@gmail.com> wrote:

> On Mon, Nov 02, 2015 at 01:38:41AM +0100, Boris Brezillon wrote:
> > MTD partitions may have been created from a DT definition, and in this case
> > the ->of_node of the struct device embedded in mtd_info should point to
> > the DT node that was used to create the partition.
> > 
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> I like the idea of this patch, but I'm not sure about all of its
> details.
> 
> > ---
> > Hi Brian,
> > 
> > Yet another patch that IMO should go into your "mtd: migrate 'of_node'
> > handling to core, not in mtd_part_parser_data" series.
> > 
> > Best Regards,
> > 
> > Boris
> > 
> >  drivers/mtd/mtdcore.c          | 17 +++++++++++++----
> >  drivers/mtd/mtdpart.c          |  3 +++
> >  drivers/mtd/ofpart.c           |  1 +
> >  include/linux/mtd/partitions.h |  1 +
> >  4 files changed, 18 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> > index b1eea48..6101288 100644
> > --- a/drivers/mtd/mtdcore.c
> > +++ b/drivers/mtd/mtdcore.c
> > @@ -32,6 +32,7 @@
> >  #include <linux/err.h>
> >  #include <linux/ioctl.h>
> >  #include <linux/init.h>
> > +#include <linux/of.h>
> >  #include <linux/proc_fs.h>
> >  #include <linux/idr.h>
> >  #include <linux/backing-dev.h>
> > @@ -584,11 +585,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
> >  			      const struct mtd_partition *parts,
> >  			      int nr_parts)
> >  {
> > -	int ret;
> > +	int ret, i;
> >  	struct mtd_partition *real_parts = NULL;
> >  
> >  	ret = parse_mtd_partitions(mtd, types, &real_parts, parser_data);
> > -	if (ret <= 0 && nr_parts && parts) {
> > +	if (ret > 0) {
> > +		nr_parts = ret;
> > +	} else if (nr_parts && parts) {
> >  		real_parts = kmemdup(parts, sizeof(*parts) * nr_parts,
> >  				     GFP_KERNEL);
> >  		if (!real_parts)
> > @@ -604,7 +607,7 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
> >  		ret = 0;
> >  	}
> >  
> > -	ret = mtd_add_device_partitions(mtd, real_parts, ret);
> > +	ret = mtd_add_device_partitions(mtd, real_parts, nr_parts);
> >  	if (ret)
> >  		goto out;
> >  
> > @@ -623,7 +626,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
> >  	}
> >  
> >  out:
> > -	kfree(real_parts);
> > +	if (real_parts) {
> > +		for (i = 0; i < nr_parts; i++)
> > +			of_node_put(real_parts[i].of_node);
> > +
> > +		kfree(real_parts);
> > +	}
> > +
> >  	return ret;
> >  }
> >  EXPORT_SYMBOL_GPL(mtd_device_parse_register);
> > diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
> > index f8ba153..95f3a0d 100644
> > --- a/drivers/mtd/mtdpart.c
> > +++ b/drivers/mtd/mtdpart.c
> > @@ -29,6 +29,7 @@
> >  #include <linux/kmod.h>
> >  #include <linux/mtd/mtd.h>
> >  #include <linux/mtd/partitions.h>
> > +#include <linux/of.h>
> >  #include <linux/err.h>
> >  #include <linux/kconfig.h>
> >  
> > @@ -319,6 +320,7 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
> >  
> >  static inline void free_partition(struct mtd_part *p)
> >  {
> > +	of_node_put(mtd_get_of_node(&p->mtd));
> >  	kfree(p->mtd.name);
> >  	kfree(p);
> >  }
> > @@ -391,6 +393,7 @@ static struct mtd_part *allocate_partition(struct mtd_info *master,
> >  	slave->mtd.dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) ?
> >  				&master->dev :
> >  				master->dev.parent;
> > +	mtd_set_of_node(&slave->mtd, of_node_get(part->of_node));
> >  
> >  	slave->mtd._read = part_read;
> >  	slave->mtd._write = part_write;
> > diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c
> > index f78d2ae..5c64e04 100644
> > --- a/drivers/mtd/ofpart.c
> > +++ b/drivers/mtd/ofpart.c
> > @@ -111,6 +111,7 @@ static int parse_ofpart_partitions(struct mtd_info *master,
> >  		if (of_get_property(pp, "lock", &len))
> >  			(*pparts)[i].mask_flags |= MTD_POWERUP_LOCK;
> >  
> > +		(*pparts)[i].of_node = of_node_get(pp);
> 
> I don't think we should mix up too much of the error handling between
> ofpart.c and mtdcore.c (right now, you do of_node_get() here but the
> of_node_put() is forced into mtdcore.c). I think the problem here is the
> same as the problem with Linus' patch here:
> 
> http://lists.infradead.org/pipermail/linux-mtd/2015-November/063219.html
> 
> It's just too easy to leak resources when MTD parsers don't have their
> own cleanup functions (like C++ destructors, or the driver model's
> remove() function, or so many other resource models). If we had a
> cleanup function, then we could just put the release handling there.
> 
> But actually, I don't think we need to 'get' the property here; we only
> need to 'get' it when we're putting it somewhere that will actually use
> it long term. i.e., when it actually gets assigned to the
> mtd.dev.of_node field and is headed for sysfs.
> 
> IOW, I think we can grab the reference in add_mtd_device() and drop it
> in del_mtd_device(). This would handle both the partition and
> non-partition case the same.

Hm, actually I think we need it. When you iterate over child nodes with
for_each_child_of_node(), the node is released (of_node_put() is
called) after each iteration. While this is not a problem for mtd
device registration (because the controller usually retain the
reference when add_mtd_device() is called), this is not true for the
partitions. And if the partitions are ever defined using an overlay,
this can be a problem.

To sum-up, I think we should retain the node reference until
add_mtd_device() has retained it, so maybe we should have a ->cleanup()
function in mtd part parsers.

Best Regards,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web