Skip to content

Commit 209bdb7

Browse files
vladimirolteankuba-moo
authored andcommitted
net: dsa: felix: don't use devres for mdiobus
As explained in commits: 74b6d7d ("net: dsa: realtek: register the MDIO bus under devres") 5135e96 ("net: dsa: don't allocate the slave_mii_bus using devres") mdiobus_free() will panic when called from devm_mdiobus_free() <- devres_release_all() <- __device_release_driver(), and that mdiobus was not previously unregistered. The Felix VSC9959 switch is a PCI device, so the initial set of constraints that I thought would cause this (I2C or SPI buses which call ->remove on ->shutdown) do not apply. But there is one more which applies here. If the DSA master itself is on a bus that calls ->remove from ->shutdown (like dpaa2-eth, which is on the fsl-mc bus), there is a device link between the switch and the DSA master, and device_links_unbind_consumers() will unbind the felix switch driver on shutdown. So the same treatment must be applied to all DSA switch drivers, which is: either use devres for both the mdiobus allocation and registration, or don't use devres at all. The felix driver has the code structure in place for orderly mdiobus removal, so just replace devm_mdiobus_alloc_size() with the non-devres variant, and add manual free where necessary, to ensure that we don't let devres free a still-registered bus. Fixes: ac3a68d ("net: phy: don't abuse devres in devm_mdiobus_register()") Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 08f1a20 commit 209bdb7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/net/dsa/ocelot/felix_vsc9959.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
10611061
return PTR_ERR(hw);
10621062
}
10631063

1064-
bus = devm_mdiobus_alloc_size(dev, sizeof(*mdio_priv));
1064+
bus = mdiobus_alloc_size(sizeof(*mdio_priv));
10651065
if (!bus)
10661066
return -ENOMEM;
10671067

@@ -1081,6 +1081,7 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
10811081
rc = mdiobus_register(bus);
10821082
if (rc < 0) {
10831083
dev_err(dev, "failed to register MDIO bus\n");
1084+
mdiobus_free(bus);
10841085
return rc;
10851086
}
10861087

@@ -1132,6 +1133,7 @@ static void vsc9959_mdio_bus_free(struct ocelot *ocelot)
11321133
lynx_pcs_destroy(phylink_pcs);
11331134
}
11341135
mdiobus_unregister(felix->imdio);
1136+
mdiobus_free(felix->imdio);
11351137
}
11361138

11371139
static void vsc9959_sched_speed_set(struct ocelot *ocelot, int port,

0 commit comments

Comments
 (0)