Skip to content

Commit 0152dfe

Browse files
Russell King (Oracle)kuba-moo
authored andcommitted
net: mvpp2: fix mvpp2 debugfs leak
When mvpp2 is unloaded, the driver specific debugfs directory is not removed, which technically leads to a memory leak. However, this directory is only created when the first device is probed, so the hardware is present. Removing the module is only something a developer would to when e.g. testing out changes, so the module would be reloaded. So this memory leak is minor. The original attempt in commit fe2c9c6 ("net: mvpp2: debugfs: fix memory leak when using debugfs_lookup()") that was labelled as a memory leak fix was not, it fixed a refcount leak, but in doing so created a problem when the module is reloaded - the directory already exists, but mvpp2_root is NULL, so we lose all debugfs entries. This fix has been reverted. This is the alternative fix, where we remove the offending directory whenever the driver is unloaded. Fixes: 21da57a ("net: mvpp2: add a debugfs interface for the Header Parser") Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Marcin Wojtas <mw@semihalf.com> Link: https://lore.kernel.org/r/E1ofOAB-00CzkG-UO@rmk-PC.armlinux.org.uk Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 93e2be3 commit 0152dfe

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

drivers/net/ethernet/marvell/mvpp2/mvpp2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,7 @@ u32 mvpp2_read(struct mvpp2 *priv, u32 offset);
15301530
void mvpp2_dbgfs_init(struct mvpp2 *priv, const char *name);
15311531

15321532
void mvpp2_dbgfs_cleanup(struct mvpp2 *priv);
1533+
void mvpp2_dbgfs_exit(void);
15331534

15341535
void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en);
15351536

drivers/net/ethernet/marvell/mvpp2/mvpp2_debugfs.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,13 @@ static int mvpp2_dbgfs_port_init(struct dentry *parent,
691691
return 0;
692692
}
693693

694+
static struct dentry *mvpp2_root;
695+
696+
void mvpp2_dbgfs_exit(void)
697+
{
698+
debugfs_remove(mvpp2_root);
699+
}
700+
694701
void mvpp2_dbgfs_cleanup(struct mvpp2 *priv)
695702
{
696703
debugfs_remove_recursive(priv->dbgfs_dir);
@@ -700,10 +707,9 @@ void mvpp2_dbgfs_cleanup(struct mvpp2 *priv)
700707

701708
void mvpp2_dbgfs_init(struct mvpp2 *priv, const char *name)
702709
{
703-
struct dentry *mvpp2_dir, *mvpp2_root;
710+
struct dentry *mvpp2_dir;
704711
int ret, i;
705712

706-
mvpp2_root = debugfs_lookup(MVPP2_DRIVER_NAME, NULL);
707713
if (!mvpp2_root)
708714
mvpp2_root = debugfs_create_dir(MVPP2_DRIVER_NAME, NULL);
709715

drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7706,7 +7706,18 @@ static struct platform_driver mvpp2_driver = {
77067706
},
77077707
};
77087708

7709-
module_platform_driver(mvpp2_driver);
7709+
static int __init mvpp2_driver_init(void)
7710+
{
7711+
return platform_driver_register(&mvpp2_driver);
7712+
}
7713+
module_init(mvpp2_driver_init);
7714+
7715+
static void __exit mvpp2_driver_exit(void)
7716+
{
7717+
platform_driver_unregister(&mvpp2_driver);
7718+
mvpp2_dbgfs_exit();
7719+
}
7720+
module_exit(mvpp2_driver_exit);
77107721

77117722
MODULE_DESCRIPTION("Marvell PPv2 Ethernet Driver - www.marvell.com");
77127723
MODULE_AUTHOR("Marcin Wojtas <mw@semihalf.com>");

0 commit comments

Comments
 (0)