--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
-@@ -1258,6 +1258,74 @@ static struct mtd_notifier ubi_mtd_notif
+@@ -1258,6 +1258,80 @@ static struct mtd_notifier ubi_mtd_notif
.remove = ubi_notify_remove,
};
+{
+ int err;
+ struct mtd_info *mtd;
++ struct device_node *np;
+ loff_t offset = 0;
+ size_t len;
+ char magic[4];
+ if (IS_ERR(mtd))
+ return;
+
++ /* skip "linux,ubi" mtd as it has already been attached */
++ np = mtd_get_of_node(mtd);
++ if (of_device_is_compatible(np, "linux,ubi"))
++ goto cleanup;
++
+ /* get the first not bad block */
+ if (mtd_can_have_bb(mtd))
+ while (mtd_block_isbad(mtd, offset)) {
static int __init ubi_init_attach(void)
{
int err, i, k;
-@@ -1308,6 +1376,12 @@ static int __init ubi_init_attach(void)
+@@ -1308,6 +1382,12 @@ static int __init ubi_init_attach(void)
}
}