diff options
author | Boris Brezillon <boris.brezillon@bootlin.com> | 2018-12-02 10:54:29 +0100 |
---|---|---|
committer | Jagan Teki <jagan@amarulasolutions.com> | 2018-12-06 00:45:36 +0530 |
commit | 2428d9160b80375870c1fff6cbb0214639628282 (patch) | |
tree | 0356e1ab16b62be0e2835316868c5cb4120cc3d5 /drivers/mtd | |
parent | 772aa9799353d1d6bd6d9e2682945d4d7122539a (diff) |
mtd: Make sure we don't parse MTD partitions belonging to another dev
The mtdparts variable might contain partition definitions for several
MTD devices. Each partition layout is separated by a ';', so let's
make sure we don't pick a wrong name when mtdparts is malformed.
Fixes: 5db66b3aee6f ("cmd: mtd: add 'mtd' command")
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
Tested-by: Heiko Schocher <hs@denx.de>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/mtd_uboot.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/drivers/mtd/mtd_uboot.c b/drivers/mtd/mtd_uboot.c index 0eda362783..6a36948b91 100644 --- a/drivers/mtd/mtd_uboot.c +++ b/drivers/mtd/mtd_uboot.c @@ -155,6 +155,7 @@ int mtd_probe_devices(void) static char *old_mtdids; const char *mtdparts = get_mtdparts(); const char *mtdids = get_mtdids(); + const char *mtdparts_next = mtdparts; bool remaining_partitions = true; struct mtd_info *mtd; @@ -219,13 +220,22 @@ int mtd_probe_devices(void) mtdparts += 9; /* For each MTD device in mtdparts */ - while (mtdparts[0] != '\0') { + for (; mtdparts[0] != '\0'; mtdparts = mtdparts_next) { char mtd_name[MTD_NAME_MAX_LEN], *colon; struct mtd_partition *parts; unsigned int mtd_name_len; int nparts, ret; + mtdparts_next = strchr(mtdparts, ';'); + if (!mtdparts_next) + mtdparts_next = mtdparts + strlen(mtdparts); + else + mtdparts_next++; + colon = strchr(mtdparts, ':'); + if (colon > mtdparts_next) + colon = NULL; + if (!colon) { printf("Wrong mtdparts: %s\n", mtdparts); return -EINVAL; @@ -263,10 +273,7 @@ int mtd_probe_devices(void) if (ret || IS_ERR_OR_NULL(mtd)) { printf("Could not find a valid device for %s\n", mtd_name); - mtdparts = strchr(mtdparts, ';'); - if (mtdparts) - mtdparts++; - + mtdparts = mtdparts_next; continue; } } |