e043a681da40f6a829b29e9a2e53c9d94f5a9134
[openwrt/staging/pepe2k.git] /
1 From: Lorenzo Bianconi <lorenzo@kernel.org>
2 Date: Wed, 7 Dec 2022 15:04:54 +0100
3 Subject: [PATCH] net: ethernet: mtk_wed: fix some possible NULL pointer
4 dereferences
5
6 Fix possible NULL pointer dereference in mtk_wed_detach routine checking
7 wo pointer is properly allocated before running mtk_wed_wo_reset() and
8 mtk_wed_wo_deinit().
9 Even if it is just a theoretical issue at the moment check wo pointer is
10 not NULL in mtk_wed_mcu_msg_update.
11 Moreover, honor mtk_wed_mcu_send_msg return value in mtk_wed_wo_reset()
12
13 Fixes: 799684448e3e ("net: ethernet: mtk_wed: introduce wed wo support")
14 Fixes: 4c5de09eb0d0 ("net: ethernet: mtk_wed: add configure wed wo support")
15 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
16 Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
17 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
18 ---
19
20 --- a/drivers/net/ethernet/mediatek/mtk_wed.c
21 +++ b/drivers/net/ethernet/mediatek/mtk_wed.c
22 @@ -174,9 +174,10 @@ mtk_wed_wo_reset(struct mtk_wed_device *
23 mtk_wdma_tx_reset(dev);
24 mtk_wed_reset(dev, MTK_WED_RESET_WED);
25
26 - mtk_wed_mcu_send_msg(wo, MTK_WED_MODULE_ID_WO,
27 - MTK_WED_WO_CMD_CHANGE_STATE, &state,
28 - sizeof(state), false);
29 + if (mtk_wed_mcu_send_msg(wo, MTK_WED_MODULE_ID_WO,
30 + MTK_WED_WO_CMD_CHANGE_STATE, &state,
31 + sizeof(state), false))
32 + return;
33
34 if (readx_poll_timeout(mtk_wed_wo_read_status, dev, val,
35 val == MTK_WED_WOIF_DISABLE_DONE,
36 @@ -632,9 +633,11 @@ mtk_wed_detach(struct mtk_wed_device *de
37 mtk_wed_free_tx_rings(dev);
38
39 if (mtk_wed_get_rx_capa(dev)) {
40 - mtk_wed_wo_reset(dev);
41 + if (hw->wed_wo)
42 + mtk_wed_wo_reset(dev);
43 mtk_wed_free_rx_rings(dev);
44 - mtk_wed_wo_deinit(hw);
45 + if (hw->wed_wo)
46 + mtk_wed_wo_deinit(hw);
47 }
48
49 if (dev->wlan.bus_type == MTK_WED_BUS_PCIE) {
50 --- a/drivers/net/ethernet/mediatek/mtk_wed_mcu.c
51 +++ b/drivers/net/ethernet/mediatek/mtk_wed_mcu.c
52 @@ -207,6 +207,9 @@ int mtk_wed_mcu_msg_update(struct mtk_we
53 if (dev->hw->version == 1)
54 return 0;
55
56 + if (WARN_ON(!wo))
57 + return -ENODEV;
58 +
59 return mtk_wed_mcu_send_msg(wo, MTK_WED_MODULE_ID_WO, id, data, len,
60 true);
61 }