--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
-@@ -1171,6 +1171,68 @@ static struct mtd_info * __init open_mtd
+@@ -1171,6 +1171,73 @@ static struct mtd_info * __init open_mtd
return mtd;
}
+ }
+ }
+
-+ /* check for a valid ubi magic if read from flash was successful */
++ /* check if the read from flash was successful */
+ err = mtd_read(mtd, offset, 4, &len, (void *) magic);
-+ if ((!err || mtd_is_bitflip(err)) &&
-+ len == 4 && strncmp(magic, "UBI#", 4)) {
++ if ((err && !mtd_is_bitflip(err)) || len != 4) {
++ pr_err("UBI error: unable to read from mtd%d\n", mtd->index);
++ goto cleanup;
++ }
++
++ /* check for a valid ubi magic */
++ if (strncmp(magic, "UBI#", 4)) {
+ pr_err("UBI error: no valid UBI magic found inside mtd%d\n", mtd->index);
+ goto cleanup;
+ }
static int __init ubi_init(void)
{
int err, i, k;
-@@ -1254,6 +1316,12 @@ static int __init ubi_init(void)
+@@ -1254,6 +1321,12 @@ static int __init ubi_init(void)
}
}
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
-@@ -1226,6 +1226,68 @@ static struct mtd_info * __init open_mtd
+@@ -1226,6 +1226,73 @@ static struct mtd_info * __init open_mtd
return mtd;
}
+ }
+ }
+
-+ /* check for a valid ubi magic if read from flash was successful */
++ /* check if the read from flash was successful */
+ err = mtd_read(mtd, offset, 4, &len, (void *) magic);
-+ if ((!err || mtd_is_bitflip(err)) &&
-+ len == 4 && strncmp(magic, "UBI#", 4)) {
++ if ((err && !mtd_is_bitflip(err)) || len != 4) {
++ pr_err("UBI error: unable to read from mtd%d\n", mtd->index);
++ goto cleanup;
++ }
++
++ /* check for a valid ubi magic */
++ if (strncmp(magic, "UBI#", 4)) {
+ pr_err("UBI error: no valid UBI magic found inside mtd%d\n", mtd->index);
+ goto cleanup;
+ }
static int __init ubi_init(void)
{
int err, i, k;
-@@ -1309,6 +1371,12 @@ static int __init ubi_init(void)
+@@ -1309,6 +1376,12 @@ static int __init ubi_init(void)
}
}