[patch 05/10] PCI/MSI: Switch to MSI descriptor locking to guard()

Thomas Gleixner
2025-03-09T08:41:51Z

Convert the code to use the new guard(msi_descs_lock).

No functional change intended.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-pci@vger.kernel.org
---
drivers/pci/msi/api.c | 6 ++----
drivers/pci/msi/msi.c | 30 ++++++++++++------------------
2 files changed, 14 insertions(+), 22 deletions(-)

--- a/drivers/pci/msi/api.c
+++ b/drivers/pci/msi/api.c
@@ -53,10 +53,9 @@ void pci_disable_msi(struct pci_dev *dev
if (!pci_msi_enabled() || !dev || !dev->msi_enabled)
return;

- msi_lock_descs(&dev->dev);
+ guard(msi_descs_lock)(&dev->dev);
pci_msi_shutdown(dev);
pci_free_msi_irqs(dev);
- msi_unlock_descs(&dev->dev);
}
EXPORT_SYMBOL(pci_disable_msi);

@@ -196,10 +195,9 @@ void pci_disable_msix(struct pci_dev *de
if (!pci_msi_enabled() || !dev || !dev->msix_enabled)
return;

- msi_lock_descs(&dev->dev);
+ guard(msi_descs_lock)(&dev->dev);
pci_msix_shutdown(dev);
pci_free_msi_irqs(dev);
- msi_unlock_descs(&dev->dev);
}
EXPORT_SYMBOL(pci_disable_msix);

--- a/drivers/pci/msi/msi.c
+++ b/drivers/pci/msi/msi.c
@@ -351,7 +351,7 @@ static int msi_verify_entries(struct pci
static int msi_capability_init(struct pci_dev *dev, int nvec,
struct irq_affinity *affd)
{
- struct irq_affinity_desc *masks = NULL;
+ struct irq_affinity_desc *masks __free(kfree) = NULL;
struct msi_desc *entry, desc;
int ret;

@@ -369,7 +369,7 @@ static int msi_capability_init(struct pc
if (affd)
masks = irq_create_affinity_masks(nvec, affd);

- msi_lock_descs(&dev->dev);
+ guard(msi_descs_lock)(&dev->dev);
ret = msi_setup_msi_desc(dev, nvec, masks);
if (ret)
goto fail;
@@ -399,16 +399,13 @@ static int msi_capability_init(struct pc

pcibios_free_irq(dev);
dev->irq = entry->irq;
- goto unlock;
+ return 0;

err:
pci_msi_unmask(&desc, msi_multi_mask(&desc));
pci_free_msi_irqs(dev);
fail:
dev->msi_enabled = 0;
-unlock:
- msi_unlock_descs(&dev->dev);
- kfree(masks);
return ret;
}

@@ -669,13 +666,13 @@ static void msix_mask_all(void __iomem *
static int msix_setup_interrupts(struct pci_dev *dev, struct msix_entry *entries,
int nvec, struct irq_affinity *affd)
{
- struct irq_affinity_desc *masks = NULL;
+ struct irq_affinity_desc *masks __free(kfree) = NULL;
int ret;

if (affd)
masks = irq_create_affinity_masks(nvec, affd);

- msi_lock_descs(&dev->dev);
+ guard(msi_descs_lock)(&dev->dev);
ret = msix_setup_msi_descs(dev, entries, nvec, masks);
if (ret)
goto out_free;
@@ -690,13 +687,10 @@ static int msix_setup_interrupts(struct
goto out_free;

msix_update_entries(dev, entries);
- goto out_unlock;
+ return 0;

out_free:
pci_free_msi_irqs(dev);
-out_unlock:
- msi_unlock_descs(&dev->dev);
- kfree(masks);
return ret;
}

@@ -871,13 +865,13 @@ void __pci_restore_msix_state(struct pci

write_msg = arch_restore_msi_irqs(dev);

- msi_lock_descs(&dev->dev);
- msi_for_each_desc(entry, &dev->dev, MSI_DESC_ALL) {
- if (write_msg)
- __pci_write_msi_msg(entry, &entry->msg);
- pci_msix_write_vector_ctrl(entry, entry->pci.msix_ctrl);
+ scoped_guard (msi_descs_lock, &dev->dev) {
+ msi_for_each_desc(entry, &dev->dev, MSI_DESC_ALL) {
+ if (write_msg)
+ __pci_write_msi_msg(entry, &entry->msg);
+ pci_msix_write_vector_ctrl(entry, entry->pci.msix_ctrl);
+ }
}
- msi_unlock_descs(&dev->dev);

pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL, 0);
}