All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Norris <computersforpeace@gmail.com>
To: <linux-mtd@lists.infradead.org>
Cc: Richard Weinberger <richard@nod.at>,
	Brian Norris <computersforpeace@gmail.com>
Subject: [PATCH 4/4] mtd: warn when registering the same master many times
Date: Mon,  1 Jun 2015 16:17:20 -0700	[thread overview]
Message-ID: <1433200640-17858-4-git-send-email-computersforpeace@gmail.com> (raw)
In-Reply-To: <1433200640-17858-1-git-send-email-computersforpeace@gmail.com>

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>
---
 drivers/mtd/mtdcore.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 03eec42dc715..f0e157e0be89 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(mtd->backing_dev_info, "MTD already registered\n"))
+		return -EEXIST;
+
 	mtd->backing_dev_info = &mtd_bdi;
 
 	BUG_ON(mtd->writesize == 0);
@@ -597,6 +605,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(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);
-- 
1.9.1

  parent reply	other threads:[~2015-06-01 23:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-01 23:17 [PATCH 1/4] mtd: diskonchip: remove two-phase partitioning / registration Brian Norris
2015-06-01 23:17 ` [PATCH 2/4] mtd: propagate error codes from add_mtd_device() Brian Norris
2015-06-02  8:02   ` Richard Weinberger
2015-06-03  0:00     ` Brian Norris
2015-06-01 23:17 ` [PATCH 3/4] mtd: fixup corner case error handling in mtd_device_parse_register() Brian Norris
2015-06-02  8:03   ` Richard Weinberger
2015-10-26 21:34     ` Brian Norris
2015-06-01 23:17 ` Brian Norris [this message]
2015-06-02  8:03   ` [PATCH 4/4] mtd: warn when registering the same master many times Richard Weinberger
2015-10-26 21:35     ` Brian Norris
2015-06-17  1:51 ` [PATCH 1/4] mtd: diskonchip: remove two-phase partitioning / registration Brian Norris

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=1433200640-17858-4-git-send-email-computersforpeace@gmail.com \
    --to=computersforpeace@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.