Subject: Re: [PATCH net-next v3 2/3] net: stmmac: Add glue driver for Motorcomm YT6801 ethernet controller

From: "Russell King (Oracle)" <[email-masked]>
Date: Mon, 8 Dec 2025 11:11:20 +0000

On Fri, Dec 05, 2025 at 05:31:34AM +0000, Yao Zi wrote:
> Hi Russell,
> 
> Sorry for the late reply,
> 
> On Mon, Nov 24, 2025 at 07:06:12PM +0000, Russell King (Oracle) wrote:
> > 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...
> 
> This isn't true. MSI API is a little magical: when the device is enabled
> through pcim_enable_device(), the device becomes devres-managed, and
> a plain call to pci_alloc_irq_vectors() becomes managed, too, even if
> its name doesn't indicate it's a devres-managed API.
> 
> pci_free_irq_vectors() will be automatically called on driver deattach.
> See pcim_setup_msi_release() in drivers/pci/msi/msi.c, which is invoked
> by pci_alloc_irq_vectors() internally.

As discussed in the sub-thread with Philipp Stanner, please explicitly
call pci_alloc_irq_vectors() in the cleanup path to avoid adding to
the burden of drivers that need to be fixed allow this "magical"
behaviour to be removed in the future.

Thanks.

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