History

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.

Matteo Croce committed 6 years ago

Commit 4e489781 parent b4162681 file · +12 −3Browse files

Unified · Split

drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c+12−3
@@ -548,8 +548,10 @@ static int mvpp2_bm_pool_destroy(struct device *dev, struct mvpp2 *priv, · 547 unmodified lines
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) · 53 unmodified lines
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) · 3869 unmodified lines
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++) {