]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
netpoll info leak
authorStephen Hemminger <shemminger@osdl.org>
Thu, 26 Oct 2006 22:46:50 +0000 (15:46 -0700)
committerDavid S. Miller <davem@sunset.davemloft.net>
Sun, 3 Dec 2006 05:22:32 +0000 (21:22 -0800)
After looking harder, Steve noticed that the netpoll
beast leaked a little every time it shutdown for a nap.
Not a big leak, but a nuisance kind of thing.

He took out his refcount duct tape and patched the
leak. It was overkill since there was already other
locking in that area, but it looked clean and wouldn't
attract fleas.

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
include/linux/netpoll.h
net/core/netpoll.c

index 1efe60c5c00c3dd5c57924707206afcf49ef2dc5..39845fc975f994b1c6b1c4c8b3065911d093b20e 100644 (file)
@@ -25,6 +25,7 @@ struct netpoll {
 };
 
 struct netpoll_info {
+       atomic_t refcnt;
        spinlock_t poll_lock;
        int poll_owner;
        int tries;
index 4de62f1f41340e33901dd4ea52e571a9e0604677..c66df2f45d268e3a477cd2d4c0b5450dde92423d 100644 (file)
@@ -658,8 +658,11 @@ int netpoll_setup(struct netpoll *np)
                npinfo->tries = MAX_RETRIES;
                spin_lock_init(&npinfo->rx_lock);
                skb_queue_head_init(&npinfo->arp_tx);
-       } else
+               atomic_set(&npinfo->refcnt, 1);
+       } else {
                npinfo = ndev->npinfo;
+               atomic_inc(&npinfo->refcnt);
+       }
 
        if (!ndev->poll_controller) {
                printk(KERN_ERR "%s: %s doesn't support polling, aborting.\n",
@@ -766,12 +769,22 @@ void netpoll_cleanup(struct netpoll *np)
 
        if (np->dev) {
                npinfo = np->dev->npinfo;
-               if (npinfo && npinfo->rx_np == np) {
-                       spin_lock_irqsave(&npinfo->rx_lock, flags);
-                       npinfo->rx_np = NULL;
-                       npinfo->rx_flags &= ~NETPOLL_RX_ENABLED;
-                       spin_unlock_irqrestore(&npinfo->rx_lock, flags);
+               if (npinfo) {
+                       if (npinfo->rx_np == np) {
+                               spin_lock_irqsave(&npinfo->rx_lock, flags);
+                               npinfo->rx_np = NULL;
+                               npinfo->rx_flags &= ~NETPOLL_RX_ENABLED;
+                               spin_unlock_irqrestore(&npinfo->rx_lock, flags);
+                       }
+
+                       np->dev->npinfo = NULL;
+                       if (atomic_dec_and_test(&npinfo->refcnt)) {
+                               skb_queue_purge(&npinfo->arp_tx);
+
+                               kfree(npinfo);
+                       }
                }
+
                dev_put(np->dev);
        }