]> git.karo-electronics.de Git - linux-beck.git/commitdiff
ubi: Fix race condition between ubi device creation and udev
authorIosif Harutyunov <iharutyunov@SonicWALL.com>
Fri, 22 Jul 2016 23:22:42 +0000 (23:22 +0000)
committerRichard Weinberger <richard@nod.at>
Fri, 29 Jul 2016 21:30:28 +0000 (23:30 +0200)
Install the UBI device object before we arm sysfs.
Otherwise udev tries to read sysfs attributes before UBI is ready and
udev rules will not match.

Cc: <stable@vger.kernel.org>
Signed-off-by: Iosif Harutyunov <iharutyunov@sonicwall.com>
[rw: massaged commit message]
Signed-off-by: Richard Weinberger <richard@nod.at>
drivers/mtd/ubi/build.c

index ef3618299494f4973fd528ae72325490eb622b2c..5d524a04d0a3d65bbabc6df76c66561dafd52611 100644 (file)
@@ -992,6 +992,9 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
                        goto out_detach;
        }
 
+       /* Make device "available" before it becomes accessible via sysfs */
+       ubi_devices[ubi_num] = ubi;
+
        err = uif_init(ubi, &ref);
        if (err)
                goto out_detach;
@@ -1036,7 +1039,6 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
        wake_up_process(ubi->bgt_thread);
        spin_unlock(&ubi->wl_lock);
 
-       ubi_devices[ubi_num] = ubi;
        ubi_notify_all(ubi, UBI_VOLUME_ADDED, NULL);
        return ubi_num;
 
@@ -1047,6 +1049,7 @@ out_uif:
        ubi_assert(ref);
        uif_close(ubi);
 out_detach:
+       ubi_devices[ubi_num] = NULL;
        ubi_wl_close(ubi);
        ubi_free_internal_volumes(ubi);
        vfree(ubi->vtbl);