mtd: avoid registering reboot notifier twice

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Mon Feb 16 18:59:06 PST 2015


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=e1dd8641c8c36ff4aacf24c7e2575770e30afbe5
Commit:     e1dd8641c8c36ff4aacf24c7e2575770e30afbe5
Parent:     d164ea32674ec82e80f480769ffcd2144f901380
Author:     Niklas Cassel <nks at flawful.org>
AuthorDate: Sun Feb 1 02:08:50 2015 +0100
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Sat Feb 7 22:55:47 2015 -0800

    mtd: avoid registering reboot notifier twice
    
    Calling mtd_device_parse_register with the same mtd_info
    (e.g. registering several partitions on a single device)
    would add the same reboot notifier twice, causing an
    infinte loop in notifier_chain_register during boot up.
    
    Signed-off-by: Niklas Cassel <nks at flawful.org>
    [Brian: add FIXME comments]
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
    
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 drivers/mtd/mtdcore.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index cbc0fc4..52eea93 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -577,7 +577,15 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
 			err = -ENODEV;
 	}
 
-	if (mtd->_reboot) {
+	/*
+	 * FIXME: some drivers unfortunately call this function more than once.
+	 * So we have to check if we've already assigned the reboot notifier.
+	 *
+	 * Generally, we can make multiple calls work for most cases, but it
+	 * does cause problems with parse_mtd_partitions() above (e.g.,
+	 * cmdlineparts will register partitions more than once).
+	 */
+	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