Skip to content

Commit 6e7d801

Browse files
ubi: fastmap: Cancel work upon detach
Ben Hutchings pointed out that 29b7a6f ("ubi: fastmap: Don't flush fastmap work on detach") does not really fix the problem, it just reduces the risk to hit the race window where fastmap work races against free()'ing ubi->volumes[]. The correct approach is making sure that no more fastmap work is in progress before we free ubi data structures. So we cancel fastmap work right after the ubi background thread is stopped. By setting ubi->thread_enabled to zero we make sure that no further work tries to wake the thread. Fixes: 29b7a6f ("ubi: fastmap: Don't flush fastmap work on detach") Fixes: 74cdaf2 ("UBI: Fastmap: Fix memory leaks while closing the WL sub-system") Cc: [email protected] Cc: Ben Hutchings <[email protected]> Cc: Martin Townsend <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent e1db654 commit 6e7d801

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

drivers/mtd/ubi/build.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,9 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
10911091
if (ubi->bgt_thread)
10921092
kthread_stop(ubi->bgt_thread);
10931093

1094+
#ifdef CONFIG_MTD_UBI_FASTMAP
1095+
cancel_work_sync(&ubi->fm_work);
1096+
#endif
10941097
ubi_debugfs_exit_dev(ubi);
10951098
uif_close(ubi);
10961099

drivers/mtd/ubi/wl.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,7 @@ int ubi_thread(void *u)
15051505
}
15061506

15071507
dbg_wl("background thread \"%s\" is killed", ubi->bgt_name);
1508+
ubi->thread_enabled = 0;
15081509
return 0;
15091510
}
15101511

@@ -1514,9 +1515,6 @@ int ubi_thread(void *u)
15141515
*/
15151516
static void shutdown_work(struct ubi_device *ubi)
15161517
{
1517-
#ifdef CONFIG_MTD_UBI_FASTMAP
1518-
flush_work(&ubi->fm_work);
1519-
#endif
15201518
while (!list_empty(&ubi->works)) {
15211519
struct ubi_work *wrk;
15221520

0 commit comments

Comments
 (0)