6f1639a5720abc4fc52d6055a74845acaa0ef85c
[openwrt/staging/pepe2k.git] /
1 From 3b12f42772c26869d60398c1710aa27b27cd945c Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Mon, 21 Aug 2023 17:12:44 +0100
4 Subject: [PATCH 109/250] net: ethernet: mtk_eth_soc: fix NULL pointer on hw
5 reset
6
7 When a hardware reset is triggered on devices not initializing WED the
8 calls to mtk_wed_fe_reset and mtk_wed_fe_reset_complete dereference a
9 pointer on uninitialized stack memory.
10 Break out of both functions in case a hw_list entry is 0.
11
12 Fixes: 08a764a7c51b ("net: ethernet: mtk_wed: add reset/reset_complete callbacks")
13 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
14 Reviewed-by: Simon Horman <horms@kernel.org>
15 Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
16 Link: https://lore.kernel.org/r/5465c1609b464cc7407ae1530c40821dcdf9d3e6.1692634266.git.daniel@makrotopia.org
17 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
18 ---
19 drivers/net/ethernet/mediatek/mtk_wed.c | 12 ++++++++++--
20 1 file changed, 10 insertions(+), 2 deletions(-)
21
22 --- a/drivers/net/ethernet/mediatek/mtk_wed.c
23 +++ b/drivers/net/ethernet/mediatek/mtk_wed.c
24 @@ -214,9 +214,13 @@ void mtk_wed_fe_reset(void)
25
26 for (i = 0; i < ARRAY_SIZE(hw_list); i++) {
27 struct mtk_wed_hw *hw = hw_list[i];
28 - struct mtk_wed_device *dev = hw->wed_dev;
29 + struct mtk_wed_device *dev;
30 int err;
31
32 + if (!hw)
33 + break;
34 +
35 + dev = hw->wed_dev;
36 if (!dev || !dev->wlan.reset)
37 continue;
38
39 @@ -237,8 +241,12 @@ void mtk_wed_fe_reset_complete(void)
40
41 for (i = 0; i < ARRAY_SIZE(hw_list); i++) {
42 struct mtk_wed_hw *hw = hw_list[i];
43 - struct mtk_wed_device *dev = hw->wed_dev;
44 + struct mtk_wed_device *dev;
45 +
46 + if (!hw)
47 + break;
48
49 + dev = hw->wed_dev;
50 if (!dev || !dev->wlan.reset_complete)
51 continue;
52