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
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.
11 However, in order to make Smatch happy make sure the variable is
14 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
15 Signed-off-by: David S. Miller <davem@davemloft.net>
17 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 5 +++--
18 1 file changed, 3 insertions(+), 2 deletions(-)
20 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
21 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
22 @@ -1987,11 +1987,11 @@ static int mtk_poll_rx(struct napi_struc
24 struct mtk_rx_dma_v2 *rxd, trxd;
25 int done = 0, bytes = 0;
26 + dma_addr_t dma_addr = DMA_MAPPING_ERROR;
28 while (done < budget) {
29 unsigned int pktlen, *rxdcsum;
30 struct net_device *netdev;
31 - dma_addr_t dma_addr;
35 @@ -2168,7 +2168,8 @@ release_desc:
37 rxd->rxd2 = RX_DMA_PREP_PLEN0(ring->buf_size);
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);