Skip to content

Commit f11cc2a

Browse files
committed
PCI/MSI: Switch msi_capability_init() to guard(msi_desc_lock)
Split the lock protected functionality of msi_capability_init() out into a helper function and use guard(msi_desc_lock) to replace the lock/unlock pair. No functional change intended. Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Bjorn Helgaas <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent 5c0ba4f commit f11cc2a

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

drivers/pci/msi/msi.c

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -335,38 +335,13 @@ static int msi_verify_entries(struct pci_dev *dev)
335335
return !entry ? 0 : -EIO;
336336
}
337337

338-
/**
339-
* msi_capability_init - configure device's MSI capability structure
340-
* @dev: pointer to the pci_dev data structure of MSI device function
341-
* @nvec: number of interrupts to allocate
342-
* @affd: description of automatic IRQ affinity assignments (may be %NULL)
343-
*
344-
* Setup the MSI capability structure of the device with the requested
345-
* number of interrupts. A return value of zero indicates the successful
346-
* setup of an entry with the new MSI IRQ. A negative return value indicates
347-
* an error, and a positive return value indicates the number of interrupts
348-
* which could have been allocated.
349-
*/
350-
static int msi_capability_init(struct pci_dev *dev, int nvec,
351-
struct irq_affinity *affd)
338+
static int __msi_capability_init(struct pci_dev *dev, int nvec, struct irq_affinity_desc *masks)
352339
{
340+
int ret = msi_setup_msi_desc(dev, nvec, masks);
353341
struct msi_desc *entry, desc;
354-
int ret;
355342

356-
/* Reject multi-MSI early on irq domain enabled architectures */
357-
if (nvec > 1 && !pci_msi_domain_supports(dev, MSI_FLAG_MULTI_PCI_MSI, ALLOW_LEGACY))
358-
return 1;
359-
360-
/* Disable MSI during setup in the hardware to erase stale state */
361-
pci_msi_set_enable(dev, 0);
362-
363-
struct irq_affinity_desc *masks __free(kfree) =
364-
affd ? irq_create_affinity_masks(nvec, affd) : NULL;
365-
366-
msi_lock_descs(&dev->dev);
367-
ret = msi_setup_msi_desc(dev, nvec, masks);
368343
if (ret)
369-
goto unlock;
344+
return ret;
370345

371346
/* All MSIs are unmasked by default; mask them all */
372347
entry = msi_first_desc(&dev->dev, MSI_DESC_ALL);
@@ -394,16 +369,45 @@ static int msi_capability_init(struct pci_dev *dev, int nvec,
394369

395370
pcibios_free_irq(dev);
396371
dev->irq = entry->irq;
397-
goto unlock;
398-
372+
return 0;
399373
err:
400374
pci_msi_unmask(&desc, msi_multi_mask(&desc));
401375
pci_free_msi_irqs(dev);
402-
unlock:
403-
msi_unlock_descs(&dev->dev);
404376
return ret;
405377
}
406378

379+
/**
380+
* msi_capability_init - configure device's MSI capability structure
381+
* @dev: pointer to the pci_dev data structure of MSI device function
382+
* @nvec: number of interrupts to allocate
383+
* @affd: description of automatic IRQ affinity assignments (may be %NULL)
384+
*
385+
* Setup the MSI capability structure of the device with the requested
386+
* number of interrupts. A return value of zero indicates the successful
387+
* setup of an entry with the new MSI IRQ. A negative return value indicates
388+
* an error, and a positive return value indicates the number of interrupts
389+
* which could have been allocated.
390+
*/
391+
static int msi_capability_init(struct pci_dev *dev, int nvec,
392+
struct irq_affinity *affd)
393+
{
394+
/* Reject multi-MSI early on irq domain enabled architectures */
395+
if (nvec > 1 && !pci_msi_domain_supports(dev, MSI_FLAG_MULTI_PCI_MSI, ALLOW_LEGACY))
396+
return 1;
397+
398+
/*
399+
* Disable MSI during setup in the hardware, but mark it enabled
400+
* so that setup code can evaluate it.
401+
*/
402+
pci_msi_set_enable(dev, 0);
403+
404+
struct irq_affinity_desc *masks __free(kfree) =
405+
affd ? irq_create_affinity_masks(nvec, affd) : NULL;
406+
407+
guard(msi_descs_lock)(&dev->dev);
408+
return __msi_capability_init(dev, nvec, masks);
409+
}
410+
407411
int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec,
408412
struct irq_affinity *affd)
409413
{

0 commit comments

Comments
 (0)