mtdoops: allow MTD selection by name

Submitted by Adrian Hunter on Feb. 16, 2009, 4:21 p.m.

Details

Message ID 4999928F.1010304@nokia.com
State Accepted
Commit e2a0f25b4f520adbd82c0caafcde0470ed11053d
Headers show

Commit Message

Adrian Hunter Feb. 16, 2009, 4:21 p.m.
MTD's have both an index number and a name.  Formerly,
the MTD selected for mtdoops was done only by index
number.  With this patch, a name can be used instead.

For example, the kernel command line:

	console=ttyMTD5

selects MTD 5 for mtdoops.  But now this is also possible:

	console=ttyMTD,log

which selects the MTD named "log" for mtdoops.

This has the advantage that partitions can be added or
removed that would affect the MTD index number but not the
name, without having to then change the kernel command line.

Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
---
 drivers/mtd/mtdoops.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

Comments

Artem Bityutskiy Feb. 17, 2009, 12:08 p.m.
On Mon, 2009-02-16 at 18:21 +0200, Adrian Hunter wrote:
> MTD's have both an index number and a name.  Formerly,
> the MTD selected for mtdoops was done only by index
> number.  With this patch, a name can be used instead.
> 
> For example, the kernel command line:
> 
> 	console=ttyMTD5
> 
> selects MTD 5 for mtdoops.  But now this is also possible:
> 
> 	console=ttyMTD,log
> 
> which selects the MTD named "log" for mtdoops.
> 
> This has the advantage that partitions can be added or
> removed that would affect the MTD index number but not the
> name, without having to then change the kernel command line.
> 
> Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>

Acked-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Richard Purdie Feb. 17, 2009, 1:28 p.m.
On Mon, 2009-02-16 at 18:21 +0200, Adrian Hunter wrote:
> MTD's have both an index number and a name.  Formerly,
> the MTD selected for mtdoops was done only by index
> number.  With this patch, a name can be used instead.
> 
> For example, the kernel command line:
> 
> 	console=ttyMTD5
> 
> selects MTD 5 for mtdoops.  But now this is also possible:
> 
> 	console=ttyMTD,log
> 
> which selects the MTD named "log" for mtdoops.

> This has the advantage that partitions can be added or
> removed that would affect the MTD index number but not the
> name, without having to then change the kernel command line.
> 
> Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Acked-by: Richard Purdie <rpurdie@linux.intel.com>
Artem Bityutskiy March 5, 2009, 10:27 a.m.
On Tue, 2009-02-17 at 14:08 +0200, Artem Bityutskiy wrote:
> On Mon, 2009-02-16 at 18:21 +0200, Adrian Hunter wrote:
> > MTD's have both an index number and a name.  Formerly,
> > the MTD selected for mtdoops was done only by index
> > number.  With this patch, a name can be used instead.
> > 
> > For example, the kernel command line:
> > 
> > 	console=ttyMTD5
> > 
> > selects MTD 5 for mtdoops.  But now this is also possible:
> > 
> > 	console=ttyMTD,log
> > 
> > which selects the MTD named "log" for mtdoops.
> > 
> > This has the advantage that partitions can be added or
> > removed that would affect the MTD index number but not the
> > name, without having to then change the kernel command line.
> > 
> > Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
> 
> Acked-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

David, would you please push this patch ?

Patch hide | download patch | download mbox

diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index 1a6b3be..fdf504f 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -44,6 +44,7 @@  static struct mtdoops_context {
 	int oops_pages;
 	int nextpage;
 	int nextcount;
+	char *name;
 
 	void *oops_buf;
 
@@ -273,6 +274,9 @@  static void mtdoops_notify_add(struct mtd_info *mtd)
 {
 	struct mtdoops_context *cxt = &oops_cxt;
 
+	if (cxt->name && !strcmp(mtd->name, cxt->name))
+		cxt->mtd_index = mtd->index;
+
 	if ((mtd->index != cxt->mtd_index) || cxt->mtd_index < 0)
 		return;
 
@@ -383,8 +387,12 @@  static int __init mtdoops_console_setup(struct console *co, char *options)
 {
 	struct mtdoops_context *cxt = co->data;
 
-	if (cxt->mtd_index != -1)
+	if (cxt->mtd_index != -1 || cxt->name)
 		return -EBUSY;
+	if (options) {
+		cxt->name = kstrdup(options, GFP_KERNEL);
+		return 0;
+	}
 	if (co->index == -1)
 		return -EINVAL;
 
@@ -432,6 +440,7 @@  static void __exit mtdoops_console_exit(void)
 
 	unregister_mtd_user(&mtdoops_notifier);
 	unregister_console(&mtdoops_console);
+	kfree(cxt->name);
 	vfree(cxt->oops_buf);
 }