Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dsa: qca8k: assign ds->user_mii_bus only for the non-OF case

To simplify reasoning about why the DSA framework provides the
ds->user_mii_bus functionality, drivers should only use it if they
need to. The qca8k driver appears to also use it simply as storage
for a pointer, which is not a good enough reason to make the core
much more difficult to follow.

ds->user_mii_bus is useful for only 2 cases:

1. The driver probes on platform_data (no OF)
2. The driver probes on OF, but there is no OF node for the MDIO bus.

It is unclear if case (1) is supported with qca8k. It might not be:
the driver might crash when of_device_get_match_data() returns NULL
and then it dereferences priv->info without NULL checking.

Anyway, let us limit the ds->user_mii_bus usage only to the above cases,
and not assign it when an OF node is present.

The bus->phy_mask assignment follows along with the movement, because
__of_mdiobus_register() overwrites this bus field anyway. The value set
by the driver only matters for the non-OF code path.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Alvin Šipraga <alsi@bang-olufsen.dk>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Reviewed-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Vladimir Oltean and committed by
David S. Miller
525366b8 e66bf63a

+6 -4
+3 -2
drivers/net/dsa/qca/qca8k-8xxx.c
··· 961 961 goto out_put_node; 962 962 } 963 963 964 + priv->internal_mdio_bus = bus; 964 965 bus->priv = (void *)priv; 965 966 snprintf(bus->id, MII_BUS_ID_SIZE, "qca8k-%d.%d", 966 967 ds->dst->index, ds->index); 967 968 bus->parent = ds->dev; 968 - bus->phy_mask = ~ds->phys_mii_mask; 969 - ds->user_mii_bus = bus; 970 969 971 970 /* Check if the devicetree declare the port:phy mapping */ 972 971 if (mdio) { ··· 979 980 /* If a mapping can't be found the legacy mapping is used, 980 981 * using the qca8k_port_to_phy function 981 982 */ 983 + ds->user_mii_bus = bus; 984 + bus->phy_mask = ~ds->phys_mii_mask; 982 985 bus->name = "qca8k-legacy user mii"; 983 986 bus->read = qca8k_legacy_mdio_read; 984 987 bus->write = qca8k_legacy_mdio_write;
+2 -2
drivers/net/dsa/qca/qca8k-leds.c
··· 366 366 { 367 367 struct fwnode_handle *led = NULL, *leds = NULL; 368 368 struct led_init_data init_data = { }; 369 - struct dsa_switch *ds = priv->ds; 370 369 enum led_default_state state; 371 370 struct qca8k_led *port_led; 372 371 int led_num, led_index; ··· 428 429 init_data.default_label = ":port"; 429 430 init_data.fwnode = led; 430 431 init_data.devname_mandatory = true; 431 - init_data.devicename = kasprintf(GFP_KERNEL, "%s:0%d", ds->user_mii_bus->id, 432 + init_data.devicename = kasprintf(GFP_KERNEL, "%s:0%d", 433 + priv->internal_mdio_bus->id, 432 434 port_num); 433 435 if (!init_data.devicename) 434 436 return -ENOMEM;
+1
drivers/net/dsa/qca/qca8k.h
··· 454 454 struct qca8k_ports_config ports_config; 455 455 struct regmap *regmap; 456 456 struct mii_bus *bus; 457 + struct mii_bus *internal_mdio_bus; 457 458 struct dsa_switch *ds; 458 459 struct mutex reg_mutex; 459 460 struct device *dev;