netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Yao Zi <ziyao@disroot.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Frank <Frank.Sae@motor-comm.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Vladimir Oltean <vladimir.oltean@nxp.com>,
	Choong Yong Liang <yong.liang.choong@linux.intel.com>,
	Chen-Yu Tsai <wens@csie.org>, Jisheng Zhang <jszhang@kernel.org>,
	Furong Xu <0x1207@gmail.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	Mingcong Bai <jeffbai@aosc.io>,
	Kexy Biscuit <kexybiscuit@aosc.io>, Runhua He <hua@aosc.io>,
	Xi Ruoyao <xry111@xry111.site>
Subject: Re: [PATCH net-next v3 2/3] net: stmmac: Add glue driver for Motorcomm YT6801 ethernet controller
Date: Mon, 24 Nov 2025 19:06:12 +0000	[thread overview]
Message-ID: <aSSspDCPM_5-l24a@shell.armlinux.org.uk> (raw)
In-Reply-To: <20251124163211.54994-3-ziyao@disroot.org>

On Mon, Nov 24, 2025 at 04:32:10PM +0000, Yao Zi wrote:
> +static int motorcomm_setup_irq(struct pci_dev *pdev,
> +			       struct stmmac_resources *res,
> +			       struct plat_stmmacenet_data *plat)
> +{
> +	int ret;
> +
> +	ret = pci_alloc_irq_vectors(pdev, 6, 6, PCI_IRQ_MSIX);
> +	if (ret > 0) {
> +		res->rx_irq[0]	= pci_irq_vector(pdev, 0);
> +		res->tx_irq[0]	= pci_irq_vector(pdev, 4);
> +		res->irq	= pci_irq_vector(pdev, 5);
> +
> +		plat->flags |= STMMAC_FLAG_MULTI_MSI_EN;
> +
> +		return 0;
> +	}
> +
> +	dev_info(&pdev->dev, "failed to allocate MSI-X vector: %d\n", ret);
> +	dev_info(&pdev->dev, "try MSI instead\n");
> +
> +	ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI);
> +	if (ret < 0)
> +		return dev_err_probe(&pdev->dev, ret,
> +				     "failed to allocate MSI\n");
> +
> +	res->irq = pci_irq_vector(pdev, 0);
> +
> +	return 0;
> +}
> +
> +static int motorcomm_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> +{
...
> +	ret = motorcomm_setup_irq(pdev, &res, plat);
> +	if (ret)
> +		return dev_err_probe(&pdev->dev, ret, "failed to setup IRQ\n");
> +
> +	motorcomm_init(priv);
> +
> +	res.addr = priv->base + GMAC_OFFSET;
> +
> +	return stmmac_dvr_probe(&pdev->dev, plat, &res);

If stmmac_dvr_probe() fails, then it will return an error code. This
leaves the PCI MSI interrupt allocated...

> +}
> +
> +static void motorcomm_remove(struct pci_dev *pdev)
> +{
> +	stmmac_dvr_remove(&pdev->dev);
> +	pci_free_irq_vectors(pdev);

... which stood out because of the presence of this function doing
stuff after the call to stmmac_dvr_remove().

So... reviewing the other stmmac PCI drivers:

- dwmac-intel calls pci_alloc_irq_vectors() but does not call
  pci_free_irq_vectors(). This looks like a bug.
- dwmac-intel calls pcim_enable_device() in its probe function, and
  also its intel_eth_pci_resume() - pcim_enable_device() is the devres
  managed function, so we end up adding more and more devres entries
  each time intel_eth_pci_resume() is resumed. Note that
  intel_eth_pci_suspend() doesn't disable the device. So, this should
  probably be the non-devres version.
- dwmac-loongson looks sane, but the checks for ld->multichan before
  calling loongson_dwmac_msi_clear() look unnecessary, as
  pci_free_irq_vectors() can be safely called even if MSI/MSI-X have
  not been (successfully) allocated.

So, I wonder whether there is scope to have a common way to clean up
PCI drivers. Could you look into this please?

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

  reply	other threads:[~2025-11-24 19:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-24 16:32 [PATCH net-next v3 0/3] Add DWMAC glue driver for Motorcomm YT6801 Yao Zi
2025-11-24 16:32 ` [PATCH net-next v3 1/3] net: phy: motorcomm: Support YT8531S PHY in YT6801 Ethernet controller Yao Zi
2025-11-24 16:32 ` [PATCH net-next v3 2/3] net: stmmac: Add glue driver for Motorcomm YT6801 ethernet controller Yao Zi
2025-11-24 19:06   ` Russell King (Oracle) [this message]
2025-12-05  5:31     ` Yao Zi
2025-12-05  9:34       ` Russell King (Oracle)
2025-12-05 22:16         ` Bjorn Helgaas
2025-12-08  9:54           ` Philipp Stanner
2025-12-08 10:15             ` Russell King (Oracle)
2025-12-08 10:47               ` Philipp Stanner
2025-12-08 10:53                 ` Russell King (Oracle)
2025-12-08 10:55                   ` Philipp Stanner
2025-12-11 14:23             ` Yao Zi
2025-12-11 14:44               ` Philipp Stanner
2025-12-08 11:11       ` Russell King (Oracle)
2025-11-24 16:32 ` [PATCH net-next v3 3/3] MAINTAINERS: Assign myself as maintainer of Motorcomm DWMAC glue driver Yao Zi

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=aSSspDCPM_5-l24a@shell.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=0x1207@gmail.com \
    --cc=Frank.Sae@motor-comm.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=hua@aosc.io \
    --cc=jeffbai@aosc.io \
    --cc=jszhang@kernel.org \
    --cc=kexybiscuit@aosc.io \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=vladimir.oltean@nxp.com \
    --cc=wens@csie.org \
    --cc=xry111@xry111.site \
    --cc=yong.liang.choong@linux.intel.com \
    --cc=ziyao@disroot.org \
    /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).