* [U-Boot] [PATCH] mtd: Use get_mtdids() instead of env_get("mtdids") in mtd_search_alternate_name()
@ 2018-11-16 22:15 Boris Brezillon
2018-11-17 10:59 ` Miquel Raynal
0 siblings, 1 reply; 3+ messages in thread
From: Boris Brezillon @ 2018-11-16 22:15 UTC (permalink / raw)
To: u-boot
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>
---
drivers/mtd/mtd_uboot.c | 45 ++++++++++++++++++++---------------------
1 file changed, 22 insertions(+), 23 deletions(-)
diff --git a/drivers/mtd/mtd_uboot.c b/drivers/mtd/mtd_uboot.c
index 6a3e64395de2..b38771d0497f 100644
--- a/drivers/mtd/mtd_uboot.c
+++ b/drivers/mtd/mtd_uboot.c
@@ -13,6 +13,27 @@
#define MTD_NAME_MAX_LEN 20
+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 +55,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;
@@ -95,28 +116,6 @@ static void mtd_probe_uclass_mtd_devs(void) { }
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
static const char *get_mtdparts(void)
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [U-Boot] [PATCH] mtd: Use get_mtdids() instead of env_get("mtdids") in mtd_search_alternate_name()
2018-11-16 22:15 [U-Boot] [PATCH] mtd: Use get_mtdids() instead of env_get("mtdids") in mtd_search_alternate_name() Boris Brezillon
@ 2018-11-17 10:59 ` Miquel Raynal
2018-11-18 19:29 ` Boris Brezillon
0 siblings, 1 reply; 3+ messages in thread
From: Miquel Raynal @ 2018-11-17 10:59 UTC (permalink / raw)
To: u-boot
Hi Boris,
Boris Brezillon <boris.brezillon@bootlin.com> wrote on Fri, 16 Nov 2018
23:15:42 +0100:
> 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>
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 3+ messages in thread* [U-Boot] [PATCH] mtd: Use get_mtdids() instead of env_get("mtdids") in mtd_search_alternate_name()
2018-11-17 10:59 ` Miquel Raynal
@ 2018-11-18 19:29 ` Boris Brezillon
0 siblings, 0 replies; 3+ messages in thread
From: Boris Brezillon @ 2018-11-18 19:29 UTC (permalink / raw)
To: u-boot
On Sat, 17 Nov 2018 11:59:52 +0100
Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> Hi Boris,
>
> Boris Brezillon <boris.brezillon@bootlin.com> wrote on Fri, 16 Nov 2018
> 23:15:42 +0100:
>
> > 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").
Forgot to move board_mtdparts_default(). Please don't apply this patch,
I'll send a v2.
> >
> > 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>
>
> Thanks,
> Miquèl
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-11-18 19:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-16 22:15 [U-Boot] [PATCH] mtd: Use get_mtdids() instead of env_get("mtdids") in mtd_search_alternate_name() Boris Brezillon
2018-11-17 10:59 ` Miquel Raynal
2018-11-18 19:29 ` Boris Brezillon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox