Skip to contentSkip to conversation

fsl_elbc_nand: fix mtd name

PATCH Superseded Anton Vorontsov 2 participants 5 messages Mar 18, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsl_elbc_nand: fix mtd name

Currently fsl_elbc_nand doesn't initialize mtd->name, and this causes nand_get_flash_type() to assign name that is equal to chip type, like this:

   root@b1:~# cat /proc/mtd
   dev:    size   erasesize  name
   mtd0: 00800000 00010000 "fe000000.flash"
   mtd1: 02000000 00004000 "NAND 32MiB 3,3V 8-bit"

mtd0 is physmap_of flash (normal name), and mtd1 is fsl_elbc_nand.

Despite inconsistency, with mtd name like this specifying paritions from the kernel command line becomes a torture (though, I didn't tried and not sure if mtdparts= can handle spaces at all). Plus, this causes real bugs when multiple fsl_elbc_nand chips registered.

With this patch applied fsl_elbc_nand chip will have proper name:

   root@b1:~# cat /proc/mtd
   dev:    size   erasesize  name
   mtd0: 00800000 00010000 "fe000000.flash"
   mtd1: 02000000 00004000 "e0600000.flash"

p.s. We can't use priv->dev->bus_id as in physmap_of, because fsl_elbc_nand pretends to be a localbus controller, so its bus_id is "address.localbus", which is incorrect and thus will also not work for multiple chips.

---
 drivers/mtd/nand/fsl_elbc_nand.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/mtd/nand/fsl_elbc_nand.c +4 -0
index b025dfe..54a9d83 100644
@@ -974,6 +974,8 @@ static int fsl_elbc_chip_remove(struct fsl_elbc_mtd *priv)
 
 	nand_release(&priv->mtd);
 
+	kfree(priv->mtd.name);
+
 	if (priv->vbase)
 		iounmap(priv->vbase);
 
@@ -1050,6 +1052,8 @@ static int fsl_elbc_chip_probe(struct fsl_elbc_ctrl *ctrl,
 	if (ret)
 		goto err;
 
+	priv->mtd.name = kasprintf(GFP_KERNEL, "%x.flash", res.start);
+
 #ifdef CONFIG_MTD_PARTITIONS
 	/* First look for RedBoot table or partitions on the command
 	 * line, these take precedence over device tree information */
Signature · 1 line
1.5.2.2
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Anton Vorontsov

With this patch applied fsl_elbc_nand chip will have proper name:

   root@b1:~# cat /proc/mtd
   dev:    size   erasesize  name
   mtd0: 00800000 00010000 "fe000000.flash"
   mtd1: 02000000 00004000 "e0600000.flash"

p.s. We can't use priv->dev->bus_id as in physmap_of, because fsl_elbc_nand pretends to be a localbus controller, so its bus_id is "address.localbus", which is incorrect and thus will also not work for multiple chips.

-Scott

#2 lore raw

PATCH v2 1/1 fsl_elbc_nand: fix mtd name

In reply to Anton Vorontsov

Currently fsl_elbc_nand doesn't initialize mtd->name, and this causes nand_get_flash_type() to assign name that is equal to chip type, like this:

   root@b1:~# cat /proc/mtd
   dev:    size   erasesize  name
   mtd0: 00800000 00010000 "fe000000.flash"
   mtd1: 02000000 00004000 "NAND 32MiB 3,3V 8-bit"

mtd0 is physmap_of flash (normal name), and mtd1 is fsl_elbc_nand.

Despite inconsistency, with mtd name like this specifying paritions from the kernel command line becomes a torture (though, I didn't tried and not sure if mtdparts= can handle spaces at all). Plus, this causes real bugs when multiple fsl_elbc_nand chips registered.

With this patch applied fsl_elbc_nand chip will have proper name:

   root@b1:~# cat /proc/mtd
   dev:    size   erasesize  name
   mtd0: 00800000 00010000 "fe000000.flash"
   mtd1: 02000000 00004000 "e0600000.flash"

p.s. We can't use priv->dev->bus_id as in physmap_of, because fsl_elbc_nand pretends to be a localbus controller, so its bus_id is "address.localbus", which is incorrect and thus will also not work for multiple chips.

---

Oops, forgot the NULL checking.

 drivers/mtd/nand/fsl_elbc_nand.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
drivers/mtd/nand/fsl_elbc_nand.c +9 -0
index b025dfe..9fff5d1 100644
@@ -974,6 +974,9 @@ static int fsl_elbc_chip_remove(struct fsl_elbc_mtd *priv)
 
 	nand_release(&priv->mtd);
 
+	if (priv->mtd.name)
+		kfree(priv->mtd.name);
+
 	if (priv->vbase)
 		iounmap(priv->vbase);
 
@@ -1050,6 +1053,12 @@ static int fsl_elbc_chip_probe(struct fsl_elbc_ctrl *ctrl,
 	if (ret)
 		goto err;
 
+	priv->mtd.name = kasprintf(GFP_KERNEL, "%x.flash", res.start);
+	if (!priv->mtd.name) {
+		ret = -ENOMEM;
+		goto err;
+	}
+
 #ifdef CONFIG_MTD_PARTITIONS
 	/* First look for RedBoot table or partitions on the command
 	 * line, these take precedence over device tree information */
Signature · 1 line
1.5.2.2
#3 lore raw
Quoted 1 line · Anton Vorontsov

Oops, forgot the NULL checking.

[snip]

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_remove(struct fsl_elbc_mtd *priv) · line 979

Quoted 3 lines
drivers/mtd/nand/fsl_elbc_nand.c +3 -0
+	if (priv->mtd.name)
+		kfree(priv->mtd.name);
+

Not needed; kfree(NULL) is a no-op.

-Scott

#4 lore raw

PATCH v3 1/1 fsl_elbc_nand: fix mtd name

Currently fsl_elbc_nand doesn't initialize mtd->name, and this causes nand_get_flash_type() to assign name that is equal to chip type, like this:

   root@b1:~# cat /proc/mtd
   dev:    size   erasesize  name
   mtd0: 00800000 00010000 "fe000000.flash"
   mtd1: 02000000 00004000 "NAND 32MiB 3,3V 8-bit"

mtd0 is physmap_of flash (normal name), and mtd1 is fsl_elbc_nand.

Despite inconsistency, with mtd name like this specifying paritions from the kernel command line becomes a torture (though, I didn't tried and not sure if mtdparts= can handle spaces at all). Plus, this causes real bugs when multiple fsl_elbc_nand chips registered.

With this patch applied fsl_elbc_nand chip will have proper name:

   root@b1:~# cat /proc/mtd
   dev:    size   erasesize  name
   mtd0: 00800000 00010000 "fe000000.flash"
   mtd1: 02000000 00004000 "e0600000.flash"

p.s. We can't use priv->dev->bus_id as in physmap_of, because fsl_elbc_nand pretends to be a localbus controller, so its bus_id is "address.localbus", which is incorrect and thus will also not work for multiple chips.

---

Quoted 8 lines · Scott Wood
Quoted 1 line · Anton Vorontsov

Oops, forgot the NULL checking.

[snip]

Review

Quoted 3 lines
(quoted diff) +3 -0
+	if (priv->mtd.name)
+		kfree(priv->mtd.name);
+

Not needed; kfree(NULL) is a no-op.

D'oh, right. Also, we should fill the name prior to nand_scan_ident, otherwise if error happened between nand_scan_ident and kasprintf then we'll kfree chip's type name.

 drivers/mtd/nand/fsl_elbc_nand.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/mtd/nand/fsl_elbc_nand.c +8 -0
index b025dfe..9c86d9b 100644
@@ -974,6 +974,8 @@ static int fsl_elbc_chip_remove(struct fsl_elbc_mtd *priv)
 
 	nand_release(&priv->mtd);
 
+	kfree(priv->mtd.name);
+
 	if (priv->vbase)
 		iounmap(priv->vbase);
 
@@ -1034,6 +1036,12 @@ static int fsl_elbc_chip_probe(struct fsl_elbc_ctrl *ctrl,
 		goto err;
 	}
 
+	priv->mtd.name = kasprintf(GFP_KERNEL, "%x.flash", res.start);
+	if (!priv->mtd.name) {
+		ret = -ENOMEM;
+		goto err;
+	}
+
 	ret = fsl_elbc_chip_init(priv);
 	if (ret)
 		goto err;
Signature · 1 line
1.5.2.2