public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: Jakub Kicinski <kuba@kernel.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
	davem@davemloft.net, Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	Richard Cochran <richardcochran@gmail.com>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, imx@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	Stefan Wahren <wahrenst@gmx.net>, Simon Horman <horms@kernel.org>,
	Andrew Lunn <andrew@lunn.ch>
Subject: Re: [net-next v15 04/12] net: mtip: The L2 switch driver for imx287
Date: Mon, 21 Jul 2025 23:06:11 +0200	[thread overview]
Message-ID: <20250721230611.45fb74df@wsk> (raw)
In-Reply-To: <20250718181028.00cda754@kernel.org>

[-- Attachment #1: Type: text/plain, Size: 3888 bytes --]

Hi Jakub,

> On Wed, 16 Jul 2025 23:47:23 +0200 Lukasz Majewski wrote:
> > +static void mtip_ndev_cleanup(struct switch_enet_private *fep)
> > +{
> > +	struct mtip_ndev_priv *priv;
> > +	int i;
> > +
> > +	for (i = 0; i < SWITCH_EPORT_NUMBER; i++) {
> > +		if (fep->ndev[i]) {  
> 
> this just checks if netdev is NULL
> 
> > +			priv = netdev_priv(fep->ndev[i]);
> > +			cancel_work_sync(&priv->tx_timeout_work);
> > +
> > +			unregister_netdev(fep->ndev[i]);  
> 
> and if not unregisters
> 
> > +			free_netdev(fep->ndev[i]);
> > +		}
> > +	}
> > +}
> > +
> > +static int mtip_ndev_init(struct switch_enet_private *fep,
> > +			  struct platform_device *pdev)
> > +{
> > +	struct mtip_ndev_priv *priv;
> > +	int i, ret = 0;
> > +
> > +	for (i = 0; i < SWITCH_EPORT_NUMBER; i++) {
> > +		fep->ndev[i] = alloc_netdev(sizeof(struct
> > mtip_ndev_priv),  
> 
> but we assign the pointer immediatelly
> 
> > +					    fep->ndev_name[i],
> > NET_NAME_USER,
> > +					    ether_setup);
> > +		if (!fep->ndev[i]) {
> > +			ret = -ENOMEM;
> > +			break;
> > +		}
> > +
> > +		fep->ndev[i]->ethtool_ops = &mtip_ethtool_ops;
> > +		fep->ndev[i]->netdev_ops = &mtip_netdev_ops;
> > +		SET_NETDEV_DEV(fep->ndev[i], &pdev->dev);
> > +
> > +		priv = netdev_priv(fep->ndev[i]);
> > +		priv->dev = fep->ndev[i];
> > +		priv->fep = fep;
> > +		priv->portnum = i + 1;
> > +		fep->ndev[i]->irq = fep->irq;
> > +
> > +		mtip_setup_mac(fep->ndev[i]);
> > +
> > +		ret = register_netdev(fep->ndev[i]);  
> 
> and don't clear it when register fails
> 
> > +		if (ret) {
> > +			dev_err(&fep->ndev[i]->dev,
> > +				"%s: ndev %s register err: %d\n",
> > __func__,
> > +				fep->ndev[i]->name, ret);
> > +			break;
> > +		}
> > +
> > +		dev_dbg(&fep->ndev[i]->dev, "%s: MTIP eth L2
> > switch %pM\n",
> > +			fep->ndev[i]->name,
> > fep->ndev[i]->dev_addr);
> > +	}
> > +
> > +	if (ret)
> > +		mtip_ndev_cleanup(fep);  
> 
> You're probably better off handling the unwind on error separately
> from the full cleanup function, but I guess that's subjective.

Yes, you are right - I shall add:
fep->ndev[i] = NULL;

just after free_ndev(fep->ndev[i]); in the
mtip_ndev_cleanup() function.

> 
> > +	return ret;
> > +}  
> 
> > +static int mtip_sw_probe(struct platform_device *pdev)
> > +{  
> 
> > +	ret = mtip_ndev_init(fep, pdev);
> > +	if (ret) {
> > +		dev_err(&pdev->dev, "%s: Failed to create virtual
> > ndev (%d)\n",
> > +			__func__, ret);
> > +		goto ndev_init_err;
> > +	}
> > +
> > +	ret = mtip_switch_dma_init(fep);  
> 
> > +	ret = mtip_mii_init(fep, pdev);  
> 
> Seems like we're registering the netdevs before fully initializing 
> the HW? Is it safe if user (or worse, some other kernel subsystem) 
> tries to open the netdevs before the driver finished the init?
>  

This needs to be reordered - the ndev registration shall be the last
step.

Thanks for pointing this out.

> 
> > +	if (ret) {
> > +		dev_err(&pdev->dev, "%s: Cannot init phy bus
> > (%d)!\n", __func__,
> > +			ret);
> > +		goto mii_init_err;
> > +	}
> > +	/* setup timer for learning aging function */
> > +	timer_setup(&fep->timer_mgnt, mtip_mgnt_timer, 0);
> > +	mod_timer(&fep->timer_mgnt,
> > +		  jiffies +
> > msecs_to_jiffies(LEARNING_AGING_INTERVAL)); +
> > +	return 0;
> > +
> > + mii_init_err:
> > + dma_init_err:
> > +	mtip_ndev_cleanup(fep);  
> 
> Please name the labels after the action they jump to, not the location
> where they jump from.

Ok.

> 
> > + ndev_init_err:
> > +
> > +	return ret;  


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Johanna Denk,
Tabea Lutz HRB 165235 Munich, Office: Kirchenstr.5, D-82194
Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2025-07-21 21:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-16 21:47 [net-next v15 00/12] net: mtip: Add support for MTIP imx287 L2 switch driver Lukasz Majewski
2025-07-16 21:47 ` [net-next v15 01/12] dt-bindings: net: Add MTIP L2 switch description Lukasz Majewski
2025-07-16 21:47 ` [net-next v15 02/12] ARM: dts: nxp: mxs: Adjust the imx28.dtsi " Lukasz Majewski
2025-07-16 21:47 ` [net-next v15 03/12] ARM: dts: nxp: mxs: Adjust XEA board's DTS to support L2 switch Lukasz Majewski
2025-07-16 21:47 ` [net-next v15 04/12] net: mtip: The L2 switch driver for imx287 Lukasz Majewski
2025-07-19  1:10   ` Jakub Kicinski
2025-07-21 21:06     ` Lukasz Majewski [this message]
2025-07-16 21:47 ` [net-next v15 05/12] net: mtip: Add buffers management functions to the L2 switch driver Lukasz Majewski
2025-07-16 21:47 ` [net-next v15 06/12] net: mtip: Add net_device_ops " Lukasz Majewski
2025-07-19  1:28   ` Jakub Kicinski
2025-07-22  9:16     ` Lukasz Majewski
2025-07-23 20:05       ` Lukasz Majewski
2025-07-23 20:17         ` Jakub Kicinski
2025-07-23 21:11           ` Lukasz Majewski
2025-07-16 21:47 ` [net-next v15 07/12] net: mtip: Add mtip_switch_{rx|tx} " Lukasz Majewski
2025-07-16 21:47 ` [net-next v15 08/12] net: mtip: Extend the L2 switch driver with management operations Lukasz Majewski
2025-07-16 21:47 ` [net-next v15 09/12] net: mtip: Extend the L2 switch driver for imx287 with bridge operations Lukasz Majewski
2025-07-16 21:47 ` [net-next v15 10/12] ARM: mxs_defconfig: Enable CONFIG_NFS_FSCACHE Lukasz Majewski
2025-07-16 21:47 ` [net-next v15 11/12] ARM: mxs_defconfig: Update mxs_defconfig to 6.16-rc5 Lukasz Majewski
2025-07-16 21:47 ` [net-next v15 12/12] ARM: mxs_defconfig: Enable CONFIG_FEC_MTIP_L2SW to support MTIP L2 switch Lukasz Majewski

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=20250721230611.45fb74df@wsk \
    --to=lukma@denx.de \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=festevam@gmail.com \
    --cc=horms@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=robh@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=wahrenst@gmx.net \
    /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