d1c5fb6656db54f069beece26653d8e5a7a35236
[openwrt/staging/neocturne.git] /
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
4 mtk_wed_wo_init fails
5
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.
9
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>
14 ---
15
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
19 }
20
21 static void
22 -mtk_wed_detach(struct mtk_wed_device *dev)
23 +__mtk_wed_detach(struct mtk_wed_device *dev)
24 {
25 struct mtk_wed_hw *hw = dev->hw;
26
27 - mutex_lock(&hw_lock);
28 -
29 mtk_wed_deinit(dev);
30
31 mtk_wdma_rx_reset(dev);
32 @@ -657,6 +655,13 @@ mtk_wed_detach(struct mtk_wed_device *de
33 module_put(THIS_MODULE);
34
35 hw->wed_dev = NULL;
36 +}
37 +
38 +static void
39 +mtk_wed_detach(struct mtk_wed_device *dev)
40 +{
41 + mutex_lock(&hw_lock);
42 + __mtk_wed_detach(dev);
43 mutex_unlock(&hw_lock);
44 }
45
46 @@ -1545,8 +1550,10 @@ mtk_wed_attach(struct mtk_wed_device *de
47 ret = mtk_wed_wo_init(hw);
48 }
49 out:
50 - if (ret)
51 - mtk_wed_detach(dev);
52 + if (ret) {
53 + dev_err(dev->hw->dev, "failed to attach wed device\n");
54 + __mtk_wed_detach(dev);
55 + }
56 unlock:
57 mutex_unlock(&hw_lock);
58