mtd: warn when registering the same master many times
Linux-MTD Mailing List
linux-mtd at lists.infradead.org
Fri Nov 6 10:59:28 PST 2015
Gitweb: http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=be0dbff8b46d69bd738f63b4fe0cf64417f776b0
Commit: be0dbff8b46d69bd738f63b4fe0cf64417f776b0
Parent: 3e00ed0e984bbec47f5e531bad3cf36885aa5d83
Author: Brian Norris <computersforpeace at gmail.com>
AuthorDate: Mon Jun 1 16:17:20 2015 -0700
Committer: Brian Norris <computersforpeace at gmail.com>
CommitDate: Mon Oct 26 14:34:07 2015 -0700
mtd: warn when registering the same master many times
When CONFIG_MTD_PARTITIONED_MASTER=y, it is fatal to call
mtd_device_parse_register() twice on the same MTD, as we try to register
the same device/kobject multipile times.
When CONFIG_MTD_PARTITIONED_MASTER=n, calling
mtd_device_parse_register() is more of just a nuisance, as we can mostly
navigate around any conflicting actions.
But anyway, doing so is a Bad Thing (TM), and we should complain loudly
for any drivers that try to do this.
Signed-off-by: Brian Norris <computersforpeace at gmail.com>
Reviewed-by: Richard Weinberger <richard at nod.at>
---
drivers/mtd/mtdcore.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index a2e76ac..41dc501 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -387,6 +387,14 @@ int add_mtd_device(struct mtd_info *mtd)
struct mtd_notifier *not;
int i, error;
+ /*
+ * May occur, for instance, on buggy drivers which call
+ * mtd_device_parse_register() multiple times on the same master MTD,
+ * especially with CONFIG_MTD_PARTITIONED_MASTER=y.
+ */
+ if (WARN_ONCE(mtd->backing_dev_info, "MTD already registered\n"))
+ return -EEXIST;
+
mtd->backing_dev_info = &mtd_bdi;
BUG_ON(mtd->writesize == 0);
@@ -606,6 +614,7 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
* does cause problems with parse_mtd_partitions() above (e.g.,
* cmdlineparts will register partitions more than once).
*/
+ WARN_ONCE(mtd->reboot_notifier.notifier_call, "MTD already registered\n");
if (mtd->_reboot && !mtd->reboot_notifier.notifier_call) {
mtd->reboot_notifier.notifier_call = mtd_reboot_notifier;
register_reboot_notifier(&mtd->reboot_notifier);
More information about the linux-mtd-cvs
mailing list