diff options
author | Shaohua Li <shaohua.li@intel.com> | 2007-12-17 20:57:09 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-02-01 18:04:27 -0500 |
commit | 017fc480cc8cc0594dc250951d78e814667ae4c2 (patch) | |
tree | 04efdbe646e8333be11ba6e9a0fc867109d22245 /drivers/pci/pci.c | |
parent | ec0a3a27fbb5792980b8c3ce4a93bc2ee93d0b35 (diff) |
PCI: avoid save the same type of cap multiple times
Avoid adding the same type of cap multiple times, otherwise we will see dead loop.
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/pci/pci.c')
-rw-r--r-- | drivers/pci/pci.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 342857c555de..7248e9fb12bd 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -569,6 +569,7 @@ static int pci_save_pcie_state(struct pci_dev *dev) | |||
569 | int pos, i = 0; | 569 | int pos, i = 0; |
570 | struct pci_cap_saved_state *save_state; | 570 | struct pci_cap_saved_state *save_state; |
571 | u16 *cap; | 571 | u16 *cap; |
572 | int found = 0; | ||
572 | 573 | ||
573 | pos = pci_find_capability(dev, PCI_CAP_ID_EXP); | 574 | pos = pci_find_capability(dev, PCI_CAP_ID_EXP); |
574 | if (pos <= 0) | 575 | if (pos <= 0) |
@@ -577,6 +578,8 @@ static int pci_save_pcie_state(struct pci_dev *dev) | |||
577 | save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP); | 578 | save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP); |
578 | if (!save_state) | 579 | if (!save_state) |
579 | save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL); | 580 | save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL); |
581 | else | ||
582 | found = 1; | ||
580 | if (!save_state) { | 583 | if (!save_state) { |
581 | dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); | 584 | dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); |
582 | return -ENOMEM; | 585 | return -ENOMEM; |
@@ -588,7 +591,8 @@ static int pci_save_pcie_state(struct pci_dev *dev) | |||
588 | pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]); | 591 | pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]); |
589 | pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]); | 592 | pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]); |
590 | save_state->cap_nr = PCI_CAP_ID_EXP; | 593 | save_state->cap_nr = PCI_CAP_ID_EXP; |
591 | pci_add_saved_cap(dev, save_state); | 594 | if (!found) |
595 | pci_add_saved_cap(dev, save_state); | ||
592 | return 0; | 596 | return 0; |
593 | } | 597 | } |
594 | 598 | ||
@@ -616,6 +620,7 @@ static int pci_save_pcix_state(struct pci_dev *dev) | |||
616 | int pos, i = 0; | 620 | int pos, i = 0; |
617 | struct pci_cap_saved_state *save_state; | 621 | struct pci_cap_saved_state *save_state; |
618 | u16 *cap; | 622 | u16 *cap; |
623 | int found = 0; | ||
619 | 624 | ||
620 | pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); | 625 | pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); |
621 | if (pos <= 0) | 626 | if (pos <= 0) |
@@ -624,6 +629,8 @@ static int pci_save_pcix_state(struct pci_dev *dev) | |||
624 | save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX); | 629 | save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX); |
625 | if (!save_state) | 630 | if (!save_state) |
626 | save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL); | 631 | save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL); |
632 | else | ||
633 | found = 1; | ||
627 | if (!save_state) { | 634 | if (!save_state) { |
628 | dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); | 635 | dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); |
629 | return -ENOMEM; | 636 | return -ENOMEM; |
@@ -632,7 +639,8 @@ static int pci_save_pcix_state(struct pci_dev *dev) | |||
632 | 639 | ||
633 | pci_read_config_word(dev, pos + PCI_X_CMD, &cap[i++]); | 640 | pci_read_config_word(dev, pos + PCI_X_CMD, &cap[i++]); |
634 | save_state->cap_nr = PCI_CAP_ID_PCIX; | 641 | save_state->cap_nr = PCI_CAP_ID_PCIX; |
635 | pci_add_saved_cap(dev, save_state); | 642 | if (!found) |
643 | pci_add_saved_cap(dev, save_state); | ||
636 | return 0; | 644 | return 0; |
637 | } | 645 | } |
638 | 646 | ||