Re: [PATCH net] net: ethernet: ti: am65-cpsw: fix error handling in am65_cpsw_nuss_probe()

From: Maciej Fijalkowski
Date: Fri Nov 25 2022 - 09:36:26 EST


On Thu, Nov 24, 2022 at 11:03:08AM +0800, Zhang Changzhong wrote:
> The am65_cpsw_nuss_cleanup_ndev() function calls unregister_netdev()
> even if register_netdev() fails, which triggers WARN_ON(1) in

If this has been only compile tested then I assume you haven't encounter
this WARN_ON(1) trigger by yourself?

> unregister_netdevice_many(). To fix it, make sure that
> unregister_netdev() is called only on registered netdev.
>
> Compile tested only.
>
> Fixes: 84b4aa493249 ("net: ethernet: ti: am65-cpsw: add multi port support in mac-only mode")
> Signed-off-by: Zhang Changzhong <zhangchangzhong@xxxxxxxxxx>
> ---
> drivers/net/ethernet/ti/am65-cpsw-nuss.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> index c50b137..d04a239 100644
> --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> @@ -2082,7 +2082,7 @@ static void am65_cpsw_nuss_cleanup_ndev(struct am65_cpsw_common *common)
>
> for (i = 0; i < common->port_num; i++) {
> port = &common->ports[i];
> - if (port->ndev)
> + if (port->ndev && port->ndev->reg_state == NETREG_REGISTERED)
> unregister_netdev(port->ndev);

It seems that if am65_cpsw_nuss_register_ndevs() fails on
register_netdev() port->ndev is still a valid pointer, so your assumption
looks correct to me.

Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@xxxxxxxxx>

> }
> }
> --
> 2.9.5
>