[PATCH] mtd: ubi: Fix race condition between ubi device creation and udev

Iosif Harutyunov iharutyunov at SonicWALL.com
Wed Jul 20 19:07:55 PDT 2016


While implementing udev rules for UBI device I ran into the problem when udev would
ignore UBI rules I created to process attachment of volume. Interestingly, when I trigger
udev ubi subsystem "change" event manually after the attachment, rules would work just fine.

I traced problem down to UBI sysfs processing, which turned out to be racing condition.
See patch below to address the problem.

Thanks.
Iosif,_

Signed-off-by: Iosif Harutyunov <iharutyunov at sonicwall.com>
---
Once ubi is attached, make sure ubi_devices[] is initialized early before being
used in the dev_attribute_show().

This is to prevent race condition between udev ubi rules processing and ubi device
creation, which manifests itself ignoring udev ATTR rules.

---
 drivers/mtd/ubi/build.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index ef36182..e6117d7 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -986,6 +986,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
 		goto out_free;
 	}
 
+	ubi_devices[ubi_num] = ubi;
+
 	if (ubi->autoresize_vol_id != -1) {
 		err = autoresize(ubi, ubi->autoresize_vol_id);
 		if (err)
@@ -1036,7 +1038,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 +1048,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);
-- 
1.7.7.6




More information about the linux-mtd mailing list