In rtpcs_probe_serdes_bus(), the code manages the device
tree node reference incorrectly:
- It acquires a node pointer np via of_find_compatible_node(),
which increments the reference count.
- It calls of_mdio_find_bus(np) to locate the bus.
- It calls of_node_put(np), which decrements the reference
count. If this was the last reference, the node is freed.
- It then attempts to check if (!of_device_is_available(np)).
The pointer np is used after its reference has been released.
This can lead to a kernel oops or unpredictable behavior if
the memory has been reclaimed.
Fixes: fe27cce1e ("realtek: add SerDes PCS driver")
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23391
Signed-off-by: Robert Marko <robimarko@gmail.com>
return ERR_PTR(-ENODEV);
}
+ if (!of_device_is_available(np)) {
+ dev_err(ctrl->dev, "SerDes mdio bus not usable");
+ of_node_put(np);
+ return ERR_PTR(-ENODEV);
+ }
+
bus = of_mdio_find_bus(np);
of_node_put(np);
if (!bus) {
return ERR_PTR(-EPROBE_DEFER);
}
- if (!of_device_is_available(np)) {
- dev_err(ctrl->dev, "SerDes mdio bus not usable");
- return ERR_PTR(-ENODEV);
- }
-
return bus;
}