Skip to content

Commit 126d684

Browse files
Russell Kingdavem330
authored andcommitted
sfp: fix oops with ethtool -m
If a network interface is created prior to the SFP socket being available, ethtool can request module information. This unfortunately leads to an oops: Unable to handle kernel NULL pointer dereference at virtual address 00000008 pgd = (ptrval) [00000008] *pgd=7c400831, *pte=00000000, *ppte=00000000 Internal error: Oops: 17 [#1] SMP ARM Modules linked in: CPU: 0 PID: 1480 Comm: ethtool Not tainted 4.19.0-rc3 torvalds#138 Hardware name: Broadcom Northstar Plus SoC PC is at sfp_get_module_info+0x8/0x10 LR is at dev_ethtool+0x218c/0x2afc Fix this by not filling in the network device's SFP bus pointer until SFP is fully bound, thereby avoiding the core calling into the SFP bus code. Fixes: ce0aa27 ("sfp: add sfp-bus to bridge between network devices and sfp cages") Reported-by: Florian Fainelli <f.fainelli@gmail.com> Tested-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 774268f commit 126d684

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/net/phy/sfp-bus.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ static int sfp_register_bus(struct sfp_bus *bus)
349349
}
350350
if (bus->started)
351351
bus->socket_ops->start(bus->sfp);
352+
bus->netdev->sfp_bus = bus;
352353
bus->registered = true;
353354
return 0;
354355
}
@@ -357,6 +358,7 @@ static void sfp_unregister_bus(struct sfp_bus *bus)
357358
{
358359
const struct sfp_upstream_ops *ops = bus->upstream_ops;
359360

361+
bus->netdev->sfp_bus = NULL;
360362
if (bus->registered) {
361363
if (bus->started)
362364
bus->socket_ops->stop(bus->sfp);
@@ -438,7 +440,6 @@ static void sfp_upstream_clear(struct sfp_bus *bus)
438440
{
439441
bus->upstream_ops = NULL;
440442
bus->upstream = NULL;
441-
bus->netdev->sfp_bus = NULL;
442443
bus->netdev = NULL;
443444
}
444445

@@ -467,7 +468,6 @@ struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode,
467468
bus->upstream_ops = ops;
468469
bus->upstream = upstream;
469470
bus->netdev = ndev;
470-
ndev->sfp_bus = bus;
471471

472472
if (bus->sfp) {
473473
ret = sfp_register_bus(bus);

0 commit comments

Comments
 (0)