Skip to contentSkip to conversation

net: mvneta: bm: fix device reference leak on failed lookup

PATCH Applied Johan Hovold 3 participants 3 messages Jul 9 – Jul 21

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

PATCH 1/1 net: mvneta: bm: fix device reference leak on failed lookup

Make sure to drop the reference taken to the buffer manager device when attempting to look up its driver data before the driver has been bound.

Note that holding a reference to a device does not prevent its driver data from going away.

Fixes 965cbbec7f20 ("net: mvneta: remove data pointer usage from device_node structure")
Cc Gregory CLEMENT <[email protected]>
---
 drivers/net/ethernet/marvell/mvneta_bm.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/mvneta_bm.c +13 -2
index 6bb380494919..128fe1f512b4 100644
@@ -395,9 +395,20 @@ static void mvneta_bm_put_sram(struct mvneta_bm *priv)
 
 struct mvneta_bm *mvneta_bm_get(struct device_node *node)
 {
-	struct platform_device *pdev = of_find_device_by_node(node);
+	struct platform_device *pdev;
+	struct mvneta_bm *priv;
+
+	pdev = of_find_device_by_node(node);
+	if (!pdev)
+		return NULL;
+
+	priv = platform_get_drvdata(pdev);
+	if (!priv) {
+		platform_device_put(pdev);
+		return NULL;
+	}
 
-	return pdev ? platform_get_drvdata(pdev) : NULL;
+	return priv;
 }
 EXPORT_SYMBOL_GPL(mvneta_bm_get);
 
Signature · 1 line
2.54.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Johan Hovold

Make sure to drop the reference taken to the buffer manager device when attempting to look up its driver data before the driver has been bound.

Note that holding a reference to a device does not prevent its driver data from going away.

Fixes 965cbbec7f20 ("net: mvneta: remove data pointer usage from device_node structure")
Cc Gregory CLEMENT <[email protected]>

Okay, platform_device_put() has to be called directly instead of mvneta_bm_put() because that takes in the priv structure.

Quoted 35 lines
---
 drivers/net/ethernet/marvell/mvneta_bm.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/mvneta_bm.c +13 -3
index 6bb380494919..128fe1f512b4 100644
@@ -395,9 +395,20 @@ static void mvneta_bm_put_sram(struct mvneta_bm *priv)
 
 struct mvneta_bm *mvneta_bm_get(struct device_node *node)
 {
-       struct platform_device *pdev = of_find_device_by_node(node);
+       struct platform_device *pdev;
+       struct mvneta_bm *priv;
+
+       pdev = of_find_device_by_node(node);
+       if (!pdev)
+               return NULL;
+
+       priv = platform_get_drvdata(pdev);
+       if (!priv) {
+               platform_device_put(pdev);
+               return NULL;
+       }
 
-       return pdev ? platform_get_drvdata(pdev) : NULL;
+       return priv;
 }
 EXPORT_SYMBOL_GPL(mvneta_bm_get);
 
--

2.54.0

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

Hello:

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

Quoted 6 lines · On Thu, 9 Jul 2026 10:27:13 +0200 you wrote:

Make sure to drop the reference taken to the buffer manager device when attempting to look up its driver data before the driver has been bound.

Note that holding a reference to a device does not prevent its driver data from going away.

Quoted 6 lines
Fixes 965cbbec7f20 ("net: mvneta: remove data pointer usage from device_node structure")
Cc Gregory CLEMENT <[email protected]>

[...]

Here is the summary with links:
- net: mvneta: bm: fix device reference leak on failed lookup

    https://git.kernel.org/netdev/net-next/c/ede0f99cef53

You are awesome, thank you!

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