Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[firefly-linux-kernel-4.4.55.git] / drivers / mtd / mtdcore.c
index a2e76ac9f1dcb37c4fa458c53eefb2a767257adb..95c13b2ffa799e59f453e8a95813171cd56a13fc 100644 (file)
@@ -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_ONCE(mtd->backing_dev_info, "MTD already registered\n"))
+               return -EEXIST;
+
        mtd->backing_dev_info = &mtd_bdi;
 
        BUG_ON(mtd->writesize == 0);
@@ -590,8 +598,10 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
        }
        /* Didn't come up with either parsed OR fallback partitions */
        if (ret < 0) {
-               pr_info("mtd: failed to find partitions\n");
-               goto out;
+               pr_info("mtd: failed to find partitions; one or more parsers reports errors (%d)\n",
+                       ret);
+               /* Don't abort on errors; we can still use unpartitioned MTD */
+               ret = 0;
        }
 
        ret = mtd_add_device_partitions(mtd, real_parts, ret);
@@ -606,6 +616,8 @@ 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_ONCE(mtd->_reboot && 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);
@@ -1204,8 +1216,7 @@ EXPORT_SYMBOL_GPL(mtd_writev);
  */
 void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size)
 {
-       gfp_t flags = __GFP_NOWARN | __GFP_WAIT |
-                      __GFP_NORETRY | __GFP_NO_KSWAPD;
+       gfp_t flags = __GFP_NOWARN | __GFP_DIRECT_RECLAIM | __GFP_NORETRY;
        size_t min_alloc = max_t(size_t, mtd->writesize, PAGE_SIZE);
        void *kbuf;