[...] > > > > I guess you can use devm_kcalloc() and get rid of kfree() here. > > > > I forgot to answer to this in the previous revision. No devm can't be > used there available_pcs is just an array allocated for phylink_config. > > Phylink then copy the data in it and doesn't use it anymore hence it > just needs to be allocated here and doesn't need to stay till the driver > gets removed. I guess this is exactly the point. Since available_pcs is used just here and this is not a hot-path, I think the code would be simpler, but I do not have a strong opinion about it. > > > > + if (!available_pcs) > > > + return -ENOMEM; > > > + > > > + err = fwnode_phylink_pcs_parse(dev_fwnode(&dev->dev), available_pcs, > > > + &num_pcs); > > > + if (err) > > > + goto out; > > > + > > > + port->phylink_config.available_pcs = available_pcs; > > > + port->phylink_config.num_available_pcs = num_pcs; > > > + > > > + __set_bit(PHY_INTERFACE_MODE_SGMII, > > > + port->phylink_config.supported_interfaces); > > > + __set_bit(PHY_INTERFACE_MODE_1000BASEX, > > > + port->phylink_config.supported_interfaces); > > > + __set_bit(PHY_INTERFACE_MODE_2500BASEX, > > > + port->phylink_config.supported_interfaces); > > > + __set_bit(PHY_INTERFACE_MODE_USXGMII, > > > + port->phylink_config.supported_interfaces); > > > + > > > + phy_interface_copy(port->phylink_config.pcs_interfaces, > > > + port->phylink_config.supported_interfaces); > > > + > > > + phylink = phylink_create(&port->phylink_config, > > > + of_fwnode_handle(np), > > > + phy_mode, &airoha_phylink_ops); > > > + if (IS_ERR(phylink)) { > > > + err = PTR_ERR(phylink); > > > + goto out; > > > + } > > > + > > > + port->phylink = phylink; > > > +out: > > > + kfree(available_pcs); > > > + > > > + return err; > > > +} > > > + > > > static int airoha_alloc_gdm_port(struct airoha_eth *eth, > > > struct device_node *np, int index) > > > { > > > @@ -2873,7 +3004,23 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth, > > > if (err) > > > return err; > > > > > > - return register_netdev(dev); > > > + if (airhoa_is_phy_external(port)) { > > > + err = airoha_setup_phylink(dev); > > > > This will re-introduce the issue reported here: > > https://lore.kernel.org/netdev/5c94b9b3850f7f29ed653e2205325620df28c3ff.1746715755.git.christophe.jaillet@wanadoo.fr/ > > > > I'm confused about this. The suggestion wasn't that register_netdev > might fail and I need to destroy phylink? Or the linked patch was merged > and I need to rebase on top of net-next? what I mean here is if register_netdev() or airoha_setup_phylink() fails, we should free metadata_dst running airoha_metadata_dst_free() as pointed out by Christophe. I think this path depends on Christophe's one. Regards, Lorenzo > > I didn't include that change to not cause conflicts but once it's merged > I will rebase and include that fix. > > > > + if (err) > > > + return err; > > > + } > > > + > > > + err = register_netdev(dev); > > > + if (err) > > > + goto free_phylink; > > > + > > > + return 0; > > > + > > > +free_phylink: > > > + if (airhoa_is_phy_external(port)) > > > + phylink_destroy(port->phylink); > > > + > > > + return err; > > > } > > > > > > static int airoha_probe(struct platform_device *pdev) > > > @@ -2967,6 +3114,9 @@ static int airoha_probe(struct platform_device *pdev) > > > struct airoha_gdm_port *port = eth->ports[i]; > > > > > > if (port && port->dev->reg_state == NETREG_REGISTERED) { > > > + if (airhoa_is_phy_external(port)) > > > + phylink_destroy(port->phylink); > > > + > > > unregister_netdev(port->dev); > > > airoha_metadata_dst_free(port); > > > } > > > @@ -2994,6 +3144,9 @@ static void airoha_remove(struct platform_device *pdev) > > > continue; > > > > > > airoha_dev_stop(port->dev); > > > + if (airhoa_is_phy_external(port)) > > > + phylink_destroy(port->phylink); > > > + > > > unregister_netdev(port->dev); > > > airoha_metadata_dst_free(port); > > > } > > > diff --git a/drivers/net/ethernet/airoha/airoha_eth.h b/drivers/net/ethernet/airoha/airoha_eth.h > > > index 53f39083a8b0..73a500474076 100644 > > > --- a/drivers/net/ethernet/airoha/airoha_eth.h > > > +++ b/drivers/net/ethernet/airoha/airoha_eth.h > > > @@ -498,6 +498,9 @@ struct airoha_gdm_port { > > > struct net_device *dev; > > > int id; > > > > > > + struct phylink *phylink; > > > + struct phylink_config phylink_config; > > > + > > > struct airoha_hw_stats stats; > > > > > > DECLARE_BITMAP(qos_sq_bmap, AIROHA_NUM_QOS_CHANNELS); > > > diff --git a/drivers/net/ethernet/airoha/airoha_regs.h b/drivers/net/ethernet/airoha/airoha_regs.h > > > index d931530fc96f..54f7079b28b0 100644 > > > --- a/drivers/net/ethernet/airoha/airoha_regs.h > > > +++ b/drivers/net/ethernet/airoha/airoha_regs.h > > > @@ -357,6 +357,18 @@ > > > #define IP_FRAGMENT_PORT_MASK GENMASK(8, 5) > > > #define IP_FRAGMENT_NBQ_MASK GENMASK(4, 0) > > > > > > +#define REG_GDMA4_TMBI_FRAG 0x2028 > > > +#define GDMA4_SGMII1_TX_WEIGHT_MASK GENMASK(31, 26) > > > +#define GDMA4_SGMII1_TX_FRAG_SIZE_MASK GENMASK(25, 16) > > > +#define GDMA4_SGMII0_TX_WEIGHT_MASK GENMASK(15, 10) > > > +#define GDMA4_SGMII0_TX_FRAG_SIZE_MASK GENMASK(9, 0) > > > + > > > +#define REG_GDMA4_RMBI_FRAG 0x202c > > > +#define GDMA4_SGMII1_RX_WEIGHT_MASK GENMASK(31, 26) > > > +#define GDMA4_SGMII1_RX_FRAG_SIZE_MASK GENMASK(25, 16) > > > +#define GDMA4_SGMII0_RX_WEIGHT_MASK GENMASK(15, 10) > > > +#define GDMA4_SGMII0_RX_FRAG_SIZE_MASK GENMASK(9, 0) > > > + > > > #define REG_MC_VLAN_EN 0x2100 > > > #define MC_VLAN_EN_MASK BIT(0) > > > > > > -- > > > 2.48.1 > > > > > > > -- > Ansuel