diff mbox series

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

Message ID 1669258989-18277-1-git-send-email-zhangchangzhong@huawei.com (mailing list archive)
State Accepted
Commit 46fb6512538d201d9a5b2bd7138b6751c37fdf0b
Delegated to: Netdev Maintainers
Headers show
Series [net] net: ethernet: ti: am65-cpsw: fix error handling in am65_cpsw_nuss_probe() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 1 maintainers not CCed: s-vadapalli@ti.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Zhang Changzhong Nov. 24, 2022, 3:03 a.m. UTC
The am65_cpsw_nuss_cleanup_ndev() function calls unregister_netdev()
even if register_netdev() fails, which triggers WARN_ON(1) in
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@huawei.com>
---
 drivers/net/ethernet/ti/am65-cpsw-nuss.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Maciej Fijalkowski Nov. 25, 2022, 2:36 p.m. UTC | #1
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@huawei.com>
> ---
>  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@intel.com>

>  	}
>  }
> -- 
> 2.9.5
>
patchwork-bot+netdevbpf@kernel.org Nov. 28, 2022, 11:10 a.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Thu, 24 Nov 2022 11:03:08 +0800 you wrote:
> The am65_cpsw_nuss_cleanup_ndev() function calls unregister_netdev()
> even if register_netdev() fails, which triggers WARN_ON(1) in
> unregister_netdevice_many(). To fix it, make sure that
> unregister_netdev() is called only on registered netdev.
> 
> Compile tested only.
> 
> [...]

Here is the summary with links:
  - [net] net: ethernet: ti: am65-cpsw: fix error handling in am65_cpsw_nuss_probe()
    https://git.kernel.org/netdev/net/c/46fb6512538d

You are awesome, thank you!
diff mbox series

Patch

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);
 	}
 }