Skip to content

Commit 9f898fc

Browse files
Ryceancurrykuba-moo
authored andcommitted
net: bcmasp: fix memory leak when bringing down interface
When bringing down the TX rings we flush the rings but forget to reclaimed the flushed packets. This leads to a memory leak since we do not free the dma mapped buffers. This also leads to tx control block corruption when bringing down the interface for power management. Fixes: 490cb41 ("net: bcmasp: Add support for ASP2.0 Ethernet controller") Signed-off-by: Justin Chen <[email protected]> Acked-by: Florian Fainelli <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 680d11f commit 9f898fc

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,8 @@ static void umac_init(struct bcmasp_intf *intf)
436436
umac_wl(intf, 0x800, UMC_RX_MAX_PKT_SZ);
437437
}
438438

439-
static int bcmasp_tx_poll(struct napi_struct *napi, int budget)
439+
static int bcmasp_tx_reclaim(struct bcmasp_intf *intf)
440440
{
441-
struct bcmasp_intf *intf =
442-
container_of(napi, struct bcmasp_intf, tx_napi);
443441
struct bcmasp_intf_stats64 *stats = &intf->stats64;
444442
struct device *kdev = &intf->parent->pdev->dev;
445443
unsigned long read, released = 0;
@@ -482,10 +480,16 @@ static int bcmasp_tx_poll(struct napi_struct *napi, int budget)
482480
DESC_RING_COUNT);
483481
}
484482

485-
/* Ensure all descriptors have been written to DRAM for the hardware
486-
* to see updated contents.
487-
*/
488-
wmb();
483+
return released;
484+
}
485+
486+
static int bcmasp_tx_poll(struct napi_struct *napi, int budget)
487+
{
488+
struct bcmasp_intf *intf =
489+
container_of(napi, struct bcmasp_intf, tx_napi);
490+
int released = 0;
491+
492+
released = bcmasp_tx_reclaim(intf);
489493

490494
napi_complete(&intf->tx_napi);
491495

@@ -797,6 +801,7 @@ static void bcmasp_init_tx(struct bcmasp_intf *intf)
797801
intf->tx_spb_dma_read = intf->tx_spb_dma_addr;
798802
intf->tx_spb_index = 0;
799803
intf->tx_spb_clean_index = 0;
804+
memset(intf->tx_cbs, 0, sizeof(struct bcmasp_tx_cb) * DESC_RING_COUNT);
800805

801806
/* Make sure channels are disabled */
802807
tx_spb_ctrl_wl(intf, 0x0, TX_SPB_CTRL_ENABLE);
@@ -885,6 +890,8 @@ static void bcmasp_netif_deinit(struct net_device *dev)
885890
} while (timeout-- > 0);
886891
tx_spb_dma_wl(intf, 0x0, TX_SPB_DMA_FIFO_CTRL);
887892

893+
bcmasp_tx_reclaim(intf);
894+
888895
umac_enable_set(intf, UMC_CMD_TX_EN, 0);
889896

890897
phy_stop(dev->phydev);

0 commit comments

Comments
 (0)