All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: parsers: Support '[]' for id in mtdparts
@ 2020-04-06 16:09 ` Ronald G. Minnich
  0 siblings, 0 replies; 8+ messages in thread
From: Ronald G. Minnich @ 2020-04-06 16:09 UTC (permalink / raw)
  To: miquel.raynal, rminnich, richard, vigneshr, linus.walleij,
	linux-mtd, linux-kernel

The MTD subsystem can support command-line defined partitions
for one or more MTD devices.

The format is:
 * mtdparts=<mtddef>[;<mtddef]
 * <mtddef>  := <mtd-id>:<partdef>[,<partdef>]

The ':' separates the id from the partdef.

On PCI MTD devices, the name can be the PCI slot name,
e.g. 0000:00:1f.5. There are two ':' in the name alone.

Change the definition of <mtd-id> so it can be bracketed
with '[]' and hence contain any number of ':'.
An opening '[' must be matched with a closing ']'.
The ':' continues to separate the mtd-id from the <partdef>.

Signed-off-by: Ronald G. Minnich <rminnich@google.com>
Change-Id: I17a757e65f532b11606c7bb104f08837bcd444b9
---
 drivers/mtd/parsers/cmdlinepart.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/parsers/cmdlinepart.c b/drivers/mtd/parsers/cmdlinepart.c
index c86f2db8c882..ef9dc0bd7724 100644
--- a/drivers/mtd/parsers/cmdlinepart.c
+++ b/drivers/mtd/parsers/cmdlinepart.c
@@ -10,7 +10,8 @@
  * mtdparts=<mtddef>[;<mtddef]
  * <mtddef>  := <mtd-id>:<partdef>[,<partdef>]
  * <partdef> := <size>[@<offset>][<name>][ro][lk]
- * <mtd-id>  := unique name used in mapping driver/device (mtd->name)
+ * <mtd-id>  := unique name used in mapping driver/device (mtd->name) |
+ *              '[' unique name as above, not including a "]" ']'
  * <size>    := standard linux memsize OR "-" to denote all remaining space
  *              size is automatically truncated at end of device
  *              if specified or truncated size is 0 the part is skipped
@@ -221,14 +222,38 @@ static int mtdpart_setup_real(char *s)
 		char *p, *mtd_id;
 
 		mtd_id = s;
+		mtd_id_len = 0;
+		p = s;
 
-		/* fetch <mtd-id> */
+		/*
+		 * fetch <mtd-id>
+		 * If the first char is '[',
+		 * the form is [mtd-id]:
+		 * otherwise it is mtd-id:
+		 */
+		if (*s == '[') {
+			mtd_id++;
+			p = strchr(s, ']');
+			if (!p) {
+				pr_err("mtd (%s) has '[' but no ']'", s);
+				return -EINVAL;
+			}
+			mtd_id_len = p - mtd_id;
+		}
+
+		/* There is always a : following mtd-id. */
 		p = strchr(s, ':');
 		if (!p) {
 			pr_err("no mtd-id\n");
 			return -EINVAL;
 		}
-		mtd_id_len = p - mtd_id;
+
+		/*
+		 * If the mtd-id was bracketed, mtd_id_len will be valid.
+		 * If it is still 0, we must set it here.
+		 */
+		if (mtd_id_len == 0)
+			mtd_id_len = p - mtd_id;
 
 		dbg(("parsing <%s>\n", p+1));
 
-- 
2.26.0.292.g33ef6b2f38-goog


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

end of thread, other threads:[~2020-04-16 17:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-06 16:09 [PATCH] mtd: parsers: Support '[]' for id in mtdparts Ronald G. Minnich
2020-04-06 16:09 ` Ronald G. Minnich
2020-04-16  9:51 ` Linus Walleij
2020-04-16  9:51   ` Linus Walleij
2020-04-16 14:55   ` ron minnich
2020-04-16 14:55     ` ron minnich
2020-04-16 17:03     ` Linus Walleij
2020-04-16 17:03       ` Linus Walleij

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.