aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2007-03-08 15:06:13 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-03-12 19:31:50 -0400
commit9f35575dfc172f0a93fb464761883c8f49599b7a (patch)
tree5459681e96de3914a95c4993fc6f54b0e3b2ffee
parent392ee1e6dd901db6c4504617476f6442ed91f72d (diff)
[PATCH] pci: Repair pci_save/restore_state so we can restore one save many times.
Because we do not reserve space for the pci-x and pci-e state in struct pci dev we need to dynamically allocate it. However because we need to support restore being called multiple times after a single save it is never safe to free the buffers we have allocated to hold the state. So this patch modifies the save routines to first check to see if we have already allocated a state buffer before allocating a new one. Then the restore routines are modified to not free the state after restoring it. Simple and it fixes some subtle error path handling bugs, that are hard to test for. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Acked-by: Auke Kok <auke-jan.h.kok@intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/pci/pci.c12
-rw-r--r--include/linux/pci.h5
2 files changed, 6 insertions, 11 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 6048c0c637a0..d3eab057b2d3 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -551,7 +551,9 @@ static int pci_save_pcie_state(struct pci_dev *dev)
551 if (pos <= 0) 551 if (pos <= 0)
552 return 0; 552 return 0;
553 553
554 save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL); 554 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
555 if (!save_state)
556 save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL);
555 if (!save_state) { 557 if (!save_state) {
556 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); 558 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
557 return -ENOMEM; 559 return -ENOMEM;
@@ -582,8 +584,6 @@ static void pci_restore_pcie_state(struct pci_dev *dev)
582 pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]); 584 pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]);
583 pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]); 585 pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]);
584 pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]); 586 pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]);
585 pci_remove_saved_cap(save_state);
586 kfree(save_state);
587} 587}
588 588
589 589
@@ -597,7 +597,9 @@ static int pci_save_pcix_state(struct pci_dev *dev)
597 if (pos <= 0) 597 if (pos <= 0)
598 return 0; 598 return 0;
599 599
600 save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL); 600 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
601 if (!save_state)
602 save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL);
601 if (!save_state) { 603 if (!save_state) {
602 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); 604 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
603 return -ENOMEM; 605 return -ENOMEM;
@@ -622,8 +624,6 @@ static void pci_restore_pcix_state(struct pci_dev *dev)
622 cap = (u16 *)&save_state->data[0]; 624 cap = (u16 *)&save_state->data[0];
623 625
624 pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]); 626 pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]);
625 pci_remove_saved_cap(save_state);
626 kfree(save_state);
627} 627}
628 628
629 629
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 78417e421b4c..481ea0663f19 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -209,11 +209,6 @@ static inline void pci_add_saved_cap(struct pci_dev *pci_dev,
209 hlist_add_head(&new_cap->next, &pci_dev->saved_cap_space); 209 hlist_add_head(&new_cap->next, &pci_dev->saved_cap_space);
210} 210}
211 211
212static inline void pci_remove_saved_cap(struct pci_cap_saved_state *cap)
213{
214 hlist_del(&cap->next);
215}
216
217/* 212/*
218 * For PCI devices, the region numbers are assigned this way: 213 * For PCI devices, the region numbers are assigned this way:
219 * 214 *