Commit 4e48978c authored by Matteo Croce's avatar Matteo Croce Committed by David S. Miller

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: default avatarColin Ian King <colin.king@canonical.com>
Fixes: c2d6fe61 ("mvpp2: XDP TX support")
Signed-off-by: default avatarMatteo Croce <mcroce@microsoft.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b416268b
...@@ -548,8 +548,10 @@ static int mvpp2_bm_pool_destroy(struct device *dev, struct mvpp2 *priv, ...@@ -548,8 +548,10 @@ static int mvpp2_bm_pool_destroy(struct device *dev, struct mvpp2 *priv,
val |= MVPP2_BM_STOP_MASK; val |= MVPP2_BM_STOP_MASK;
mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val); mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val);
if (priv->percpu_pools) if (priv->percpu_pools) {
page_pool_destroy(priv->page_pool[bm_pool->id]); page_pool_destroy(priv->page_pool[bm_pool->id]);
priv->page_pool[bm_pool->id] = NULL;
}
dma_free_coherent(dev, bm_pool->size_bytes, dma_free_coherent(dev, bm_pool->size_bytes,
bm_pool->virt_addr, bm_pool->virt_addr,
...@@ -609,10 +611,17 @@ static int mvpp2_bm_init(struct device *dev, struct mvpp2 *priv) ...@@ -609,10 +611,17 @@ static int mvpp2_bm_init(struct device *dev, struct mvpp2 *priv)
mvpp2_pools[pn].buf_num, mvpp2_pools[pn].buf_num,
mvpp2_pools[pn].pkt_size, mvpp2_pools[pn].pkt_size,
dma_dir); dma_dir);
if (IS_ERR(priv->page_pool[i])) if (IS_ERR(priv->page_pool[i])) {
int j;
for (j = 0; j < i; j++) {
page_pool_destroy(priv->page_pool[j]);
priv->page_pool[j] = NULL;
}
return PTR_ERR(priv->page_pool[i]); return PTR_ERR(priv->page_pool[i]);
} }
} }
}
dev_info(dev, "using %d %s buffers\n", poolnum, dev_info(dev, "using %d %s buffers\n", poolnum,
priv->percpu_pools ? "per-cpu" : "shared"); priv->percpu_pools ? "per-cpu" : "shared");
...@@ -4486,7 +4495,7 @@ static int mvpp2_check_pagepool_dma(struct mvpp2_port *port) ...@@ -4486,7 +4495,7 @@ static int mvpp2_check_pagepool_dma(struct mvpp2_port *port)
if (!priv->percpu_pools) if (!priv->percpu_pools)
return err; return err;
if (!priv->page_pool) if (!priv->page_pool[0])
return -ENOMEM; return -ENOMEM;
for (i = 0; i < priv->port_count; i++) { for (i = 0; i < priv->port_count; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment