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>

authored by

Shaohua Li and committed by
Greg Kroah-Hartman
017fc480 ec0a3a27

+10 -2
+10 -2
drivers/pci/pci.c
··· 569 569 int pos, i = 0; 570 570 struct pci_cap_saved_state *save_state; 571 571 u16 *cap; 572 + int found = 0; 572 573 573 574 pos = pci_find_capability(dev, PCI_CAP_ID_EXP); 574 575 if (pos <= 0) ··· 578 577 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP); 579 578 if (!save_state) 580 579 save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL); 580 + else 581 + found = 1; 581 582 if (!save_state) { 582 583 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); 583 584 return -ENOMEM; ··· 591 588 pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]); 592 589 pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]); 593 590 save_state->cap_nr = PCI_CAP_ID_EXP; 594 - pci_add_saved_cap(dev, save_state); 591 + if (!found) 592 + pci_add_saved_cap(dev, save_state); 595 593 return 0; 596 594 } 597 595 ··· 620 616 int pos, i = 0; 621 617 struct pci_cap_saved_state *save_state; 622 618 u16 *cap; 619 + int found = 0; 623 620 624 621 pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); 625 622 if (pos <= 0) ··· 629 624 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX); 630 625 if (!save_state) 631 626 save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL); 627 + else 628 + found = 1; 632 629 if (!save_state) { 633 630 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); 634 631 return -ENOMEM; ··· 639 632 640 633 pci_read_config_word(dev, pos + PCI_X_CMD, &cap[i++]); 641 634 save_state->cap_nr = PCI_CAP_ID_PCIX; 642 - pci_add_saved_cap(dev, save_state); 635 + if (!found) 636 + pci_add_saved_cap(dev, save_state); 643 637 return 0; 644 638 } 645 639