Skip to contentSkip to conversation

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

PATCH Applied Miaoqian Lin 3 participants 3 messages Aug 28, 2025 – Sep 1, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v3 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")

----
Changes in v3:
- fix IS_ERR
Changes in v2:
- use err = PTR_ERR(ring->pp);
v1 link: https://lore.kernel.org/all/[email protected]
v2 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.39.5 (Apple Git-154)
Reviewed-by on v3 1/1
#1 lore raw
Quoted 23 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")

----
Changes in v3:
- fix IS_ERR
Changes in v2:
- use err = PTR_ERR(ring->pp);
v1 link: https://lore.kernel.org/all/[email protected]
v2 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 +0 -0
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;

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

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +3 -1
 
  	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;

You should wait for 24h before submission of the next version. That's a general rule for netdev.

But given that this change is quite small...

#2 lore raw
In reply to Miaoqian Lin
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 28 Aug 2025 20:18:58 +0800 you 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.

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

[...]

Here is the summary with links:
- [v3] eth: mlx4: Fix IS_ERR() vs NULL check bug in mlx4_en_create_rx_ring

    https://git.kernel.org/netdev/net/c/e580beaf43d5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html