Skip to content

Commit

Permalink
hv_netvsc: protect module refcount by checking net_device_ctx->vf_netdev
Browse files Browse the repository at this point in the history
We're not guaranteed to see NETDEV_REGISTER/NETDEV_UNREGISTER notifications
only once per VF but we increase/decrease module refcount unconditionally.
Check vf_netdev to make sure we don't take/release it twice. We presume
that only one VF per netvsc device may exist.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Acked-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Vitaly Kuznetsov authored and David S. Miller committed Aug 15, 2016
1 parent 57c1826 commit 0f20d79
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/net/hyperv/netvsc_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ static int netvsc_register_vf(struct net_device *vf_netdev)

net_device_ctx = netdev_priv(ndev);
netvsc_dev = net_device_ctx->nvdev;
if (netvsc_dev == NULL)
if (!netvsc_dev || net_device_ctx->vf_netdev)
return NOTIFY_DONE;

netdev_info(ndev, "VF registering: %s\n", vf_netdev->name);
Expand Down Expand Up @@ -1312,7 +1312,7 @@ static int netvsc_unregister_vf(struct net_device *vf_netdev)

net_device_ctx = netdev_priv(ndev);
netvsc_dev = net_device_ctx->nvdev;
if (netvsc_dev == NULL)
if (!netvsc_dev || !net_device_ctx->vf_netdev)
return NOTIFY_DONE;
netdev_info(ndev, "VF unregistering: %s\n", vf_netdev->name);
netvsc_inject_disable(net_device_ctx);
Expand Down

0 comments on commit 0f20d79

Please sign in to comment.