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)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 20 Nov 2016 01:01:29 +0000 (01:01 +0000)
commit 714fb87e8bc05ff78255afc0dca981e8c5242785 upstream.

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.

Signed-off-by: Iosif Harutyunov <iharutyunov@sonicwall.com>
[rw: massaged commit message]
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/mtd/ubi/build.c

index 1f9c363..5c87c94 100644 (file)
@@ -974,6 +974,9 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
                        goto out_detach;
        }
 
                        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;
        err = uif_init(ubi, &ref);
        if (err)
                goto out_detach;
@@ -1017,7 +1020,6 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
        wake_up_process(ubi->bgt_thread);
        spin_unlock(&ubi->wl_lock);
 
        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;
 
        ubi_notify_all(ubi, UBI_VOLUME_ADDED, NULL);
        return ubi_num;
 
@@ -1028,6 +1030,7 @@ out_uif:
        ubi_assert(ref);
        uif_close(ubi);
 out_detach:
        ubi_assert(ref);
        uif_close(ubi);
 out_detach:
+       ubi_devices[ubi_num] = NULL;
        ubi_wl_close(ubi);
        free_internal_volumes(ubi);
        vfree(ubi->vtbl);
        ubi_wl_close(ubi);
        free_internal_volumes(ubi);
        vfree(ubi->vtbl);