driver: macvtap: Unregister netdev rx_handler if macvtap_newlink fails
authorGao Feng <fgao@ikuai8.com>
Fri, 25 Nov 2016 02:05:06 +0000 (10:05 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Nov 2016 01:04:28 +0000 (20:04 -0500)
The macvtap_newlink registers the netdev rx_handler firstly, but it
does not unregister the handler if macvlan_common_newlink failed.

Signed-off-by: Gao Feng <fgao@ikuai8.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/macvtap.c

index 070e3290aa6efea6fcb505cdf0860a4dce676b74..bceca28757717cae65cc5004a829f8462404dad0 100644 (file)
@@ -491,7 +491,13 @@ static int macvtap_newlink(struct net *src_net,
        /* Don't put anything that may fail after macvlan_common_newlink
         * because we can't undo what it does.
         */
-       return macvlan_common_newlink(src_net, dev, tb, data);
+       err = macvlan_common_newlink(src_net, dev, tb, data);
+       if (err) {
+               netdev_rx_handler_unregister(dev);
+               return err;
+       }
+
+       return 0;
 }
 
 static void macvtap_dellink(struct net_device *dev,