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