summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Brezillon <boris.brezillon@collabora.com>2020-04-29 09:53:47 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-10-01 11:11:56 +0200
commit17fd0a642bbc15dec94c50e35c80c9e0fab590ea (patch)
tree6cb30a9cd0dee6928101bbb8a85b4a7db74a890f
parentda1935ae27d6af755d561204cf4b2ba2cf39fbd0 (diff)
downloadlinux-stable-17fd0a642bbc15dec94c50e35c80c9e0fab590ea.tar.gz
linux-stable-17fd0a642bbc15dec94c50e35c80c9e0fab590ea.tar.bz2
linux-stable-17fd0a642bbc15dec94c50e35c80c9e0fab590ea.zip
mtd: parser: cmdline: Support MTD names containing one or more colons
[ Upstream commit eb13fa0227417e84aecc3bd9c029d376e33474d3 ] Looks like some drivers define MTD names with a colon in it, thus making mtdpart= parsing impossible. Let's fix the parser to gracefully handle that case: the last ':' in a partition definition sequence is considered instead of the first one. Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com> Signed-off-by: Ron Minnich <rminnich@google.com> Tested-by: Ron Minnich <rminnich@google.com> Signed-off-by: Richard Weinberger <richard@nod.at> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/mtd/cmdlinepart.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index 08f62987cc37..ffbc9b304beb 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -228,12 +228,29 @@ static int mtdpart_setup_real(char *s)
struct cmdline_mtd_partition *this_mtd;
struct mtd_partition *parts;
int mtd_id_len, num_parts;
- char *p, *mtd_id;
+ char *p, *mtd_id, *semicol;
+
+ /*
+ * Replace the first ';' by a NULL char so strrchr can work
+ * properly.
+ */
+ semicol = strchr(s, ';');
+ if (semicol)
+ *semicol = '\0';
mtd_id = s;
- /* fetch <mtd-id> */
- p = strchr(s, ':');
+ /*
+ * fetch <mtd-id>. We use strrchr to ignore all ':' that could
+ * be present in the MTD name, only the last one is interpreted
+ * as an <mtd-id>/<part-definition> separator.
+ */
+ p = strrchr(s, ':');
+
+ /* Restore the ';' now. */
+ if (semicol)
+ *semicol = ';';
+
if (!p) {
pr_err("no mtd-id\n");
return -EINVAL;