mirror of
https://github.com/edk2-porting/linux-next.git
synced 2025-01-06 04:33:58 +08:00
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: 7d17c02a01
("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
This commit is contained in:
parent
77087a04c8
commit
a61528d997
@ -1111,9 +1111,9 @@ static void sm_release(struct mtd_blktrans_dev *dev)
|
||||
{
|
||||
struct sm_ftl *ftl = dev->priv;
|
||||
|
||||
mutex_lock(&ftl->mutex);
|
||||
del_timer_sync(&ftl->timer);
|
||||
cancel_work_sync(&ftl->flush_work);
|
||||
mutex_lock(&ftl->mutex);
|
||||
sm_cache_flush(ftl);
|
||||
mutex_unlock(&ftl->mutex);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user