int ksz_switch_register(struct ksz_device *dev)
 {
        const struct ksz_chip_data *info;
-       struct device_node *port, *ports;
+       struct device_node *ports;
        phy_interface_t interface;
        unsigned int port_num;
        int ret;
                if (!ports)
                        ports = of_get_child_by_name(dev->dev->of_node, "ports");
                if (ports) {
-                       for_each_available_child_of_node(ports, port) {
+                       for_each_available_child_of_node_scoped(ports, port) {
                                if (of_property_read_u32(port, "reg",
                                                         &port_num))
                                        continue;
                                if (!(dev->port_mask & BIT(port_num))) {
-                                       of_node_put(port);
                                        of_node_put(ports);
                                        return -EINVAL;
                                }