Commit 9f35575d authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Linus Torvalds

[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: default avatarEric W. Biederman <ebiederm@xmission.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
Acked-by: default avatarAuke Kok <auke-jan.h.kok@intel.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 392ee1e6
...@@ -551,6 +551,8 @@ static int pci_save_pcie_state(struct pci_dev *dev) ...@@ -551,6 +551,8 @@ static int pci_save_pcie_state(struct pci_dev *dev)
if (pos <= 0) if (pos <= 0)
return 0; return 0;
save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
if (!save_state)
save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL); save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL);
if (!save_state) { if (!save_state) {
dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
...@@ -582,8 +584,6 @@ static void pci_restore_pcie_state(struct pci_dev *dev) ...@@ -582,8 +584,6 @@ static void pci_restore_pcie_state(struct pci_dev *dev)
pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]); pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]);
pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]); pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]);
pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]); pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]);
pci_remove_saved_cap(save_state);
kfree(save_state);
} }
...@@ -597,6 +597,8 @@ static int pci_save_pcix_state(struct pci_dev *dev) ...@@ -597,6 +597,8 @@ static int pci_save_pcix_state(struct pci_dev *dev)
if (pos <= 0) if (pos <= 0)
return 0; return 0;
save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
if (!save_state)
save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL); save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL);
if (!save_state) { if (!save_state) {
dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
...@@ -622,8 +624,6 @@ static void pci_restore_pcix_state(struct pci_dev *dev) ...@@ -622,8 +624,6 @@ static void pci_restore_pcix_state(struct pci_dev *dev)
cap = (u16 *)&save_state->data[0]; cap = (u16 *)&save_state->data[0];
pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]); pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]);
pci_remove_saved_cap(save_state);
kfree(save_state);
} }
......
...@@ -209,11 +209,6 @@ static inline void pci_add_saved_cap(struct pci_dev *pci_dev, ...@@ -209,11 +209,6 @@ static inline void pci_add_saved_cap(struct pci_dev *pci_dev,
hlist_add_head(&new_cap->next, &pci_dev->saved_cap_space); hlist_add_head(&new_cap->next, &pci_dev->saved_cap_space);
} }
static inline void pci_remove_saved_cap(struct pci_cap_saved_state *cap)
{
hlist_del(&cap->next);
}
/* /*
* For PCI devices, the region numbers are assigned this way: * For PCI devices, the region numbers are assigned this way:
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment