0084-net-next-mediatek-fix-missing-free-of-scratch-memory.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. From 5207debf8825a8b6f2934b7d39ef76c163dfd794 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <[email protected]>
  3. Date: Sat, 23 Apr 2016 09:18:28 +0200
  4. Subject: [PATCH 84/91] net-next: mediatek: fix missing free of scratch memory
  5. Scratch memory gets allocated in mtk_init_fq_dma() but the corresponding
  6. code to free it is missing inside mtk_dma_free() causing a memory leak.
  7. Signed-off-by: John Crispin <[email protected]>
  8. ---
  9. drivers/net/ethernet/mediatek/mtk_eth_soc.c | 18 +++++++++++++-----
  10. drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 ++
  11. 2 files changed, 15 insertions(+), 5 deletions(-)
  12. diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  13. index 37e9260..6896d17 100644
  14. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  15. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  16. @@ -469,14 +469,14 @@ static inline void mtk_rx_get_desc(struct mtk_rx_dma *rxd,
  17. /* the qdma core needs scratch memory to be setup */
  18. static int mtk_init_fq_dma(struct mtk_eth *eth)
  19. {
  20. - dma_addr_t phy_ring_head, phy_ring_tail;
  21. + dma_addr_t phy_ring_tail;
  22. int cnt = MTK_DMA_SIZE;
  23. dma_addr_t dma_addr;
  24. int i;
  25. eth->scratch_ring = dma_alloc_coherent(eth->dev,
  26. cnt * sizeof(struct mtk_tx_dma),
  27. - &phy_ring_head,
  28. + &eth->phy_scratch_ring,
  29. GFP_ATOMIC | __GFP_ZERO);
  30. if (unlikely(!eth->scratch_ring))
  31. return -ENOMEM;
  32. @@ -493,19 +493,19 @@ static int mtk_init_fq_dma(struct mtk_eth *eth)
  33. return -ENOMEM;
  34. memset(eth->scratch_ring, 0x0, sizeof(struct mtk_tx_dma) * cnt);
  35. - phy_ring_tail = phy_ring_head +
  36. + phy_ring_tail = eth->phy_scratch_ring +
  37. (sizeof(struct mtk_tx_dma) * (cnt - 1));
  38. for (i = 0; i < cnt; i++) {
  39. eth->scratch_ring[i].txd1 =
  40. (dma_addr + (i * MTK_QDMA_PAGE_SIZE));
  41. if (i < cnt - 1)
  42. - eth->scratch_ring[i].txd2 = (phy_ring_head +
  43. + eth->scratch_ring[i].txd2 = (eth->phy_scratch_ring +
  44. ((i + 1) * sizeof(struct mtk_tx_dma)));
  45. eth->scratch_ring[i].txd3 = TX_DMA_SDL(MTK_QDMA_PAGE_SIZE);
  46. }
  47. - mtk_w32(eth, phy_ring_head, MTK_QDMA_FQ_HEAD);
  48. + mtk_w32(eth, eth->phy_scratch_ring, MTK_QDMA_FQ_HEAD);
  49. mtk_w32(eth, phy_ring_tail, MTK_QDMA_FQ_TAIL);
  50. mtk_w32(eth, (cnt << 16) | cnt, MTK_QDMA_FQ_CNT);
  51. mtk_w32(eth, MTK_QDMA_PAGE_SIZE << 16, MTK_QDMA_FQ_BLEN);
  52. @@ -1203,6 +1203,14 @@ static void mtk_dma_free(struct mtk_eth *eth)
  53. for (i = 0; i < MTK_MAC_COUNT; i++)
  54. if (eth->netdev[i])
  55. netdev_reset_queue(eth->netdev[i]);
  56. + if (eth->scratch_ring) {
  57. + dma_free_coherent(eth->dev,
  58. + MTK_DMA_SIZE * sizeof(struct mtk_tx_dma),
  59. + eth->scratch_ring,
  60. + eth->phy_scratch_ring);
  61. + eth->scratch_ring = NULL;
  62. + eth->phy_scratch_ring = 0;
  63. + }
  64. mtk_tx_clean(eth);
  65. mtk_rx_clean(eth);
  66. kfree(eth->scratch_head);
  67. diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  68. index eed626d..57f7e8a 100644
  69. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  70. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  71. @@ -357,6 +357,7 @@ struct mtk_rx_ring {
  72. * @rx_ring: Pointer to the memore holding info about the RX ring
  73. * @rx_napi: The NAPI struct
  74. * @scratch_ring: Newer SoCs need memory for a second HW managed TX ring
  75. + * @phy_scratch_ring: physical address of scratch_ring
  76. * @scratch_head: The scratch memory that scratch_ring points to.
  77. * @clk_ethif: The ethif clock
  78. * @clk_esw: The switch clock
  79. @@ -384,6 +385,7 @@ struct mtk_eth {
  80. struct mtk_rx_ring rx_ring;
  81. struct napi_struct rx_napi;
  82. struct mtk_tx_dma *scratch_ring;
  83. + dma_addr_t phy_scratch_ring;
  84. void *scratch_head;
  85. struct clk *clk_ethif;
  86. struct clk *clk_esw;
  87. --
  88. 1.7.10.4