]> www.infradead.org Git - users/willy/xarray.git/commitdiff
PCI: Fix devres regression in pci_intx()
authorPhilipp Stanner <pstanner@redhat.com>
Thu, 25 Jul 2024 12:07:30 +0000 (14:07 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Thu, 1 Aug 2024 17:56:06 +0000 (12:56 -0500)
pci_intx() becomes managed if pcim_enable_device() has been called in
advance. Commit 25216afc9db5 ("PCI: Add managed pcim_intx()") changed this
behavior so that pci_intx() always leads to creation of a separate device
resource for itself, whereas earlier, a shared resource was used for all
PCI devres operations.

Unfortunately, pci_intx() seems to be used in some drivers' remove() paths;
in the managed case this causes a device resource to be created on driver
detach, which causes .probe() to fail if the driver is reloaded:

  pci 0000:00:1f.2: Resources present before probing

Fix the regression by only redirecting pci_intx() to its managed twin
pcim_intx() if the pci_command changes.

Link: https://lore.kernel.org/r/20240725120729.59788-2-pstanner@redhat.com
Fixes: 25216afc9db5 ("PCI: Add managed pcim_intx()")
Reported-by: Damien Le Moal <dlemoal@kernel.org>
Closes: https://lore.kernel.org/all/b8f4ba97-84fc-4b7e-ba1a-99de2d9f0118@kernel.org/
Signed-off-by: Philipp Stanner <pstanner@redhat.com>
[bhelgaas: add error message to commit log]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Tested-by: Damien Le Moal <dlemoal@kernel.org>
drivers/pci/pci.c

index e3a49f66982d52fc8a30f3dbf387a2ea95be1deb..ffaaca0978cbc95fbb7566e9700b375cdb4940cc 100644 (file)
@@ -4477,12 +4477,6 @@ void pci_intx(struct pci_dev *pdev, int enable)
 {
        u16 pci_command, new;
 
-       /* Preserve the "hybrid" behavior for backwards compatibility */
-       if (pci_is_managed(pdev)) {
-               WARN_ON_ONCE(pcim_intx(pdev, enable) != 0);
-               return;
-       }
-
        pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
 
        if (enable)
@@ -4490,8 +4484,15 @@ void pci_intx(struct pci_dev *pdev, int enable)
        else
                new = pci_command | PCI_COMMAND_INTX_DISABLE;
 
-       if (new != pci_command)
+       if (new != pci_command) {
+               /* Preserve the "hybrid" behavior for backwards compatibility */
+               if (pci_is_managed(pdev)) {
+                       WARN_ON_ONCE(pcim_intx(pdev, enable) != 0);
+                       return;
+               }
+
                pci_write_config_word(pdev, PCI_COMMAND, new);
+       }
 }
 EXPORT_SYMBOL_GPL(pci_intx);