[PATCH] mtd: parsers: Support '[]' for id in mtdparts
From: Ronald G. Minnich
Date: Mon Apr 06 2020 - 12:10:04 EST
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@xxxxxxxxxx>
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