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:
parent
64d72c7451
commit
45fa6e3175
@ -913,18 +913,20 @@ static int rtmdio_probe(struct platform_device *pdev)
|
|||||||
if (of_property_read_u32(dn, "reg", &addr))
|
if (of_property_read_u32(dn, "reg", &addr))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (addr >= ctrl->cfg->cpu_port) {
|
if (addr < 0 || addr >= ctrl->cfg->cpu_port) {
|
||||||
pr_err("%s: illegal port number %d\n", __func__, addr);
|
dev_err(dev, "illegal port number %d\n", addr);
|
||||||
return -ENODEV;
|
of_node_put(dn);
|
||||||
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
of_property_read_u32(dn->parent, "reg", &ctrl->smi_bus[addr]);
|
of_property_read_u32(dn->parent, "reg", &ctrl->smi_bus[addr]);
|
||||||
if (of_property_read_u32(dn, "realtek,smi-address", &ctrl->smi_addr[addr]))
|
if (of_property_read_u32(dn, "realtek,smi-address", &ctrl->smi_addr[addr]))
|
||||||
ctrl->smi_addr[addr] = addr;
|
ctrl->smi_addr[addr] = addr;
|
||||||
|
|
||||||
if (ctrl->smi_bus[addr] >= RTMDIO_MAX_SMI_BUS) {
|
if (ctrl->smi_bus[addr] < 0 || ctrl->smi_bus[addr] >= RTMDIO_MAX_SMI_BUS) {
|
||||||
pr_err("%s: illegal SMI bus number %d\n", __func__, ctrl->smi_bus[addr]);
|
dev_err(dev, "illegal SMI bus number %d\n", ctrl->smi_bus[addr]);
|
||||||
return -ENODEV;
|
of_node_put(dn);
|
||||||
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (of_device_is_compatible(dn, "ethernet-phy-ieee802.3-c45"))
|
if (of_device_is_compatible(dn, "ethernet-phy-ieee802.3-c45"))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user