Skip to content

Commit

Permalink
net: ethernet: mtk_wed: fix possible deadlock if mtk_wed_wo_init fails
Browse files Browse the repository at this point in the history
Introduce __mtk_wed_detach() in order to avoid a deadlock in
mtk_wed_attach routine if mtk_wed_wo_init fails since both
mtk_wed_attach and mtk_wed_detach run holding hw_lock mutex.

Fixes: 4c5de09 ("net: ethernet: mtk_wed: add configure wed wo support")
Signed-off-by: Lorenzo Bianconi <[email protected]>
Reviewed-by: Leon Romanovsky <[email protected]>
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
LorenzoBianconi authored and kuba-moo committed Dec 9, 2022
1 parent c79e0af commit 587585e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions drivers/net/ethernet/mediatek/mtk_wed.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,10 @@ mtk_wed_deinit(struct mtk_wed_device *dev)
}

static void
mtk_wed_detach(struct mtk_wed_device *dev)
__mtk_wed_detach(struct mtk_wed_device *dev)
{
struct mtk_wed_hw *hw = dev->hw;

mutex_lock(&hw_lock);

mtk_wed_deinit(dev);

mtk_wdma_rx_reset(dev);
Expand Down Expand Up @@ -615,6 +613,13 @@ mtk_wed_detach(struct mtk_wed_device *dev)
module_put(THIS_MODULE);

hw->wed_dev = NULL;
}

static void
mtk_wed_detach(struct mtk_wed_device *dev)
{
mutex_lock(&hw_lock);
__mtk_wed_detach(dev);
mutex_unlock(&hw_lock);
}

Expand Down Expand Up @@ -1497,8 +1502,10 @@ mtk_wed_attach(struct mtk_wed_device *dev)
ret = mtk_wed_wo_init(hw);
}
out:
if (ret)
mtk_wed_detach(dev);
if (ret) {
dev_err(dev->hw->dev, "failed to attach wed device\n");
__mtk_wed_detach(dev);
}
unlock:
mutex_unlock(&hw_lock);

Expand Down

0 comments on commit 587585e

Please sign in to comment.