mtd: fixup corner case error handling in mtd_device_parse_register()

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Fri Nov 6 10:59:27 PST 2015


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=3e00ed0e984bbec47f5e531bad3cf36885aa5d83
Commit:     3e00ed0e984bbec47f5e531bad3cf36885aa5d83
Parent:     af30c0a00aa0d086a820c2ec75544c07611834d7
Author:     Brian Norris <computersforpeace at gmail.com>
AuthorDate: Mon Jun 1 16:17:19 2015 -0700
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Mon Oct 26 14:32:33 2015 -0700

    mtd: fixup corner case error handling in mtd_device_parse_register()
    
    Since commit 3efe41be224c ("mtd: implement common reboot notifier
    boilerplate"), we might try to register a reboot notifier for an MTD
    that failed to register. Let's avoid this by making the error path
    clearer.
    
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
    Reviewed-by: Richard Weinberger <richard at nod.at>
---
 drivers/mtd/mtdcore.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index bbcba0d..a2e76ac 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -588,9 +588,15 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
 		else
 			ret = nr_parts;
 	}
+	/* Didn't come up with either parsed OR fallback partitions */
+	if (ret < 0) {
+		pr_info("mtd: failed to find partitions\n");
+		goto out;
+	}
 
-	if (ret >= 0)
-		ret = mtd_add_device_partitions(mtd, real_parts, ret);
+	ret = mtd_add_device_partitions(mtd, real_parts, ret);
+	if (ret)
+		goto out;
 
 	/*
 	 * FIXME: some drivers unfortunately call this function more than once.
@@ -605,6 +611,7 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
 		register_reboot_notifier(&mtd->reboot_notifier);
 	}
 
+out:
 	kfree(real_parts);
 	return ret;
 }



More information about the linux-mtd-cvs mailing list