Patchwork plat_ram: call mtd_device_register only if partition data exists

login
register
mail settings
Submitter Ilya Yanok
Date Dec. 12, 2011, 11:37 p.m.
Message ID <1323733076-6301-1-git-send-email-yanok@emcraft.com>
Download mbox | patch
Permalink /patch/130957/
State Accepted
Commit c32987918efaa6949c5b2f3e43b654a742b18f7d
Headers show

Comments

Ilya Yanok - Dec. 12, 2011, 11:37 p.m.
mtd_device_parse_register() registers the device as a whole if no
partition data is passed so there is no reason to call
mtd_device_register() after that.

Signed-off-by: Ilya Yanok <yanok@emcraft.com>
---
 drivers/mtd/maps/plat-ram.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
Artem Bityutskiy - Dec. 17, 2011, 3:31 p.m.
On Tue, 2011-12-13 at 00:37 +0100, Ilya Yanok wrote:
> mtd_device_parse_register() registers the device as a whole if no
> partition data is passed so there is no reason to call
> mtd_device_register() after that.
> 
> Signed-off-by: Ilya Yanok <yanok@emcraft.com>

This seems to be a bug-fix, right? What happens without this patch?
We end up with 2 MTD equivalent MTD devices?
Ilya Yanok - Dec. 17, 2011, 10:26 p.m.
Hi Artem,

On 17.12.2011 19:31, Artem Bityutskiy wrote:
>> mtd_device_parse_register() registers the device as a whole if no
>> partition data is passed so there is no reason to call
>> mtd_device_register() after that.
>>
>> Signed-off-by: Ilya Yanok <yanok@emcraft.com>
> 
> This seems to be a bug-fix, right? What happens without this patch?

Right.

> We end up with 2 MTD equivalent MTD devices?

Yes (only second one shown in /proc/mtd) and a warning for kobject:

kobject (cf2c10e0): tried to init an initialized object, something is
seriously wrong.

Regards, Ilya.
Artem Bityutskiy - Dec. 18, 2011, 11:49 a.m.
On Sun, 2011-12-18 at 02:26 +0400, Ilya Yanok wrote:
> Hi Artem,
> 
> On 17.12.2011 19:31, Artem Bityutskiy wrote:
> >> mtd_device_parse_register() registers the device as a whole if no
> >> partition data is passed so there is no reason to call
> >> mtd_device_register() after that.
> >>
> >> Signed-off-by: Ilya Yanok <yanok@emcraft.com>
> > 
> > This seems to be a bug-fix, right? What happens without this patch?
> 
> Right.
> 
> > We end up with 2 MTD equivalent MTD devices?
> 
> Yes (only second one shown in /proc/mtd) and a warning for kobject:
> 
> kobject (cf2c10e0): tried to init an initialized object, something is
> seriously wrong.

OK, then I'll ping David Woodhouse to merge this before 3.2 release.
Taken to l2-mtd-2.6.git so far, thanks!

Patch

diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index 94f5534..45876d0 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -227,10 +227,14 @@  static int platram_probe(struct platform_device *pdev)
 	if (!err)
 		dev_info(&pdev->dev, "registered mtd device\n");
 
-	/* add the whole device. */
-	err = mtd_device_register(info->mtd, NULL, 0);
-	if (err)
-		dev_err(&pdev->dev, "failed to register the entire device\n");
+	if (pdata->nr_partitions) {
+		/* add the whole device. */
+		err = mtd_device_register(info->mtd, NULL, 0);
+		if (err) {
+			dev_err(&pdev->dev,
+				"failed to register the entire device\n");
+		}
+	}
 
 	return err;