[PATCH net-next v6 4/7] net: stmmac: introduce pcs_init/pcs_exit stmmac operations

Simon Horman horms at kernel.org
Sat May 11 11:11:19 PDT 2024


On Fri, May 10, 2024 at 09:38:11AM +0200, Romain Gantois wrote:
> From: "Russell King (Oracle)" <rmk+kernel at armlinux.org.uk>
> 
> Introduce a mechanism whereby platforms can create their PCS instances
> prior to the network device being published to userspace, but after
> some of the core stmmac initialisation has been completed. This means
> that the data structures that platforms need will be available.
> 
> Signed-off-by: Russell King (Oracle) <rmk+kernel at armlinux.org.uk>
> Reviewed-by: Maxime Chevallier <maxime.chevallier at bootlin.com>
> Reviewed-by: Serge Semin <fancer.lancer at gmail.com>
> Co-developed-by: Romain Gantois <romain.gantois at bootlin.com>
> Signed-off-by: Romain Gantois <romain.gantois at bootlin.com>
> ---
>  drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 8 +++++++-
>  include/linux/stmmac.h                            | 2 ++
>  2 files changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> index 778d79cdb2e6d..f562c563aab55 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> @@ -505,7 +505,10 @@ int stmmac_pcs_setup(struct net_device *ndev)
>  	priv = netdev_priv(ndev);
>  	mode = priv->plat->phy_interface;
>  
> -	if (priv->plat->mdio_bus_data && priv->plat->mdio_bus_data->has_xpcs) {
> +	if (priv->plat->pcs_init) {
> +		ret = priv->plat->pcs_init(priv);
> +	} else if (priv->plat->mdio_bus_data &&
> +		   priv->plat->mdio_bus_data->has_xpcs) {
>  		/* Try to probe the XPCS by scanning all addresses */
>  		for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
>  			xpcs = xpcs_create_mdiodev(priv->mii, addr, mode);

I am unsure if this can occur, but if priv->plat->pcs_init returns 0 then
xpcs will be used while uninitialised towards the end of this function.

Flagged by Smatch.

...



More information about the linux-arm-kernel mailing list