Skip to content

Commit

Permalink
net/bnx2x: fix memory leak
Browse files Browse the repository at this point in the history
[ upstream commit 68ed074 ]

We allocate DMA memory but never free after using it.
Add function to free DMA memory.

Fixes: b5bf771 ("bnx2x: driver support routines")

Signed-off-by: Shahed Shaikh <shshaikh@marvell.com>
  • Loading branch information
Shahed Shaikh authored and kevintraynor committed May 7, 2019
1 parent a88105e commit 272093c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
15 changes: 15 additions & 0 deletions drivers/net/bnx2x/bnx2x.c
Expand Up @@ -185,13 +185,27 @@ bnx2x_dma_alloc(struct bnx2x_softc *sc, size_t size, struct bnx2x_dma *dma,
}
dma->paddr = (uint64_t) z->iova;
dma->vaddr = z->addr;
dma->mzone = (const void *)z;

PMD_DRV_LOG(DEBUG, sc,
"%s: virt=%p phys=%" PRIx64, msg, dma->vaddr, dma->paddr);

return 0;
}

void bnx2x_dma_free(struct bnx2x_dma *dma)
{
if (dma->mzone == NULL)
return;

rte_memzone_free((const struct rte_memzone *)dma->mzone);
dma->sc = NULL;
dma->paddr = 0;
dma->vaddr = NULL;
dma->nseg = 0;
dma->mzone = NULL;
}

static int bnx2x_acquire_hw_lock(struct bnx2x_softc *sc, uint32_t resource)
{
uint32_t lock_status;
Expand Down Expand Up @@ -2436,6 +2450,7 @@ static int bnx2x_alloc_mem(struct bnx2x_softc *sc)

static void bnx2x_free_fw_stats_mem(struct bnx2x_softc *sc)
{
bnx2x_dma_free(&sc->fw_stats_dma);
sc->fw_stats_num = 0;

sc->fw_stats_req_size = 0;
Expand Down
3 changes: 2 additions & 1 deletion drivers/net/bnx2x/bnx2x.h
Expand Up @@ -319,6 +319,7 @@ struct bnx2x_dma {
rte_iova_t paddr;
void *vaddr;
int nseg;
const void *mzone;
char msg[RTE_MEMZONE_NAMESIZE - 6];
};

Expand Down Expand Up @@ -1753,7 +1754,7 @@ int bnx2x_cmpxchg(volatile int *addr, int old, int new);

int bnx2x_dma_alloc(struct bnx2x_softc *sc, size_t size,
struct bnx2x_dma *dma, const char *msg, uint32_t align);

void bnx2x_dma_free(struct bnx2x_dma *dma);
uint32_t bnx2x_dmae_opcode_add_comp(uint32_t opcode, uint8_t comp_type);
uint32_t bnx2x_dmae_opcode_clr_src_reset(uint32_t opcode);
uint32_t bnx2x_dmae_opcode(struct bnx2x_softc *sc, uint8_t src_type,
Expand Down
17 changes: 9 additions & 8 deletions drivers/net/bnx2x/ecore_sp.h
Expand Up @@ -151,14 +151,15 @@ typedef rte_spinlock_t ECORE_MUTEX_SPIN;
} \
} while (0)

#define ECORE_ILT_FREE(x, y, size) \
do { \
if (x) { \
rte_free(x); \
x = NULL; \
y = 0; \
} \
} while (0)
#define ECORE_ILT_FREE(x, y, size) \
do { \
if (x) { \
bnx2x_dma_free((struct bnx2x_dma *)x); \
rte_free(x); \
x = NULL; \
y = 0; \
} \
} while (0)

#define ECORE_IS_VALID_ETHER_ADDR(_mac) TRUE

Expand Down

0 comments on commit 272093c

Please sign in to comment.