Skip to content

Commit

Permalink
Merge tag 'pci-v6.14-fixes-1' of git://git.kernel.org/pub/scm/linux/k…
Browse files Browse the repository at this point in the history
…ernel/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()
  • Loading branch information
Linus Torvalds committed Jan 31, 2025
2 parents 1b5f3c5 + d555ed4 commit 0c0746f
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions drivers/pci/devres.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,19 +419,12 @@ static void pcim_intx_restore(struct device *dev, void *data)
pci_intx(pdev, res->orig_intx);
}

static struct pcim_intx_devres *get_or_create_intx_devres(struct device *dev)
static void save_orig_intx(struct pci_dev *pdev, struct pcim_intx_devres *res)
{
struct pcim_intx_devres *res;

res = devres_find(dev, pcim_intx_restore, NULL, NULL);
if (res)
return res;
u16 pci_command;

res = devres_alloc(pcim_intx_restore, sizeof(*res), GFP_KERNEL);
if (res)
devres_add(dev, res);

return res;
pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
res->orig_intx = !(pci_command & PCI_COMMAND_INTX_DISABLE);
}

/**
Expand All @@ -447,12 +440,23 @@ static struct pcim_intx_devres *get_or_create_intx_devres(struct device *dev)
int pcim_intx(struct pci_dev *pdev, int enable)
{
struct pcim_intx_devres *res;
struct device *dev = &pdev->dev;

res = get_or_create_intx_devres(&pdev->dev);
if (!res)
return -ENOMEM;
/*
* pcim_intx() must only restore the INTx value that existed before the
* driver was loaded, i.e., before it called pcim_intx() for the
* first time.
*/
res = devres_find(dev, pcim_intx_restore, NULL, NULL);
if (!res) {
res = devres_alloc(pcim_intx_restore, sizeof(*res), GFP_KERNEL);
if (!res)
return -ENOMEM;

save_orig_intx(pdev, res);
devres_add(dev, res);
}

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

return 0;
Expand Down

0 comments on commit 0c0746f

Please sign in to comment.