1 From: Lorenzo Bianconi <lorenzo@kernel.org>
2 Date: Wed, 7 Dec 2022 15:04:55 +0100
3 Subject: [PATCH] net: ethernet: mtk_wed: fix possible deadlock if
6 Introduce __mtk_wed_detach() in order to avoid a deadlock in
7 mtk_wed_attach routine if mtk_wed_wo_init fails since both
8 mtk_wed_attach and mtk_wed_detach run holding hw_lock mutex.
10 Fixes: 4c5de09eb0d0 ("net: ethernet: mtk_wed: add configure wed wo support")
11 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
12 Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
13 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
16 --- a/drivers/net/ethernet/mediatek/mtk_wed.c
17 +++ b/drivers/net/ethernet/mediatek/mtk_wed.c
18 @@ -619,12 +619,10 @@ mtk_wed_deinit(struct mtk_wed_device *de
22 -mtk_wed_detach(struct mtk_wed_device *dev)
23 +__mtk_wed_detach(struct mtk_wed_device *dev)
25 struct mtk_wed_hw *hw = dev->hw;
27 - mutex_lock(&hw_lock);
31 mtk_wdma_rx_reset(dev);
32 @@ -657,6 +655,13 @@ mtk_wed_detach(struct mtk_wed_device *de
33 module_put(THIS_MODULE);
39 +mtk_wed_detach(struct mtk_wed_device *dev)
41 + mutex_lock(&hw_lock);
42 + __mtk_wed_detach(dev);
43 mutex_unlock(&hw_lock);
46 @@ -1538,8 +1543,10 @@ mtk_wed_attach(struct mtk_wed_device *de
47 ret = mtk_wed_wo_init(hw);
51 - mtk_wed_detach(dev);
53 + dev_err(dev->hw->dev, "failed to attach wed device\n");
54 + __mtk_wed_detach(dev);
57 mutex_unlock(&hw_lock);