All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v3] driver: dummy: Fix one possbile memleak when fail to register_netdevice
@ 2017-04-29  3:39 gfree.wind
  2017-05-01  2:53 ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: gfree.wind @ 2017-04-29  3:39 UTC (permalink / raw)
  To: davem, sd, phil, stephen, zhangshengju, netdev; +Cc: Gao Feng

From: Gao Feng <gfree.wind@foxmail.com>

The dummy driver allocates dev->dstats and priv->vfinfo in its
ndo_init func dummy_dev_init, free the dev->dstats in the ndo_uninit
and free the priv->vfinfo in its destructor func. Then there is one
memleak that some errors happen after register_netdevice invokes the
ndo_init callback. Because only the ndo_uninit callback is invoked in
the error handler of register_netdevice, but destructor not.

Now create one new func dummy_destructor_free to free the mem in the
destructor, and the ndo_uninit func also invokes it when fail to
register the dummy device.

It's not only free all resources, but also follow the original desgin
that the priv->vfinfo is freed in the destructor normally after
register the device successfully.

Signed-off-by: Gao Feng <gfree.wind@foxmail.com>
---
 v3: Split one patch to multiple commits, per David Ahern
 v2: Move the free in ndo_uninit when fail to register, per Herbert Xu
 v1: initial version

 drivers/net/dummy.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index 2c80611..0b3c1cc 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -153,9 +153,19 @@ static int dummy_dev_init(struct net_device *dev)
 	return 0;
 }
 
+static void dummy_destructor_free(struct net_device *dev)
+{
+	struct dummy_priv *priv = netdev_priv(dev);
+
+	kfree(priv->vfinfo);
+}
+
 static void dummy_dev_uninit(struct net_device *dev)
 {
 	free_percpu(dev->dstats);
+	/* dev is not registered, perform the free instead of destructor */
+	if (dev->reg_state == NETREG_UNINITIALIZED)
+		dummy_destructor_free(dev);
 }
 
 static int dummy_change_carrier(struct net_device *dev, bool new_carrier)
@@ -310,9 +320,7 @@ static const struct ethtool_ops dummy_ethtool_ops = {
 
 static void dummy_free_netdev(struct net_device *dev)
 {
-	struct dummy_priv *priv = netdev_priv(dev);
-
-	kfree(priv->vfinfo);
+	dummy_destructor_free(dev);
 	free_netdev(dev);
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net v3] driver: dummy: Fix one possbile memleak when fail to register_netdevice
  2017-04-29  3:39 [PATCH net v3] driver: dummy: Fix one possbile memleak when fail to register_netdevice gfree.wind
@ 2017-05-01  2:53 ` David Miller
  2017-05-02  2:15   ` Gao Feng
  0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2017-05-01  2:53 UTC (permalink / raw)
  To: gfree.wind; +Cc: sd, phil, stephen, zhangshengju, netdev


Please, Gao, submit this as a proper, numbered, patch series
with a proper header posting.

That way you can explain why you took this strategy to fix
this problem, compared to your original approach.

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH net v3] driver: dummy: Fix one possbile memleak when fail to register_netdevice
  2017-05-01  2:53 ` David Miller
@ 2017-05-02  2:15   ` Gao Feng
  0 siblings, 0 replies; 3+ messages in thread
From: Gao Feng @ 2017-05-02  2:15 UTC (permalink / raw)
  To: 'David Miller'; +Cc: sd, phil, stephen, zhangshengju, netdev

> From: David Miller [mailto:davem@davemloft.net]
> Sent: Monday, May 1, 2017 10:54 AM
> 
> Please, Gao, submit this as a proper, numbered, patch series with a proper
> header posting.
> 
> That way you can explain why you took this strategy to fix this problem,
> compared to your original approach.
> 
> Thanks.

OK, no problem.

Regards
Feng

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-05-02  2:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-29  3:39 [PATCH net v3] driver: dummy: Fix one possbile memleak when fail to register_netdevice gfree.wind
2017-05-01  2:53 ` David Miller
2017-05-02  2:15   ` Gao Feng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.