PCI: pciehp: Fix null pointer deref when hot-removing SR-IOV device
PCI: pciehp: Fix null pointer deref when hot-removing SR-IOV device

Hot-removing a device with SR-IOV enabled causes a null pointer dereference
in v3.9 and v3.10.

This is a regression caused by ba518e3c17 ("PCI: pciehp: Iterate over all
devices in slot, not functions 0-7").  When we iterate over the
bus->devices list, we first remove the PF, which also removes all the VFs
from the list.  Then the list iterator blows up because more than just the
current entry was removed from the list.

ac205b7bb7 ("PCI: make sriov work with hotplug remove") works around a
similar problem in pci_stop_bus_devices() by iterating over the list in
reverse, so the VFs are stopped and removed from the list first, before the
PF.

This patch changes pciehp_unconfigure_device() to iterate over the list in
reverse, too.

[bhelgaas: bugzilla, changelog]
Reference: https://bugzilla.kernel.org/show_bug.cgi?id=60604
Signed-off-by: Yinghai Lu <0674548f4d596393408a51d6287a76ebba2f42aa@kernel.org>
Signed-off-by: Bjorn Helgaas <f10ec01be0c6b54271af5c550cd257810bdf3268@google.com>
Acked-by: Yijing Wang <ac442ed3e729ed4f09d087e9c319e1c47c72d6f1@huawei.com>
CC: 4fbacc2fa0ffdbb11bf1ad6925b886ebd08dd15f@vger.kernel.org	# v3.9+
KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs