diff options
author | Brian Norris <computersforpeace@gmail.com> | 2015-06-01 19:17:20 -0400 |
---|---|---|
committer | Brian Norris <computersforpeace@gmail.com> | 2015-10-26 17:34:07 -0400 |
commit | be0dbff8b46d69bd738f63b4fe0cf64417f776b0 (patch) | |
tree | 044a2240eba4a10e2a8d920ecd2119e19d84b3de | |
parent | 3e00ed0e984bbec47f5e531bad3cf36885aa5d83 (diff) |
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@gmail.com>
Reviewed-by: Richard Weinberger <richard@nod.at>
-rw-r--r-- | drivers/mtd/mtdcore.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index a2e76ac9f1dc..41dc501cb49a 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c | |||
@@ -387,6 +387,14 @@ int add_mtd_device(struct mtd_info *mtd) | |||
387 | struct mtd_notifier *not; | 387 | struct mtd_notifier *not; |
388 | int i, error; | 388 | int i, error; |
389 | 389 | ||
390 | /* | ||
391 | * May occur, for instance, on buggy drivers which call | ||
392 | * mtd_device_parse_register() multiple times on the same master MTD, | ||
393 | * especially with CONFIG_MTD_PARTITIONED_MASTER=y. | ||
394 | */ | ||
395 | if (WARN_ONCE(mtd->backing_dev_info, "MTD already registered\n")) | ||
396 | return -EEXIST; | ||
397 | |||
390 | mtd->backing_dev_info = &mtd_bdi; | 398 | mtd->backing_dev_info = &mtd_bdi; |
391 | 399 | ||
392 | BUG_ON(mtd->writesize == 0); | 400 | BUG_ON(mtd->writesize == 0); |
@@ -606,6 +614,7 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, | |||
606 | * does cause problems with parse_mtd_partitions() above (e.g., | 614 | * does cause problems with parse_mtd_partitions() above (e.g., |
607 | * cmdlineparts will register partitions more than once). | 615 | * cmdlineparts will register partitions more than once). |
608 | */ | 616 | */ |
617 | WARN_ONCE(mtd->reboot_notifier.notifier_call, "MTD already registered\n"); | ||
609 | if (mtd->_reboot && !mtd->reboot_notifier.notifier_call) { | 618 | if (mtd->_reboot && !mtd->reboot_notifier.notifier_call) { |
610 | mtd->reboot_notifier.notifier_call = mtd_reboot_notifier; | 619 | mtd->reboot_notifier.notifier_call = mtd_reboot_notifier; |
611 | register_reboot_notifier(&mtd->reboot_notifier); | 620 | register_reboot_notifier(&mtd->reboot_notifier); |