public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@bootlin.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 5/9] mtd: Use get_mtdids() instead of env_get("mtdids") in mtd_search_alternate_name()
Date: Mon, 19 Nov 2018 12:51:17 +0100	[thread overview]
Message-ID: <20181119115121.7699-5-boris.brezillon@bootlin.com> (raw)
In-Reply-To: <20181119115121.7699-1-boris.brezillon@bootlin.com>

The environment is not guaranteed to contain a valid mtdids variable
when called from mtd_search_alternate_name(). Call get_mtdids() instead
of env_get("mtdids").

Fixes: ff4afa8a981e ("mtd: uboot: search for an equivalent MTD name with the mtdids")
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
Changes in v2:
- Add Miquel's R-b
- Move board_mtdparts_default() prototype def to fix a build failure
---
 drivers/mtd/mtd_uboot.c | 49 ++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/mtd/mtd_uboot.c b/drivers/mtd/mtd_uboot.c
index 6a3e64395de2..c4434d70520d 100644
--- a/drivers/mtd/mtd_uboot.c
+++ b/drivers/mtd/mtd_uboot.c
@@ -13,6 +13,29 @@
 
 #define MTD_NAME_MAX_LEN 20
 
+void board_mtdparts_default(const char **mtdids, const char **mtdparts);
+
+static const char *get_mtdids(void)
+{
+	__maybe_unused const char *mtdparts = NULL;
+	const char *mtdids = env_get("mtdids");
+
+	if (mtdids)
+		return mtdids;
+
+#if defined(CONFIG_SYS_MTDPARTS_RUNTIME)
+	board_mtdparts_default(&mtdids, &mtdparts);
+#elif defined(MTDIDS_DEFAULT)
+	mtdids = MTDIDS_DEFAULT;
+#elif defined(CONFIG_MTDIDS_DEFAULT)
+	mtdids = CONFIG_MTDIDS_DEFAULT;
+#endif
+
+	if (mtdids)
+		env_set("mtdids", mtdids);
+
+	return mtdids;
+}
 
 /**
  * mtd_search_alternate_name - Search an alternate name for @mtdname thanks to
@@ -34,7 +57,7 @@ int mtd_search_alternate_name(const char *mtdname, char *altname,
 	const char *mtdids, *equal, *comma, *dev_id, *mtd_id;
 	int dev_id_len, mtd_id_len;
 
-	mtdids = env_get("mtdids");
+	mtdids = get_mtdids();
 	if (!mtdids)
 		return -EINVAL;
 
@@ -92,30 +115,6 @@ static void mtd_probe_uclass_mtd_devs(void) { }
 #endif
 
 #if defined(CONFIG_MTD_PARTITIONS)
-extern void board_mtdparts_default(const char **mtdids,
-				   const char **mtdparts);
-
-static const char *get_mtdids(void)
-{
-	__maybe_unused const char *mtdparts = NULL;
-	const char *mtdids = env_get("mtdids");
-
-	if (mtdids)
-		return mtdids;
-
-#if defined(CONFIG_SYS_MTDPARTS_RUNTIME)
-	board_mtdparts_default(&mtdids, &mtdparts);
-#elif defined(MTDIDS_DEFAULT)
-	mtdids = MTDIDS_DEFAULT;
-#elif defined(CONFIG_MTDIDS_DEFAULT)
-	mtdids = CONFIG_MTDIDS_DEFAULT;
-#endif
-
-	if (mtdids)
-		env_set("mtdids", mtdids);
-
-	return mtdids;
-}
 
 #define MTDPARTS_MAXLEN         512
 
-- 
2.17.1

  parent reply	other threads:[~2018-11-19 11:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-19 11:51 [U-Boot] [PATCH 1/9] mtd: Add a function to report when the MTD dev list has been updated Boris Brezillon
2018-11-19 11:51 ` [U-Boot] [PATCH 2/9] mtd: Parse mtdparts/mtdids again when the MTD " Boris Brezillon
2018-11-19 11:51 ` [U-Boot] [PATCH 3/9] mtd: Delete partitions attached to the device when a device is deleted Boris Brezillon
2018-11-19 11:51 ` [U-Boot] [PATCH 4/9] mtd: sf: Make sure we don't register the same device twice Boris Brezillon
2018-11-19 11:51 ` Boris Brezillon [this message]
2018-11-19 11:51 ` [U-Boot] [PATCH 6/9] mtd: Be more strict on the "mtdparts=" prefix check Boris Brezillon
2018-11-19 11:51 ` [U-Boot] [PATCH 7/9] mtd: Make sure the name passed in mtdparts fits in mtd_name[] Boris Brezillon
2018-11-19 11:51 ` [U-Boot] [PATCH 8/9] mtd: Make sure we don't parse MTD partitions belonging to another dev Boris Brezillon
2018-11-19 11:51 ` [U-Boot] [PATCH 9/9] mtd: Don't stop MTD partition creation when it fails on one device Boris Brezillon
2018-11-19 12:40 ` [U-Boot] [PATCH 1/9] mtd: Add a function to report when the MTD dev list has been updated Boris Brezillon
2018-11-19 13:30   ` Heiko Schocher
2018-11-19 13:44     ` Boris Brezillon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181119115121.7699-5-boris.brezillon@bootlin.com \
    --to=boris.brezillon@bootlin.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox