Skip to contentSkip to conversation

eth: mlx4: Fix IS_ERR() vs NULL check bug in mlx4_en_create_rx_ring

PATCH Superseded Miaoqian Lin 4 participants 6 messages Aug 5, 2025 – Aug 18, 2025

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eth: mlx4: Fix IS_ERR() vs NULL check bug in mlx4_en_create_rx_ring

Replace NULL check with IS_ERR() check after calling page_pool_create() since this function returns error pointers (ERR_PTR).
Using NULL check could lead to invalid pointer dereference.

Fixes 8533b14b3d65 ("eth: mlx4: create a page pool for Rx")
---
 drivers/net/ethernet/mellanox/mlx4/en_rx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1 -1
index 92a16ddb7d86..b60f3d5fbd16 100644
@@ -267,7 +267,7 @@ int mlx4_en_create_rx_ring(struct mlx4_en_priv *priv,
 	pp.dma_dir = priv->dma_dir;
 
 	ring->pp = page_pool_create(&pp);
-	if (!ring->pp)
+	if (IS_ERR(ring->pp))
 		goto err_ring;
 
 	if (xdp_rxq_info_reg(&ring->xdp_rxq, priv->dev, queue_index, 0) < 0)
Signature · 1 line
2.25.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Miaoqian Lin

Replace NULL check with IS_ERR() check after calling page_pool_create() since this function returns error pointers (ERR_PTR).
Using NULL check could lead to invalid pointer dereference.

Fixes 8533b14b3d65 ("eth: mlx4: create a page pool for Rx")
maintainer
#2 lore raw
In reply to Miaoqian Lin

drivers/net/ethernet/mellanox/mlx4/en_rx.c int mlx4_en_create_rx_ring(struct mlx4_en_priv *priv, · line 271

Quoted 4 lines · On Tue, 5 Aug 2025 06:50:57 +0400 Miaoqian Lin wrote:
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1 -1
 	ring->pp = page_pool_create(&pp);
-	if (!ring->pp)
+	if (IS_ERR(ring->pp))
 		goto err_ring;

Thanks for fixing! Looks we previously depended on err being initialized to -ENOMEM, but since we have an errno now, I think it'd be better to use it:

	if (IS_ERR(ring->pp)) {
		err = PTR_ERR(ring->pp);
		goto err_ring;
	}
#3 lore raw
Quoted 10 lines · Jakub Kicinski

drivers/net/ethernet/mellanox/mlx4/en_rx.c int mlx4_en_create_rx_ring(struct mlx4_en_priv *priv, · line 271

Quoted 4 lines · On Tue, 5 Aug 2025 06:50:57 +0400 Miaoqian Lin wrote:
  	ring->pp = page_pool_create(&pp);
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1 -1
-	if (!ring->pp)
+	if (IS_ERR(ring->pp))
  		goto err_ring;

Thanks for fixing! Looks we previously depended on err being initialized to -ENOMEM, but since we have an errno now, I think it'd be better to use it:

Quoted 5 lines
	if (IS_ERR(ring->pp)) {
		err = PTR_ERR(ring->pp);
		goto err_ring;
	}

+1

#4 lore raw

PATCH v2 1/1 eth: mlx4: Fix IS_ERR() vs NULL check bug in mlx4_en_create_rx_ring

In reply to Miaoqian Lin

Replace NULL check with IS_ERR() check after calling page_pool_create() since this function returns error pointers (ERR_PTR).
Using NULL check could lead to invalid pointer dereference.

Fixes 8533b14b3d65 ("eth: mlx4: create a page pool for Rx")

---
Changes in v2:
use err = PTR_ERR(ring->pp);
v1 link: https://lore.kernel.org/all/[email protected]

---
 drivers/net/ethernet/mellanox/mlx4/en_rx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx4/en_rx.c +3 -1
index 92a16ddb7d86..13666d50b90f 100644
@@ -267,8 +267,10 @@ int mlx4_en_create_rx_ring(struct mlx4_en_priv *priv,
    pp.dma_dir = priv->dma_dir;
 
    ring->pp = page_pool_create(&pp);
-   if (!ring->pp)
+   if (IS_ERR(ring->pp)) {
+       err = PTR_ERR(ring->pp);
        goto err_ring;
+   }
 
    if (xdp_rxq_info_reg(&ring->xdp_rxq, priv->dev, queue_index, 0) < 0)
        goto err_pp;
Signature · 1 line
2.25.1
maintainer
#5 lore raw
Quoted 3 lines · On Mon, 18 Aug 2025 00:38:30 +0800 Miaoqian Lin wrote:

Replace NULL check with IS_ERR() check after calling page_pool_create() since this function returns error pointers (ERR_PTR).
Using NULL check could lead to invalid pointer dereference.

The v2 patch is white-space corrupted. The v1 was fine, so maybe try to send it the way you send the v1?
Please do *not* try to send the new version of the patch in reply to the thread of v1. The link to v1 you put in the changelog is enough.

Signature · 1 line
pw-bot: cr