From: Boris Brezillon <boris.brezillon@bootlin.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/4] mtd: sf: Make sure we don't register the same device twice
Date: Fri, 16 Nov 2018 15:40:26 +0100 [thread overview]
Message-ID: <20181116144026.3015-4-boris.brezillon@bootlin.com> (raw)
In-Reply-To: <20181116144026.3015-1-boris.brezillon@bootlin.com>
spi_flash_mtd_register() can be called several times and each time it
will register the same mtd_info instance like if it was a new one.
The MTD ID allocation gets crazy when that happens, so let's track the
status of the sf_mtd_info object to avoid that.
Fixes: 9fe6d8716e09 ("mtd, spi: Add MTD layer driver")
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
---
drivers/mtd/spi/sf_mtd.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/spi/sf_mtd.c b/drivers/mtd/spi/sf_mtd.c
index 58d7e4439903..aabbc3589435 100644
--- a/drivers/mtd/spi/sf_mtd.c
+++ b/drivers/mtd/spi/sf_mtd.c
@@ -10,6 +10,7 @@
#include <spi_flash.h>
static struct mtd_info sf_mtd_info;
+static bool sf_mtd_registered;
static char sf_mtd_name[8];
static int spi_flash_mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
@@ -73,6 +74,12 @@ static int spi_flash_mtd_number(void)
int spi_flash_mtd_register(struct spi_flash *flash)
{
+ int ret;
+
+ if (sf_mtd_registered)
+ del_mtd_device(&sf_mtd_info);
+
+ sf_mtd_registered = false;
memset(&sf_mtd_info, 0, sizeof(sf_mtd_info));
sprintf(sf_mtd_name, "nor%d", spi_flash_mtd_number());
@@ -94,7 +101,11 @@ int spi_flash_mtd_register(struct spi_flash *flash)
sf_mtd_info.numeraseregions = 0;
sf_mtd_info.erasesize = flash->sector_size;
- return add_mtd_device(&sf_mtd_info);
+ ret = add_mtd_device(&sf_mtd_info);
+ if (!ret)
+ sf_mtd_registered = true;
+
+ return ret;
}
void spi_flash_mtd_unregister(void)
--
2.17.1
prev parent reply other threads:[~2018-11-16 14:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-16 14:40 [U-Boot] [PATCH 1/4] mtd: Add a function to report when the MTD dev list has been updated Boris Brezillon
2018-11-16 14:40 ` [U-Boot] [PATCH 2/4] mtd: Parse mtdparts/mtdids again when the MTD " Boris Brezillon
2018-11-16 14:40 ` [U-Boot] [PATCH 3/4] mtd: Delete partitions attached to the device when a device is deleted Boris Brezillon
2018-11-17 9:19 ` Boris Brezillon
2018-11-19 6:16 ` Heiko Schocher
2018-11-19 9:25 ` Miquel Raynal
2018-11-19 11:57 ` Boris Brezillon
2018-11-19 12:10 ` Heiko Schocher
2018-11-16 14:40 ` Boris Brezillon [this message]
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=20181116144026.3015-4-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