Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mtd: sm_ftl: Fix deadlock caused by cancel_work_sync in sm_release

There is a deadlock between sm_release and sm_cache_flush_work
which is a work item. The cancel_work_sync in sm_release will
not return until sm_cache_flush_work is finished. If we hold
mutex_lock and use cancel_work_sync to wait the work item to
finish, the work item also requires mutex_lock. As a result,
the sm_release will be blocked forever. The race condition is
shown below:

(Thread 1) | (Thread 2)
sm_release |
mutex_lock(&ftl->mutex) | sm_cache_flush_work
| mutex_lock(&ftl->mutex)
cancel_work_sync | ...

This patch moves del_timer_sync and cancel_work_sync out of
mutex_lock in order to mitigate deadlock.

Fixes: 7d17c02a01a1 ("mtd: Add new SmartMedia/xD FTL")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20220524044841.10517-1-duoming@zju.edu.cn

authored by

Duoming Zhou and committed by
Miquel Raynal
a61528d9 77087a04

+1 -1
+1 -1
drivers/mtd/sm_ftl.c
··· 1111 1111 { 1112 1112 struct sm_ftl *ftl = dev->priv; 1113 1113 1114 - mutex_lock(&ftl->mutex); 1115 1114 del_timer_sync(&ftl->timer); 1116 1115 cancel_work_sync(&ftl->flush_work); 1116 + mutex_lock(&ftl->mutex); 1117 1117 sm_cache_flush(ftl); 1118 1118 mutex_unlock(&ftl->mutex); 1119 1119 }