Commit ecd6df3c authored by Jakub Kicinski's avatar Jakub Kicinski

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.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 3df96774 587585e1
......@@ -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,
if (mtk_wed_mcu_send_msg(wo, MTK_WED_MODULE_ID_WO,
MTK_WED_WO_CMD_CHANGE_STATE, &state,
sizeof(state), false);
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,8 +589,10 @@ mtk_wed_detach(struct mtk_wed_device *dev)
mtk_wed_free_tx_rings(dev);
if (mtk_wed_get_rx_capa(dev)) {
if (hw->wed_wo)
mtk_wed_wo_reset(dev);
mtk_wed_free_rx_rings(dev);
if (hw->wed_wo)
mtk_wed_wo_deinit(hw);
}
......@@ -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);
......
......@@ -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);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment