Subject: Re: [PATCH] net: Fix spinlock use in alloc_netdev_mq()

From: Andrew Morton <[email-masked]>
Date: Wed, 5 Aug 2009 10:13:27 -0700

On Wed, 5 Aug 2009 10:47:47 +0200 Jiri Pirko <[email-masked]> wrote:

> >it's using an zero-initialized spinlock. This is a side-effect of:
> >
> >        dev_unicast_init(dev);
> >
> >in alloc_netdev_mq() making use of dev->addr_list_lock.
> >
> >The device has just been allocated freshly, it's not accessible
> >anywhere yet so no locking is needed at all - in fact it's wrong
> >to lock it here (the lock isnt initialized yet).
> 
> Yes this looks like the right approach. Sorry for this bug :(

Really?

> >--- a/net/core/dev.c
> >+++ b/net/core/dev.c
> >@@ -4007,9 +4007,7 @@ static void dev_unicast_flush(struct net_device *dev)
> > 
> > static void dev_unicast_init(struct net_device *dev)
> > {
> >-	netif_addr_lock_bh(dev);
> > 	__hw_addr_init(&dev->uc);
> >-	netif_addr_unlock_bh(dev);
> > }

This means that the net_device is still floating around for quite a
long time with an uninitialised spinlock, so it will be quite easy for
the same problem to reoccur as the code evolves.

It would be more robust were we to initialise that lock close to the
netdev's allocation site.