Skip to contentSkip to conversation

sh_eth: fix bitbang memory leak

PATCH In review Sergei Shtylyov 2 participants 4 messages Mar 19, 2013 – Mar 20, 2013

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

PATCH 1/2 sh_eth: fix bitbang memory leak

sh_mdio_init() allocates pointer to 'struct bb_info' but only stores it locally, so that sh_mdio_release() can't free it on driver unload. Add the pointer to 'struct bb_info' to 'struct sh_eth_private', so that sh_mdio_init() can save 'bitbang' variable for sh_mdio_release() to be able to free it later...

---
 drivers/net/ethernet/renesas/sh_eth.c |    5 +++++
 drivers/net/ethernet/renesas/sh_eth.h |    1 +
 2 files changed, 6 insertions(+)
drivers/net/ethernet/renesas/sh_eth.c +5 -0
Index: renesas/drivers/net/ethernet/renesas/sh_eth.c
===================================================================
@@ -2220,6 +2220,7 @@ static void sh_eth_tsu_init(struct sh_et
 /* MDIO bus release function */
 static int sh_mdio_release(struct net_device *ndev)
 {
+	struct sh_eth_private *mdp = netdev_priv(ndev);
 	struct mii_bus *bus = dev_get_drvdata(&ndev->dev);
 
 	/* unregister mdio bus */
@@ -2234,6 +2235,9 @@ static int sh_mdio_release(struct net_de
 	/* free bitbang info */
 	free_mdio_bitbang(bus);
 
+	/* free bitbang memory */
+	kfree(mdp->bitbang);
+
 	return 0;
 }
 
@@ -2262,6 +2266,7 @@ static int sh_mdio_init(struct net_devic
 	bitbang->ctrl.ops = &bb_ops;
 
 	/* MII controller setting */
+	mdp->bitbang = bitbang;
 	mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl);
 	if (!mdp->mii_bus) {
 		ret = -ENOMEM;
drivers/net/ethernet/renesas/sh_eth.h +1 -0
Index: renesas/drivers/net/ethernet/renesas/sh_eth.h
===================================================================
@@ -705,6 +705,7 @@ struct sh_eth_private {
 	const u16 *reg_offset;
 	void __iomem *addr;
 	void __iomem *tsu_addr;
+	struct bb_info *bitbang;
 	u32 num_rx_ring;
 	u32 num_tx_ring;
 	dma_addr_t rx_desc_dma;
#1 lore raw

Hello.

Quoted 6 lines · Sergei Shtylyov

sh_mdio_init() allocates pointer to 'struct bb_info' but only stores it locally, so that sh_mdio_release() can't free it on driver unload. Add the pointer to 'struct bb_info' to 'struct sh_eth_private', so that sh_mdio_init() can save 'bitbang' variable for sh_mdio_release() to be able to free it later...

I was in a bit of hurry and forgot to add:

Do I need to repost?

WBR, Sergei

maintainer
#2 lore raw
In reply to Sergei Shtylyov

From: Sergei Shtylyov <[email protected]>
Date: Wed, 20 Mar 2013 02:40:23 +0300

Quoted 6 lines

sh_mdio_init() allocates pointer to 'struct bb_info' but only stores it locally, so that sh_mdio_release() can't free it on driver unload. Add the pointer to 'struct bb_info' to 'struct sh_eth_private', so that sh_mdio_init() can save 'bitbang' variable for sh_mdio_release() to be able to free it later...

Applied and queued up for -stable.

#3 lore raw

Hello.

Quoted 8 lines · David Miller
Quoted 7 lines

sh_mdio_init() allocates pointer to 'struct bb_info' but only stores it locally, so that sh_mdio_release() can't free it on driver unload. Add the pointer to 'struct bb_info' to 'struct sh_eth_private', so that sh_mdio_init() can save 'bitbang' variable for sh_mdio_release() to be able to free it later...

Applied and queued up for -stable.

Thank you for the quick reaction! :-)

WBR, Sergei