From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pa0-x22e.google.com ([2607:f8b0:400e:c03::22e]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZqpQX-0003x9-Fe for linux-mtd@lists.infradead.org; Mon, 26 Oct 2015 21:35:40 +0000 Received: by pabla5 with SMTP id la5so6246246pab.0 for ; Mon, 26 Oct 2015 14:35:16 -0700 (PDT) Date: Mon, 26 Oct 2015 14:35:14 -0700 From: Brian Norris To: Richard Weinberger Cc: linux-mtd@lists.infradead.org Subject: Re: [PATCH 4/4] mtd: warn when registering the same master many times Message-ID: <20151026213514.GL13239@google.com> References: <1433200640-17858-1-git-send-email-computersforpeace@gmail.com> <1433200640-17858-4-git-send-email-computersforpeace@gmail.com> <556D633E.70300@nod.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <556D633E.70300@nod.at> List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On Tue, Jun 02, 2015 at 10:03:10AM +0200, Richard Weinberger wrote: > Am 02.06.2015 um 01:17 schrieb Brian Norris: > > 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 > > --- > > 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); > > One minor nit, IMHO WARN_ONCE() would make more sense. > > Beside of that: > Reviewed-by: Richard Weinberger Changed to WARN_ONCE() and applied