Commit 0c0746f9 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
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()
parents 1b5f3c51 d555ed45
Loading
Loading
Loading
Loading
+19 −15
Original line number Diff line number Diff line
@@ -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;

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

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

/**
@@ -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);
	/*
	 * 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;

	res->orig_intx = !enable;
		save_orig_intx(pdev, res);
		devres_add(dev, res);
	}

	pci_intx(pdev, enable);

	return 0;