Skip to contentSkip to conversation

net: fs_enet: fix platform info memory leak on remove

PATCH Applied Guangshuo Li 3 participants 4 messages Sep 16 – Sep 18

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

PATCH 1/1 net: fs_enet: fix platform info memory leak on remove

fs_enet_probe() allocates the platform information structure with kzalloc_obj() and stores it in fep->fpi.

The probe failure paths release this allocation with kfree(). However, after a successful probe, fs_enet_remove() tears down the network device without freeing fep->fpi, leaving the platform information structure allocated after driver removal.

Free fep->fpi before releasing the network device.

This issue was found by manual code inspection.

Fixes 976de6a8c304 ("fs_enet: Be an of_platform device when CONFIG_PPC_CPM_NEW_BINDING is set.")
---
 drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +1 -0
index d3c772ed5fc9..071e3f3de78c 100644
@@ -1007,6 +1007,7 @@ static void fs_enet_remove(struct platform_device *ofdev)
 	fep->ops->cleanup_data(ndev);
 	dev_set_drvdata(fep->dev, NULL);
 	phylink_destroy(fep->phylink);
+	kfree(fep->fpi);
 	free_netdev(ndev);
 }
 
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · Guangshuo Li

fs_enet_probe() allocates the platform information structure with kzalloc_obj() and stores it in fep->fpi.

The probe failure paths release this allocation with kfree(). However, after a successful probe, fs_enet_remove() tears down the network device without freeing fep->fpi, leaving the platform information structure allocated after driver removal.

Free fep->fpi before releasing the network device.

This issue was found by manual code inspection.

Fixes 976de6a8c304 ("fs_enet: Be an of_platform device when CONFIG_PPC_CPM_NEW_BINDING is set.")
---
 drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +0 -0
index d3c772ed5fc9..071e3f3de78c 100644

drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c static void fs_enet_remove(struct platform_device *ofdev) · line 1011

Quoted 5 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +1 -0
@@ -1007,6 +1007,7 @@ static void fs_enet_remove(struct platform_device *ofdev)
 	fep->ops->cleanup_data(ndev);
 	dev_set_drvdata(fep->dev, NULL);
 	phylink_destroy(fep->phylink);
+	kfree(fep->fpi);
 	free_netdev(ndev);
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Guangshuo Li
Quoted 8 lines · Guangshuo Li

fs_enet_probe() allocates the platform information structure with kzalloc_obj() and stores it in fep->fpi.

The probe failure paths release this allocation with kfree(). However, after a successful probe, fs_enet_remove() tears down the network device without freeing fep->fpi, leaving the platform information structure allocated after driver removal.

Quoted 7 lines

Free fep->fpi before releasing the network device.

This issue was found by manual code inspection.

Fixes 976de6a8c304 ("fs_enet: Be an of_platform device when CONFIG_PPC_CPM_NEW_BINDING is set.")
#3 lore raw
In reply to Guangshuo Li
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 9 lines · On Wed, 16 Sep 2026 11:14:14 +0800 you wrote:

fs_enet_probe() allocates the platform information structure with kzalloc_obj() and stores it in fep->fpi.

The probe failure paths release this allocation with kfree(). However, after a successful probe, fs_enet_remove() tears down the network device without freeing fep->fpi, leaving the platform information structure allocated after driver removal.

[...]

Here is the summary with links:
- net: fs_enet: fix platform info memory leak on remove

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

You are awesome, thank you!

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