959add1954c98f8e944808c680b5a5ae0251b3f6
[openwrt/staging/thess.git] /
1 From e10a35abb3da12b812cfb6fc6137926a0c81e39a Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Sun, 10 Sep 2023 22:40:30 +0100
4 Subject: [PATCH] net: ethernet: mtk_eth_soc: fix uninitialized variable
5
6 Variable dma_addr in function mtk_poll_rx can be uninitialized on
7 some of the error paths. In practise this doesn't matter, even random
8 data present in uninitialized stack memory can safely be used in the
9 way it happens in the error path.
10
11 However, in order to make Smatch happy make sure the variable is
12 always initialized.
13
14 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
15 Signed-off-by: David S. Miller <davem@davemloft.net>
16 ---
17 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 5 +++--
18 1 file changed, 3 insertions(+), 2 deletions(-)
19
20 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
21 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
22 @@ -1940,11 +1940,11 @@ static int mtk_poll_rx(struct napi_struc
23 u8 *data, *new_data;
24 struct mtk_rx_dma_v2 *rxd, trxd;
25 int done = 0, bytes = 0;
26 + dma_addr_t dma_addr = DMA_MAPPING_ERROR;
27
28 while (done < budget) {
29 unsigned int pktlen, *rxdcsum;
30 struct net_device *netdev;
31 - dma_addr_t dma_addr;
32 u32 hash, reason;
33 int mac = 0;
34
35 @@ -2121,7 +2121,8 @@ release_desc:
36 else
37 rxd->rxd2 = RX_DMA_PREP_PLEN0(ring->buf_size);
38
39 - if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA))
40 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA) &&
41 + likely(dma_addr != DMA_MAPPING_ERROR))
42 rxd->rxd2 |= RX_DMA_PREP_ADDR64(dma_addr);
43
44 ring->calc_idx = idx;