Skip to contentSkip to conversation

net: ethernet: rtsn: Fix a null pointer dereference in rtsn_probe()

PATCH Applied Haoxiang Li 3 participants 3 messages Jul 3, 2025 – Jul 8, 2025

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

PATCH v2 1/1 net: ethernet: rtsn: Fix a null pointer dereference in rtsn_probe()

Add check for the return value of rcar_gen4_ptp_alloc() to prevent potential null pointer dereference.

Fixes b0d3969d2b4d ("net: ethernet: rtsn: Add support for Renesas Ethernet-TSN")

---
Changes in v2:
- Add a blank line to make the grouping similar to the style of other error checks in probe. Thanks, Niklas!

---
 drivers/net/ethernet/renesas/rtsn.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/ethernet/renesas/rtsn.c +5 -0
index 6b3f7fca8d15..05c4b6c8c9c3 100644
@@ -1259,7 +1259,12 @@ static int rtsn_probe(struct platform_device *pdev)
 	priv = netdev_priv(ndev);
 	priv->pdev = pdev;
 	priv->ndev = ndev;
+
 	priv->ptp_priv = rcar_gen4_ptp_alloc(pdev);
+	if (!priv->ptp_priv) {
+		ret = -ENOMEM;
+		goto error_free;
+	}
 
 	spin_lock_init(&priv->lock);
 	platform_set_drvdata(pdev, priv);
Signature · 1 line
2.25.1
maintainer Reviewed-by on v2 1/1
#1 lore raw

Hi Haoxiang,

Thanks for your work.

Quoted 6 lines · Haoxiang Li

Add check for the return value of rcar_gen4_ptp_alloc() to prevent potential null pointer dereference.

Fixes b0d3969d2b4d ("net: ethernet: rtsn: Add support for Renesas Ethernet-TSN")
Quoted 28 lines

---
Changes in v2:
- Add a blank line to make the grouping similar to the style of other error checks in probe. Thanks, Niklas!

---
 drivers/net/ethernet/renesas/rtsn.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/ethernet/renesas/rtsn.c +5 -0
index 6b3f7fca8d15..05c4b6c8c9c3 100644
@@ -1259,7 +1259,12 @@ static int rtsn_probe(struct platform_device *pdev)
 	priv = netdev_priv(ndev);
 	priv->pdev = pdev;
 	priv->ndev = ndev;
+
 	priv->ptp_priv = rcar_gen4_ptp_alloc(pdev);
+	if (!priv->ptp_priv) {
+		ret = -ENOMEM;
+		goto error_free;
+	}
 
 	spin_lock_init(&priv->lock);
 	platform_set_drvdata(pdev, priv);
Signature · 1 line
2.25.1
Signature · 2 lines
Kind Regards,
Niklas Söderlund
#2 lore raw
In reply to Haoxiang Li
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, 3 Jul 2025 18:01:09 +0800 you wrote:

Add check for the return value of rcar_gen4_ptp_alloc() to prevent potential null pointer dereference.

Fixes b0d3969d2b4d ("net: ethernet: rtsn: Add support for Renesas Ethernet-TSN")

[...]

Here is the summary with links:
- [v2] net: ethernet: rtsn: Fix a null pointer dereference in rtsn_probe()

    https://git.kernel.org/netdev/net/c/95a234f6affb

You are awesome, thank you!

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