Re: [patch V4 09/14] PCI/MSI: Switch msix_capability_init() to guard(msi_desc_lock)

Bjorn Helgaas
2025-03-19T17:09:35Z

On Wed, Mar 19, 2025 at 11:56:54AM +0100, Thomas Gleixner wrote:
> Split the lock protected functionality of msix_capability_init() out into a
> helper function and use guard(msi_desc_lock) to replace the lock/unlock
> pair.
>
> Simplify the error path in the helper function by utilizing a custom
> cleanup to get rid of the remaining gotos.
>
> No functional change intended.
>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Acked-by: Bjorn Helgaas <bhelgaas@google.com>

> ---
> V4: Split out from the previous combo patch
> ---
> drivers/pci/msi/msi.c | 36 ++++++++++++++++++++----------------
> 1 file changed, 20 insertions(+), 16 deletions(-)
>
> --- a/drivers/pci/msi/msi.c
> +++ b/drivers/pci/msi/msi.c
> @@ -663,35 +663,39 @@ static void msix_mask_all(void __iomem *
> writel(ctrl, base + PCI_MSIX_ENTRY_VECTOR_CTRL);
> }
>
> -static int msix_setup_interrupts(struct pci_dev *dev, struct msix_entry *entries,
> - int nvec, struct irq_affinity *affd)
> +DEFINE_FREE(free_msi_irqs, struct pci_dev *, if (_T) pci_free_msi_irqs(_T));
> +
> +static int __msix_setup_interrupts(struct pci_dev *__dev, struct msix_entry *entries,
> + int nvec, struct irq_affinity_desc *masks)
> {
> - struct irq_affinity_desc *masks __free(kfree) =
> - affd ? irq_create_affinity_masks(nvec, affd) : NULL;
> - int ret;
> + struct pci_dev *dev __free(free_msi_irqs) = __dev;
>
> - msi_lock_descs(&dev->dev);
> - ret = msix_setup_msi_descs(dev, entries, nvec, masks);
> + int ret = msix_setup_msi_descs(dev, entries, nvec, masks);
> if (ret)
> - goto out_free;
> + return ret;
>
> ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX);
> if (ret)
> - goto out_free;
> + return ret;
>
> /* Check if all MSI entries honor device restrictions */
> ret = msi_verify_entries(dev);
> if (ret)
> - goto out_free;
> + return ret;
>
> + retain_ptr(dev);
> msix_update_entries(dev, entries);
> - goto out_unlock;
> + return 0;
> +}
> +
> +static int msix_setup_interrupts(struct pci_dev *dev, struct msix_entry *entries,
> + int nvec, struct irq_affinity *affd)
> +{
> + struct irq_affinity_desc *masks __free(kfree) =
> + affd ? irq_create_affinity_masks(nvec, affd) : NULL;
>
> -out_free:
> - pci_free_msi_irqs(dev);
> -out_unlock:
> - msi_unlock_descs(&dev->dev);
> - return ret;
> + guard(msi_descs_lock)(&dev->dev);
> + return __msix_setup_interrupts(dev, entries, nvec, masks);
> }
>
> /**
>