Skip to contentSkip to conversation

pds_core: fix memory leak in pdsc_debugfs_add_qcq()

PATCH Applied Abdun Nihaal 4 participants 4 messages Apr 9, 2025 – Apr 12, 2025

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

PATCH 1/1 pds_core: fix memory leak in pdsc_debugfs_add_qcq()

The memory allocated for intr_ctrl_regset, which is passed to debugfs_create_regset32() may not be cleaned up when the driver is removed. Fix that by using device managed allocation for it.

Fixes 45d76f492938 ("pds_core: set up device and adminq")
---
 drivers/net/ethernet/amd/pds_core/debugfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/amd/pds_core/debugfs.c +3 -2
index ac37a4e738ae..04c5e3abd8d7 100644
@@ -154,8 +154,9 @@ void pdsc_debugfs_add_qcq(struct pdsc *pdsc, struct pdsc_qcq *qcq)
 		debugfs_create_u32("index", 0400, intr_dentry, &intr->index);
 		debugfs_create_u32("vector", 0400, intr_dentry, &intr->vector);
 
-		intr_ctrl_regset = kzalloc(sizeof(*intr_ctrl_regset),
-					   GFP_KERNEL);
+		intr_ctrl_regset = devm_kzalloc(pdsc->dev,
+						sizeof(*intr_ctrl_regset),
+						GFP_KERNEL);
 		if (!intr_ctrl_regset)
 			return;
 		intr_ctrl_regset->regs = intr_ctrl_regs;
Signature · 1 line
2.47.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Abdun Nihaal

The memory allocated for intr_ctrl_regset, which is passed to debugfs_create_regset32() may not be cleaned up when the driver is removed. Fix that by using device managed allocation for it.

Fixes 45d76f492938 ("pds_core: set up device and adminq")
---
 drivers/net/ethernet/amd/pds_core/debugfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/amd/pds_core/debugfs.c +0 -0
index ac37a4e738ae..04c5e3abd8d7 100644
@@ -154,8 +154,9 @@ void pdsc_debugfs_add_qcq(struct pdsc *pdsc, struct pdsc_qcq *qcq)
 		debugfs_create_u32("index", 0400, intr_dentry, &intr->index);

drivers/net/ethernet/amd/pds_core/debugfs.c void pdsc_debugfs_add_qcq(struct pdsc *pdsc, struct pdsc_qcq *qcq) · line 162

Quoted 10 lines
drivers/net/ethernet/amd/pds_core/debugfs.c +3 -2
 		debugfs_create_u32("vector", 0400, intr_dentry, &intr->vector);
 
-		intr_ctrl_regset = kzalloc(sizeof(*intr_ctrl_regset),
-					   GFP_KERNEL);
+		intr_ctrl_regset = devm_kzalloc(pdsc->dev,
+						sizeof(*intr_ctrl_regset),
+						GFP_KERNEL);
 		if (!intr_ctrl_regset)
 			return;
 		intr_ctrl_regset->regs = intr_ctrl_regs;

In ionic driver it is also devm_ version, thanks for catching that.

For future submission remember to set correct target (net instead of net-next as it is a fix)

Thanks,
Michal

Quoted 2 lines
Signature · 1 line
2.47.2
Reviewed-by on v1 1/1
#2 lore raw
In reply to Abdun Nihaal
Quoted 7 lines · Abdun Nihaal

The memory allocated for intr_ctrl_regset, which is passed to debugfs_create_regset32() may not be cleaned up when the driver is removed. Fix that by using device managed allocation for it.

Fixes 45d76f492938 ("pds_core: set up device and adminq")

Thanks!

Quoted 23 lines
---
  drivers/net/ethernet/amd/pds_core/debugfs.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/amd/pds_core/debugfs.c +3 -3
index ac37a4e738ae..04c5e3abd8d7 100644
@@ -154,8 +154,9 @@ void pdsc_debugfs_add_qcq(struct pdsc *pdsc, struct pdsc_qcq *qcq)
                 debugfs_create_u32("index", 0400, intr_dentry, &intr->index);
                 debugfs_create_u32("vector", 0400, intr_dentry, &intr->vector);
 
-               intr_ctrl_regset = kzalloc(sizeof(*intr_ctrl_regset),
-                                          GFP_KERNEL);
+               intr_ctrl_regset = devm_kzalloc(pdsc->dev,
+                                               sizeof(*intr_ctrl_regset),
+                                               GFP_KERNEL);
                 if (!intr_ctrl_regset)
                         return;
                 intr_ctrl_regset->regs = intr_ctrl_regs;
--

2.47.2

#3 lore raw
In reply to Abdun Nihaal
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 Wed, 9 Apr 2025 11:14:48 +0530 you wrote:

The memory allocated for intr_ctrl_regset, which is passed to debugfs_create_regset32() may not be cleaned up when the driver is removed. Fix that by using device managed allocation for it.

Fixes 45d76f492938 ("pds_core: set up device and adminq")

[...]

Here is the summary with links:
- [net-next] pds_core: fix memory leak in pdsc_debugfs_add_qcq()

    https://git.kernel.org/netdev/net/c/8b82f656826c

You are awesome, thank you!

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