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.
Unified · Split
| @@ -548,8 +548,10 @@ static int mvpp2_bm_pool_destroy(struct device *dev, struct mvpp2 *priv, · 547 unmodified lines | ||
| 548 | 548 | val |= MVPP2_BM_STOP_MASK; |
| 549 | 549 | mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val); |
| 550 | 550 | |
| 551 | − if (priv->percpu_pools) | |
| 551 | + if (priv->percpu_pools) { | |
| 552 | 552 | page_pool_destroy(priv->page_pool[bm_pool->id]); |
| 553 | + priv->page_pool[bm_pool->id] = NULL; | |
| 554 | + } | |
| 553 | 555 | |
| 554 | 556 | dma_free_coherent(dev, bm_pool->size_bytes, |
| 555 | 557 | bm_pool->virt_addr, |
| @@ -609,8 +611,15 @@ static int mvpp2_bm_init(struct device *dev, struct mvpp2 *priv) · 53 unmodified lines | ||
| 609 | 611 | mvpp2_pools[pn].buf_num, |
| 610 | 612 | mvpp2_pools[pn].pkt_size, |
| 611 | 613 | 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 | + } | |
| 613 | 621 | return PTR_ERR(priv->page_pool[i]); |
| 622 | + } | |
| 614 | 623 | } |
| 615 | 624 | } |
| 616 | 625 | |
| @@ -4486,7 +4495,7 @@ static int mvpp2_check_pagepool_dma(struct mvpp2_port *port) · 3869 unmodified lines | ||
| 4486 | 4495 | if (!priv->percpu_pools) |
| 4487 | 4496 | return err; |
| 4488 | 4497 | |
| 4489 | − if (!priv->page_pool) | |
| 4498 | + if (!priv->page_pool[0]) | |
| 4490 | 4499 | return -ENOMEM; |
| 4491 | 4500 | |
| 4492 | 4501 | for (i = 0; i < priv->port_count; i++) { |