Skip to contentSkip to conversation

net: dsa: qca8k: fix NULL pointer dereference for of_device_get_match_data

PATCH Applied Christian Marangi 3 participants 5 messages Sep 4, 2022 – Sep 6, 2022

Subsystems (4)
lore
Share & tools
lore

Christian Marangi

author maintainer
#0 lore raw

PATCH 1/1 net: dsa: qca8k: fix NULL pointer dereference for of_device_get_match_data

of_device_get_match_data is called on priv->dev before priv->dev is actually set. Move of_device_get_match_data after priv->dev is correctly set to fix this kernel panic.

Fixes 3bb0844e7bcd ("net: dsa: qca8k: cache match data to speed up access")
---
 drivers/net/dsa/qca/qca8k-8xxx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/qca/qca8k-8xxx.c +1 -1
index 1d3e7782a71f..c181346388a4 100644
@@ -1889,9 +1889,9 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
 	if (!priv)
 		return -ENOMEM;
 
-	priv->info = of_device_get_match_data(priv->dev);
 	priv->bus = mdiodev->bus;
 	priv->dev = &mdiodev->dev;
+	priv->info = of_device_get_match_data(priv->dev);
 
 	priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset",
 						   GPIOD_ASIS);
Signature · 1 line
2.37.2
maintainer
#1 lore raw
Quoted 7 lines · Christian Marangi

of_device_get_match_data is called on priv->dev before priv->dev is actually set. Move of_device_get_match_data after priv->dev is correctly set to fix this kernel panic.

Fixes 3bb0844e7bcd ("net: dsa: qca8k: cache match data to speed up access")

---

Did this ever work? Was it tested when you sent the big refactoring patch set?

author maintainer
#2 lore raw
Quoted 11 lines · Vladimir Oltean
Quoted 7 lines · Christian Marangi

of_device_get_match_data is called on priv->dev before priv->dev is actually set. Move of_device_get_match_data after priv->dev is correctly set to fix this kernel panic.

Fixes 3bb0844e7bcd ("net: dsa: qca8k: cache match data to speed up access")

---

Did this ever work? Was it tested when you sent the big refactoring patch set?

I have to be honest here. I feel really embarrassed about this. The short story is that the refactor was tested on Openwrt with 5.15 by manually applying the changes. This fix was applied there but I forgot to put it in the final series.

I notice this mistake only now that I'm backporting patches and the manually applied fix was reset.

Again I'm really sorry.

Signature · 1 line
	Ansuel
#4 lore raw
In reply to Christian Marangi
This patch was applied to netdev/net.git (master) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by Paolo Abeni <[email protected]>:

Quoted 8 lines · On Sun, 4 Sep 2022 23:53:19 +0200 you wrote:

of_device_get_match_data is called on priv->dev before priv->dev is actually set. Move of_device_get_match_data after priv->dev is correctly set to fix this kernel panic.

Fixes 3bb0844e7bcd ("net: dsa: qca8k: cache match data to speed up access")

[...]

Here is the summary with links:
- [net] net: dsa: qca8k: fix NULL pointer dereference for of_device_get_match_data

    https://git.kernel.org/netdev/net/c/42b998d4aa59

You are awesome, thank you!

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