diff options
author | Clay McClure <clay@daemons.net> | 2017-09-21 19:01:34 -0700 |
---|---|---|
committer | Sasha Levin <alexander.levin@microsoft.com> | 2018-03-20 23:49:52 -0400 |
commit | 27ec5b63df0f28ad9d5d11d2accbcdbb5b171233 (patch) | |
tree | b13695a18814eee540543755afd4e5c0b02cd36d /drivers | |
parent | 214f6efcaa61fc2ec8682aee94aa87938e157fe6 (diff) |
ubi: Fix race condition between ubi volume creation and udev
[ Upstream commit a51a0c8d213594bc094cb8e54aad0cb6d7f7b9a6 ]
Similar to commit 714fb87e8bc0 ("ubi: Fix race condition between ubi
device creation and udev"), we should make the volume active before
registering it.
Signed-off-by: Clay McClure <clay@daemons.net>
Cc: <stable@vger.kernel.org>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mtd/ubi/vmt.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c index 812ecf2d253a..9965acb8aca0 100644 --- a/drivers/mtd/ubi/vmt.c +++ b/drivers/mtd/ubi/vmt.c @@ -310,6 +310,12 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) vol->last_eb_bytes = vol->usable_leb_size; } + /* Make volume "available" before it becomes accessible via sysfs */ + spin_lock(&ubi->volumes_lock); + ubi->volumes[vol_id] = vol; + ubi->vol_count += 1; + spin_unlock(&ubi->volumes_lock); + /* Register character device for the volume */ cdev_init(&vol->cdev, &ubi_vol_cdev_operations); vol->cdev.owner = THIS_MODULE; @@ -352,11 +358,6 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) if (err) goto out_sysfs; - spin_lock(&ubi->volumes_lock); - ubi->volumes[vol_id] = vol; - ubi->vol_count += 1; - spin_unlock(&ubi->volumes_lock); - ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED); self_check_volumes(ubi); return err; @@ -376,6 +377,10 @@ out_sysfs: out_cdev: cdev_del(&vol->cdev); out_mapping: + spin_lock(&ubi->volumes_lock); + ubi->volumes[vol_id] = NULL; + ubi->vol_count -= 1; + spin_unlock(&ubi->volumes_lock); if (do_free) kfree(vol->eba_tbl); out_acc: |