Skip to content

Commit 0c0746f

Browse files
committed
Merge tag 'pci-v6.14-fixes-1' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci
Pull pci fix from Bjorn Helgaas: - Save the original INTX_DISABLE bit at the first pcim_intx() call and restore that at devres cleanup instead of restoring the opposite of the most recent enable/disable pcim_intx() argument, which was wrong when a driver called pcim_intx() multiple times or with the already enabled state (Takashi Iwai) * tag 'pci-v6.14-fixes-1' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci: PCI: Restore original INTX_DISABLE bit by pcim_intx()
2 parents 1b5f3c5 + d555ed4 commit 0c0746f

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

drivers/pci/devres.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -419,19 +419,12 @@ static void pcim_intx_restore(struct device *dev, void *data)
419419
pci_intx(pdev, res->orig_intx);
420420
}
421421

422-
static struct pcim_intx_devres *get_or_create_intx_devres(struct device *dev)
422+
static void save_orig_intx(struct pci_dev *pdev, struct pcim_intx_devres *res)
423423
{
424-
struct pcim_intx_devres *res;
425-
426-
res = devres_find(dev, pcim_intx_restore, NULL, NULL);
427-
if (res)
428-
return res;
424+
u16 pci_command;
429425

430-
res = devres_alloc(pcim_intx_restore, sizeof(*res), GFP_KERNEL);
431-
if (res)
432-
devres_add(dev, res);
433-
434-
return res;
426+
pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
427+
res->orig_intx = !(pci_command & PCI_COMMAND_INTX_DISABLE);
435428
}
436429

437430
/**
@@ -447,12 +440,23 @@ static struct pcim_intx_devres *get_or_create_intx_devres(struct device *dev)
447440
int pcim_intx(struct pci_dev *pdev, int enable)
448441
{
449442
struct pcim_intx_devres *res;
443+
struct device *dev = &pdev->dev;
450444

451-
res = get_or_create_intx_devres(&pdev->dev);
452-
if (!res)
453-
return -ENOMEM;
445+
/*
446+
* pcim_intx() must only restore the INTx value that existed before the
447+
* driver was loaded, i.e., before it called pcim_intx() for the
448+
* first time.
449+
*/
450+
res = devres_find(dev, pcim_intx_restore, NULL, NULL);
451+
if (!res) {
452+
res = devres_alloc(pcim_intx_restore, sizeof(*res), GFP_KERNEL);
453+
if (!res)
454+
return -ENOMEM;
455+
456+
save_orig_intx(pdev, res);
457+
devres_add(dev, res);
458+
}
454459

455-
res->orig_intx = !enable;
456460
pci_intx(pdev, enable);
457461

458462
return 0;

0 commit comments

Comments
 (0)