1
0
Fork 0
forked from mirror/openwrt

realtek: mdio: harden mdio probing

Do better error checks during bus probing. Give meaningful return codes
in case of invalid DTS data (EINVAL instead of ENODEV). Decrease node
reference in case of errors.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/21968
Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
Markus Stockhausen 2026-02-10 17:16:48 +01:00 committed by Robert Marko
parent 64d72c7451
commit 45fa6e3175

View file

@ -913,18 +913,20 @@ static int rtmdio_probe(struct platform_device *pdev)
if (of_property_read_u32(dn, "reg", &addr))
continue;
if (addr >= ctrl->cfg->cpu_port) {
pr_err("%s: illegal port number %d\n", __func__, addr);
return -ENODEV;
if (addr < 0 || addr >= ctrl->cfg->cpu_port) {
dev_err(dev, "illegal port number %d\n", addr);
of_node_put(dn);
return -EINVAL;
}
of_property_read_u32(dn->parent, "reg", &ctrl->smi_bus[addr]);
if (of_property_read_u32(dn, "realtek,smi-address", &ctrl->smi_addr[addr]))
ctrl->smi_addr[addr] = addr;
if (ctrl->smi_bus[addr] >= RTMDIO_MAX_SMI_BUS) {
pr_err("%s: illegal SMI bus number %d\n", __func__, ctrl->smi_bus[addr]);
return -ENODEV;
if (ctrl->smi_bus[addr] < 0 || ctrl->smi_bus[addr] >= RTMDIO_MAX_SMI_BUS) {
dev_err(dev, "illegal SMI bus number %d\n", ctrl->smi_bus[addr]);
of_node_put(dn);
return -EINVAL;
}
if (of_device_is_compatible(dn, "ethernet-phy-ieee802.3-c45"))