netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roger Quadros <rogerq@kernel.org>
To: Nicolas Pitre <nico@fluxnic.net>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Grygorii Strashko <grygorii.strashko@ti.com>,
	Vignesh Raghavendra <vigneshr@ti.com>
Cc: Nicolas Pitre <npitre@baylibre.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v3 2/2] net: ethernet: ti: am65-cpsw: avoid devm_alloc_etherdev, fix module removal
Date: Fri, 4 Oct 2024 12:09:15 +0300	[thread overview]
Message-ID: <b055cea5-6f03-4c73-aae4-09b5d2290c29@kernel.org> (raw)
In-Reply-To: <20241004041218.2809774-3-nico@fluxnic.net>

Hi Nicolas,

On 04/10/2024 07:10, Nicolas Pitre wrote:
> From: Nicolas Pitre <npitre@baylibre.com>
> 
> Usage of devm_alloc_etherdev_mqs() conflicts with
> am65_cpsw_nuss_cleanup_ndev() as the same struct net_device instances
> get unregistered twice. Switch to alloc_etherdev_mqs() and make sure

Do we know why the same net device gets unregistered twice?

> am65_cpsw_nuss_cleanup_ndev() unregisters and frees those net_device
> instances properly.
> 
> With this, it is finally possible to rmmod the driver without oopsing
> the kernel.
> 
> Fixes: 93a76530316a ("net: ethernet: ti: introduce am65x/j721e gigabit eth subsystem driver")
> Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
> ---
>  drivers/net/ethernet/ti/am65-cpsw-nuss.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> index f6bc8a4dc6..e95457c988 100644
> --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> @@ -2744,10 +2744,9 @@ am65_cpsw_nuss_init_port_ndev(struct am65_cpsw_common *common, u32 port_idx)
>  		return 0;
>  
>  	/* alloc netdev */
> -	port->ndev = devm_alloc_etherdev_mqs(common->dev,
> -					     sizeof(struct am65_cpsw_ndev_priv),
> -					     AM65_CPSW_MAX_QUEUES,
> -					     AM65_CPSW_MAX_QUEUES);
> +	port->ndev = alloc_etherdev_mqs(sizeof(struct am65_cpsw_ndev_priv),
> +					AM65_CPSW_MAX_QUEUES,
> +					AM65_CPSW_MAX_QUEUES);

Can we solve this issue without doing this change as
there are many error cases relying on devm managed freeing of netdev.


>  	if (!port->ndev) {
>  		dev_err(dev, "error allocating slave net_device %u\n",
>  			port->port_id);
> @@ -2868,8 +2867,12 @@ 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 && port->ndev->reg_state == NETREG_REGISTERED)
> +		if (!port->ndev)
> +			continue;
> +		if (port->ndev->reg_state == NETREG_REGISTERED)
>  			unregister_netdev(port->ndev);
> +		free_netdev(port->ndev);
> +		port->ndev = NULL;

I still can't see what we are doing wrong in existing code.

>  	}
>  }
>  
> @@ -3613,16 +3616,17 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev)
>  
>  	ret = am65_cpsw_nuss_init_ndevs(common);
>  	if (ret)
> -		goto err_free_phylink;
> +		goto err_ndevs_clear;
>  
>  	ret = am65_cpsw_nuss_register_ndevs(common);
>  	if (ret)
> -		goto err_free_phylink;
> +		goto err_ndevs_clear;
>  
>  	pm_runtime_put(dev);
>  	return 0;
>  
> -err_free_phylink:
> +err_ndevs_clear:
> +	am65_cpsw_nuss_cleanup_ndev(common);
>  	am65_cpsw_nuss_phylink_cleanup(common);
>  	am65_cpts_release(common->cpts);
>  err_of_clear:

-- 
cheers,
-roger

  reply	other threads:[~2024-10-04  9:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-04  4:10 [PATCH net v3 0/2] fix ti-am65-cpsw-nuss module removal Nicolas Pitre
2024-10-04  4:10 ` [PATCH net v3 1/2] net: ethernet: ti: am65-cpsw: prevent WARN_ON upon " Nicolas Pitre
2024-10-04  8:48   ` Roger Quadros
2024-10-04  4:10 ` [PATCH net v3 2/2] net: ethernet: ti: am65-cpsw: avoid devm_alloc_etherdev, fix " Nicolas Pitre
2024-10-04  9:09   ` Roger Quadros [this message]
2024-10-04 12:57     ` Roger Quadros
2024-10-04 15:37     ` Nicolas Pitre
2024-10-04 19:50       ` Roger Quadros
2024-10-04 21:17         ` Nicolas Pitre
2024-10-05 20:26         ` Nicolas Pitre
2024-10-07 11:37           ` Roger Quadros
2024-10-07 11:37   ` Roger Quadros
2024-10-08  8:50 ` [PATCH net v3 0/2] fix ti-am65-cpsw-nuss " patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b055cea5-6f03-4c73-aae4-09b5d2290c29@kernel.org \
    --to=rogerq@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=grygorii.strashko@ti.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nico@fluxnic.net \
    --cc=npitre@baylibre.com \
    --cc=pabeni@redhat.com \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).