]> www.infradead.org Git - nvme.git/commitdiff
net: ethernet: mtk_eth_soc: fix memory corruption during fq dma init
authorFelix Fietkau <nbd@nbd.name>
Tue, 15 Oct 2024 08:17:55 +0000 (10:17 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 17 Oct 2024 10:02:29 +0000 (12:02 +0200)
The loop responsible for allocating up to MTK_FQ_DMA_LENGTH buffers must
only touch as many descriptors, otherwise it ends up corrupting unrelated
memory. Fix the loop iteration count accordingly.

Fixes: c57e55819443 ("net: ethernet: mtk_eth_soc: handle dma buffer size soc specific")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20241015081755.31060-1-nbd@nbd.name
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/mediatek/mtk_eth_soc.c

index 16ca427cf4c3f4325cc6942efefc2c9d68237d27..ed7313c10a0524eb0763825b4ce27b1b64363585 100644 (file)
@@ -1171,7 +1171,7 @@ static int mtk_init_fq_dma(struct mtk_eth *eth)
                if (unlikely(dma_mapping_error(eth->dma_dev, dma_addr)))
                        return -ENOMEM;
 
-               for (i = 0; i < cnt; i++) {
+               for (i = 0; i < len; i++) {
                        struct mtk_tx_dma_v2 *txd;
 
                        txd = eth->scratch_ring + (j * MTK_FQ_DMA_LENGTH + i) * soc->tx.desc_size;