Skip to content

Commit

Permalink
net: ethernet: mtk_eth_soc: fix uninitialized variable
Browse files Browse the repository at this point in the history
Variable dma_addr in function mtk_poll_rx can be uninitialized on
some of the error paths. In practise this doesn't matter, even random
data present in uninitialized stack memory can safely be used in the
way it happens in the error path.

However, in order to make Smatch happy make sure the variable is
always initialized.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Daniel Golle authored and David S. Miller committed Sep 11, 2023
1 parent c821a88 commit e10a35a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/net/ethernet/mediatek/mtk_eth_soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2005,11 +2005,11 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
u8 *data, *new_data;
struct mtk_rx_dma_v2 *rxd, trxd;
int done = 0, bytes = 0;
dma_addr_t dma_addr = DMA_MAPPING_ERROR;

while (done < budget) {
unsigned int pktlen, *rxdcsum;
struct net_device *netdev;
dma_addr_t dma_addr;
u32 hash, reason;
int mac = 0;

Expand Down Expand Up @@ -2186,7 +2186,8 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
else
rxd->rxd2 = RX_DMA_PREP_PLEN0(ring->buf_size);

if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA))
if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA) &&
likely(dma_addr != DMA_MAPPING_ERROR))
rxd->rxd2 |= RX_DMA_PREP_ADDR64(dma_addr);

ring->calc_idx = idx;
Expand Down

0 comments on commit e10a35a

Please sign in to comment.