Merge branch 'fix-possible-deadlock-during-wed-attach'

Lorenzo Bianconi says:

====================
fix possible deadlock during WED attach

Fix a possible deadlock in mtk_wed_attach if mtk_wed_wo_init routine fails.
Check wo pointer is properly allocated before running mtk_wed_wo_reset() and
mtk_wed_wo_deinit().
====================

Link: https://lore.kernel.org/r/cover.1670421354.git.lorenzo@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski 2022-12-08 19:47:45 -08:00
commit ecd6df3c1b
2 changed files with 23 additions and 10 deletions

View File

@ -174,9 +174,10 @@ mtk_wed_wo_reset(struct mtk_wed_device *dev)
mtk_wdma_tx_reset(dev);
mtk_wed_reset(dev, MTK_WED_RESET_WED);
mtk_wed_mcu_send_msg(wo, MTK_WED_MODULE_ID_WO,
MTK_WED_WO_CMD_CHANGE_STATE, &state,
sizeof(state), false);
if (mtk_wed_mcu_send_msg(wo, MTK_WED_MODULE_ID_WO,
MTK_WED_WO_CMD_CHANGE_STATE, &state,
sizeof(state), false))
return;
if (readx_poll_timeout(mtk_wed_wo_read_status, dev, val,
val == MTK_WED_WOIF_DISABLE_DONE,
@ -576,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);
@ -590,9 +589,11 @@ mtk_wed_detach(struct mtk_wed_device *dev)
mtk_wed_free_tx_rings(dev);
if (mtk_wed_get_rx_capa(dev)) {
mtk_wed_wo_reset(dev);
if (hw->wed_wo)
mtk_wed_wo_reset(dev);
mtk_wed_free_rx_rings(dev);
mtk_wed_wo_deinit(hw);
if (hw->wed_wo)
mtk_wed_wo_deinit(hw);
}
if (dev->wlan.bus_type == MTK_WED_BUS_PCIE) {
@ -612,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);
}
@ -1494,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);

View File

@ -207,6 +207,9 @@ int mtk_wed_mcu_msg_update(struct mtk_wed_device *dev, int id, void *data,
if (dev->hw->version == 1)
return 0;
if (WARN_ON(!wo))
return -ENODEV;
return mtk_wed_mcu_send_msg(wo, MTK_WED_MODULE_ID_WO, id, data, len,
true);
}