]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: mdio: realtek-rtl9300: harden otto_emdio_probe_one()
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Wed, 3 Jun 2026 17:59:20 +0000 (19:59 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sat, 6 Jun 2026 01:38:55 +0000 (18:38 -0700)
The bus probing of the MDIO driver uses a two stage approach.

1. The device tree "ethernet-ports" node is scanned to build a mapping
   between ports and PHYs.

2. The children of the device tree "controller" are scanned to create
   the individual MDIO buses.

The first step already checks the consistency of the PHY and bus nodes
that are linked via the ports. But it might miss a dangling bus child
node that is not linked. Step two simply iterates over all bus child
nodes and might read malformed data from nodes not checked in step one.

Harden this and return a meaningful error message.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://patch.msgid.link/20260603175924.123019-4-markus.stockhausen@gmx.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/mdio/mdio-realtek-rtl9300.c

index ba4151fbae0d4a6f5467e7e499c6e83bea113952..aa45b0e922165d14d56cd4e2bb9b8415bcdcad80 100644 (file)
@@ -380,7 +380,11 @@ static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv
 
        err = fwnode_property_read_u32(node, "reg", &mdio_bus);
        if (err)
-               return err;
+               return dev_err_probe(dev, err, "undefined smi bus number\n");
+
+       if (mdio_bus >= priv->info->num_buses)
+               return dev_err_probe(dev, -EINVAL,
+                                    "illegal (dangling) smi bus number %d\n", mdio_bus);
 
        /* The MDIO accesses from the kernel work with the PHY polling unit in
         * the switch. We need to tell the PPU to operate either in GPHY (i.e.