* [PATCH] ubi: Fix race condition between ubi volume creation and udev
@ 2017-09-22 2:01 Clay McClure
2017-09-22 8:27 ` Richard Weinberger
0 siblings, 1 reply; 2+ messages in thread
From: Clay McClure @ 2017-09-22 2:01 UTC (permalink / raw)
To: linux-mtd; +Cc: Clay McClure
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>
---
drivers/mtd/ubi/vmt.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 85237cf661f9..3fd8d7ff7a02 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -270,6 +270,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;
@@ -298,11 +304,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;
@@ -315,6 +316,10 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
*/
cdev_device_del(&vol->cdev, &vol->dev);
out_mapping:
+ spin_lock(&ubi->volumes_lock);
+ ubi->volumes[vol_id] = NULL;
+ ubi->vol_count -= 1;
+ spin_unlock(&ubi->volumes_lock);
ubi_eba_destroy_table(eba_tbl);
out_acc:
spin_lock(&ubi->volumes_lock);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ubi: Fix race condition between ubi volume creation and udev
2017-09-22 2:01 [PATCH] ubi: Fix race condition between ubi volume creation and udev Clay McClure
@ 2017-09-22 8:27 ` Richard Weinberger
0 siblings, 0 replies; 2+ messages in thread
From: Richard Weinberger @ 2017-09-22 8:27 UTC (permalink / raw)
To: Clay McClure; +Cc: linux-mtd
On Fri, Sep 22, 2017 at 4:01 AM, Clay McClure <clay@daemons.net> wrote:
> 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>
> ---
> drivers/mtd/ubi/vmt.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
> index 85237cf661f9..3fd8d7ff7a02 100644
> --- a/drivers/mtd/ubi/vmt.c
> +++ b/drivers/mtd/ubi/vmt.c
> @@ -270,6 +270,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;
> @@ -298,11 +304,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;
> @@ -315,6 +316,10 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
> */
> cdev_device_del(&vol->cdev, &vol->dev);
> out_mapping:
> + spin_lock(&ubi->volumes_lock);
> + ubi->volumes[vol_id] = NULL;
> + ubi->vol_count -= 1;
> + spin_unlock(&ubi->volumes_lock);
> ubi_eba_destroy_table(eba_tbl);
> out_acc:
> spin_lock(&ubi->volumes_lock);
> --
Uhh, yes. Thanks for catching this!
--
Thanks,
//richard
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-09-22 8:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-22 2:01 [PATCH] ubi: Fix race condition between ubi volume creation and udev Clay McClure
2017-09-22 8:27 ` Richard Weinberger
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.