Skip to content

Commit 4e48978

Browse files
teknoraverdavem330
authored andcommitted
mvpp2: fix pointer check
priv->page_pool is an array, so comparing against it will always return true. Do a meaningful check by checking priv->page_pool[0] instead. While at it, clear the page_pool pointers on deallocation, or when an allocation error happens during init. Reported-by: Colin Ian King <colin.king@canonical.com> Fixes: c2d6fe6 ("mvpp2: XDP TX support") Signed-off-by: Matteo Croce <mcroce@microsoft.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b416268 commit 4e48978

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,10 @@ static int mvpp2_bm_pool_destroy(struct device *dev, struct mvpp2 *priv,
548548
val |= MVPP2_BM_STOP_MASK;
549549
mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val);
550550

551-
if (priv->percpu_pools)
551+
if (priv->percpu_pools) {
552552
page_pool_destroy(priv->page_pool[bm_pool->id]);
553+
priv->page_pool[bm_pool->id] = NULL;
554+
}
553555

554556
dma_free_coherent(dev, bm_pool->size_bytes,
555557
bm_pool->virt_addr,
@@ -609,8 +611,15 @@ static int mvpp2_bm_init(struct device *dev, struct mvpp2 *priv)
609611
mvpp2_pools[pn].buf_num,
610612
mvpp2_pools[pn].pkt_size,
611613
dma_dir);
612-
if (IS_ERR(priv->page_pool[i]))
614+
if (IS_ERR(priv->page_pool[i])) {
615+
int j;
616+
617+
for (j = 0; j < i; j++) {
618+
page_pool_destroy(priv->page_pool[j]);
619+
priv->page_pool[j] = NULL;
620+
}
613621
return PTR_ERR(priv->page_pool[i]);
622+
}
614623
}
615624
}
616625

@@ -4486,7 +4495,7 @@ static int mvpp2_check_pagepool_dma(struct mvpp2_port *port)
44864495
if (!priv->percpu_pools)
44874496
return err;
44884497

4489-
if (!priv->page_pool)
4498+
if (!priv->page_pool[0])
44904499
return -ENOMEM;
44914500

44924501
for (i = 0; i < priv->port_count; i++) {

0 commit comments

Comments
 (0)