On Thu, May 19, 2022 at 05:31:01PM +0200, Clément Léger wrote: > +static int a5psw_pcs_get(struct a5psw *a5psw) > +{ > + struct device_node *ports, *port, *pcs_node; > + struct phylink_pcs *pcs; > + int ret; > + u32 reg; > + > + ports = of_get_child_by_name(a5psw->dev->of_node, "ethernet-ports"); > + if (!ports) > + return -EINVAL; > + > + for_each_available_child_of_node(ports, port) { > + pcs_node = of_parse_phandle(port, "pcs-handle", 0); > + if (!pcs_node) > + continue; > + > + if (of_property_read_u32(port, "reg", ®)) { > + ret = -EINVAL; > + goto free_pcs; I think when you exit the for_each_available_child_of_node() loop you need to manually call of_node_put(port). > + } > + > + if (reg >= ARRAY_SIZE(a5psw->pcs)) { > + ret = -ENODEV; > + goto free_pcs; > + } > + > + pcs = miic_create(pcs_node); > + if (IS_ERR(pcs)) { > + dev_err(a5psw->dev, "Failed to create PCS for port %d\n", > + reg); > + ret = PTR_ERR(pcs); > + goto free_pcs; > + } > + > + a5psw->pcs[reg] = pcs; > + } > + of_node_put(ports); > + > + return 0; > + > +free_pcs: > + a5psw_pcs_free(a5psw); > + of_node_put(ports); > + > + return ret; > +}