Skip to content

Commit 680811c

Browse files
etantilovanguy11
authored andcommitted
idpf: check error for register_netdev() on init
Current init logic ignores the error code from register_netdev(), which will cause WARN_ON() on attempt to unregister it, if there was one, and there is no info for the user that the creation of the netdev failed. WARNING: CPU: 89 PID: 6902 at net/core/dev.c:11512 unregister_netdevice_many_notify+0x211/0x1a10 ... [ 3707.563641] unregister_netdev+0x1c/0x30 [ 3707.563656] idpf_vport_dealloc+0x5cf/0xce0 [idpf] [ 3707.563684] idpf_deinit_task+0xef/0x160 [idpf] [ 3707.563712] idpf_vc_core_deinit+0x84/0x320 [idpf] [ 3707.563739] idpf_remove+0xbf/0x780 [idpf] [ 3707.563769] pci_device_remove+0xab/0x1e0 [ 3707.563786] device_release_driver_internal+0x371/0x530 [ 3707.563803] driver_detach+0xbf/0x180 [ 3707.563816] bus_remove_driver+0x11b/0x2a0 [ 3707.563829] pci_unregister_driver+0x2a/0x250 Introduce an error check and log the vport number and error code. On removal make sure to check VPORT_REG_NETDEV flag prior to calling unregister and free on the netdev. Add local variables for idx, vport_config and netdev for readability. Fixes: 0fe4546 ("idpf: add create vport and netdev configuration") Suggested-by: Tony Nguyen <[email protected]> Signed-off-by: Emil Tantilov <[email protected]> Reviewed-by: Simon Horman <[email protected]> Tested-by: Samuel Salin <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 1388dd5 commit 680811c

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

drivers/net/ethernet/intel/idpf/idpf_lib.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -927,15 +927,19 @@ static int idpf_stop(struct net_device *netdev)
927927
static void idpf_decfg_netdev(struct idpf_vport *vport)
928928
{
929929
struct idpf_adapter *adapter = vport->adapter;
930+
u16 idx = vport->idx;
930931

931932
kfree(vport->rx_ptype_lkup);
932933
vport->rx_ptype_lkup = NULL;
933934

934-
unregister_netdev(vport->netdev);
935-
free_netdev(vport->netdev);
935+
if (test_and_clear_bit(IDPF_VPORT_REG_NETDEV,
936+
adapter->vport_config[idx]->flags)) {
937+
unregister_netdev(vport->netdev);
938+
free_netdev(vport->netdev);
939+
}
936940
vport->netdev = NULL;
937941

938-
adapter->netdevs[vport->idx] = NULL;
942+
adapter->netdevs[idx] = NULL;
939943
}
940944

941945
/**
@@ -1536,13 +1540,22 @@ void idpf_init_task(struct work_struct *work)
15361540
}
15371541

15381542
for (index = 0; index < adapter->max_vports; index++) {
1539-
if (adapter->netdevs[index] &&
1540-
!test_bit(IDPF_VPORT_REG_NETDEV,
1541-
adapter->vport_config[index]->flags)) {
1542-
register_netdev(adapter->netdevs[index]);
1543-
set_bit(IDPF_VPORT_REG_NETDEV,
1544-
adapter->vport_config[index]->flags);
1543+
struct net_device *netdev = adapter->netdevs[index];
1544+
struct idpf_vport_config *vport_config;
1545+
1546+
vport_config = adapter->vport_config[index];
1547+
1548+
if (!netdev ||
1549+
test_bit(IDPF_VPORT_REG_NETDEV, vport_config->flags))
1550+
continue;
1551+
1552+
err = register_netdev(netdev);
1553+
if (err) {
1554+
dev_err(&pdev->dev, "failed to register netdev for vport %d: %pe\n",
1555+
index, ERR_PTR(err));
1556+
continue;
15451557
}
1558+
set_bit(IDPF_VPORT_REG_NETDEV, vport_config->flags);
15461559
}
15471560

15481561
/* As all the required vports are created, clear the reset flag

0 commit comments

Comments
 (0)