Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cdf25333 authored by Iosif Harutyunov's avatar Iosif Harutyunov Committed by Sasha Levin
Browse files

ubi: Fix race condition between ubi device creation and udev



[ Upstream commit 714fb87e8bc05ff78255afc0dca981e8c5242785 ]

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: default avatarIosif Harutyunov <iharutyunov@sonicwall.com>
[rw: massaged commit message]
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>

Signed-off-by: default avatarSasha Levin <alexander.levin@verizon.com>
parent 6d1b8d7a
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -999,6 +999,9 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
			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);
	err = uif_init(ubi, &ref);
	if (err)
	if (err)
		goto out_detach;
		goto out_detach;
@@ -1043,7 +1046,6 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
	wake_up_process(ubi->bgt_thread);
	wake_up_process(ubi->bgt_thread);
	spin_unlock(&ubi->wl_lock);
	spin_unlock(&ubi->wl_lock);


	ubi_devices[ubi_num] = ubi;
	ubi_notify_all(ubi, UBI_VOLUME_ADDED, NULL);
	ubi_notify_all(ubi, UBI_VOLUME_ADDED, NULL);
	return ubi_num;
	return ubi_num;


@@ -1054,6 +1056,7 @@ out_uif:
	ubi_assert(ref);
	ubi_assert(ref);
	uif_close(ubi);
	uif_close(ubi);
out_detach:
out_detach:
	ubi_devices[ubi_num] = NULL;
	ubi_wl_close(ubi);
	ubi_wl_close(ubi);
	ubi_free_internal_volumes(ubi);
	ubi_free_internal_volumes(ubi);
	vfree(ubi->vtbl);
	vfree(ubi->vtbl);