]> git.baikalelectronics.ru Git - kernel.git/commitdiff
PCI/MSI: Allocate MSI device data on first use
authorThomas Gleixner <tglx@linutronix.de>
Wed, 15 Dec 2021 17:19:49 +0000 (18:19 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Thu, 16 Dec 2021 21:16:38 +0000 (22:16 +0100)
Allocate MSI device data on first use, i.e. when a PCI driver invokes one
of the PCI/MSI enablement functions.

Add a wrapper function to ensure that the ordering vs. pcim_msi_release()
is correct.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Michael Kelley <mikelley@microsoft.com>
Tested-by: Nishanth Menon <nm@ti.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/87r1adrdje.ffs@tglx
drivers/pci/msi/msi.c

index 358b63e507e9602b813eefe23c201d7e9689b32a..369e3c5827b2782cd5cb250863805f7ae493ca26 100644 (file)
@@ -366,6 +366,19 @@ static int pcim_setup_msi_release(struct pci_dev *dev)
        return ret;
 }
 
+/*
+ * Ordering vs. devres: msi device data has to be installed first so that
+ * pcim_msi_release() is invoked before it on device release.
+ */
+static int pci_setup_msi_context(struct pci_dev *dev)
+{
+       int ret = msi_setup_device_data(&dev->dev);
+
+       if (!ret)
+               ret = pcim_setup_msi_release(dev);
+       return ret;
+}
+
 static struct msi_desc *
 msi_setup_entry(struct pci_dev *dev, int nvec, struct irq_affinity *affd)
 {
@@ -909,7 +922,7 @@ static int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec,
        if (nvec > maxvec)
                nvec = maxvec;
 
-       rc = pcim_setup_msi_release(dev);
+       rc = pci_setup_msi_context(dev);
        if (rc)
                return rc;
 
@@ -956,7 +969,7 @@ static int __pci_enable_msix_range(struct pci_dev *dev,
        if (WARN_ON_ONCE(dev->msix_enabled))
                return -EINVAL;
 
-       rc = pcim_setup_msi_release(dev);
+       rc = pci_setup_msi_context(dev);
        if (rc)
                return rc;