mtd: fixup corner case error handling in mtd_device_parse_register()
authorBrian Norris <computersforpeace@gmail.com>
Mon, 1 Jun 2015 23:17:19 +0000 (16:17 -0700)
committerBrian Norris <computersforpeace@gmail.com>
Mon, 26 Oct 2015 21:32:33 +0000 (14:32 -0700)
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@gmail.com>
Reviewed-by: Richard Weinberger <richard@nod.at>
drivers/mtd/mtdcore.c

index bbcba0dbd5c3062e7da07979fb9c42af98558b54..a2e76ac9f1dcb37c4fa458c53eefb2a767257adb 100644 (file)
@@ -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;
 }