aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2009-05-23 06:44:09 -0400
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2009-05-26 05:47:47 -0400
commitddbd3b61708483f73dbcc62a94d16cc7db928cba (patch)
tree7600caa289d1517e8642d6be21d0a0cfe88c40d5
parent95c9c1da79e59fd10ec5da3aeba22981383f7040 (diff)
UBI: fix race condition
This patch fixes a minor problem where we may fail to wake upe the UBI background thread. This is not fatal at all, it may just result at sligtly worse performace for a short period of time, just because the thread will be woken up when real I/O on the UBI starts. Anywey, the issue is the race condition between 'ubi_attach_mtd_dev()' and 'ubi_thread()'. If we do not serialize them, the 'wake_up_process()' call may be done before 'ubi_thread()' went seep, but after it checked 'ubi->thread_enabled'. This issue was spotted by Shin Hong <hongshin@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
-rw-r--r--drivers/mtd/ubi/build.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 2c3269ea133d..1405b556c65a 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -380,7 +380,7 @@ static void free_user_volumes(struct ubi_device *ubi)
380 * @ubi: UBI device description object 380 * @ubi: UBI device description object
381 * 381 *
382 * This function returns zero in case of success and a negative error code in 382 * This function returns zero in case of success and a negative error code in
383 * case of failure. Note, this function destroys all volumes if it failes. 383 * case of failure. Note, this function destroys all volumes if it fails.
384 */ 384 */
385static int uif_init(struct ubi_device *ubi) 385static int uif_init(struct ubi_device *ubi)
386{ 386{
@@ -871,9 +871,15 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
871 ubi->beb_rsvd_pebs); 871 ubi->beb_rsvd_pebs);
872 ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec); 872 ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec);
873 873
874 /*
875 * The below lock makes sure we do not race with 'ubi_thread()' which
876 * checks @ubi->thread_enabled. Otherwise we may fail to wake it up.
877 */
878 spin_lock(&ubi->wl_lock);
874 if (!DBG_DISABLE_BGT) 879 if (!DBG_DISABLE_BGT)
875 ubi->thread_enabled = 1; 880 ubi->thread_enabled = 1;
876 wake_up_process(ubi->bgt_thread); 881 wake_up_process(ubi->bgt_thread);
882 spin_unlock(&ubi->wl_lock);
877 883
878 ubi_devices[ubi_num] = ubi; 884 ubi_devices[ubi_num] = ubi;
879 return ubi_num; 885 return ubi_num;