Skip to content

Commit c4a585e

Browse files
niklas88hcahca
authored andcommitted
s390/pci: Fix potential double remove of hotplug slot
In commit 6ee600b ("s390/pci: remove hotplug slot when releasing the device") the zpci_exit_slot() was moved from zpci_device_reserved() to zpci_release_device() with the intention of keeping the hotplug slot around until the device is actually removed. Now zpci_release_device() is only called once all references are dropped. Since the zPCI subsystem only drops its reference once the device is in the reserved state it follows that zpci_release_device() must only deal with devices in the reserved state. Despite that it contains code to tear down from both configured and standby state. For the standby case this already includes the removal of the hotplug slot so would cause a double removal if a device was ever removed in either configured or standby state. Instead of causing a potential double removal in a case that should never happen explicitly WARN_ON() if a device in non-reserved state is released and get rid of the dead code cases. Fixes: 6ee600b ("s390/pci: remove hotplug slot when releasing the device") Reviewed-by: Matthew Rosato <[email protected]> Reviewed-by: Gerd Bayer <[email protected]> Tested-by: Gerd Bayer <[email protected]> Signed-off-by: Niklas Schnelle <[email protected]> Signed-off-by: Heiko Carstens <[email protected]>
1 parent 4879610 commit c4a585e

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

arch/s390/pci/pci.c

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -937,39 +937,23 @@ void zpci_device_reserved(struct zpci_dev *zdev)
937937
void zpci_release_device(struct kref *kref)
938938
{
939939
struct zpci_dev *zdev = container_of(kref, struct zpci_dev, kref);
940-
int ret;
941940

942-
if (zdev->has_hp_slot)
943-
zpci_exit_slot(zdev);
941+
WARN_ON(zdev->state != ZPCI_FN_STATE_RESERVED);
944942

945943
if (zdev->zbus->bus)
946944
zpci_bus_remove_device(zdev, false);
947945

948946
if (zdev_enabled(zdev))
949947
zpci_disable_device(zdev);
950948

951-
switch (zdev->state) {
952-
case ZPCI_FN_STATE_CONFIGURED:
953-
ret = sclp_pci_deconfigure(zdev->fid);
954-
zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev->fid, ret);
955-
fallthrough;
956-
case ZPCI_FN_STATE_STANDBY:
957-
if (zdev->has_hp_slot)
958-
zpci_exit_slot(zdev);
959-
spin_lock(&zpci_list_lock);
960-
list_del(&zdev->entry);
961-
spin_unlock(&zpci_list_lock);
962-
zpci_dbg(3, "rsv fid:%x\n", zdev->fid);
963-
fallthrough;
964-
case ZPCI_FN_STATE_RESERVED:
965-
if (zdev->has_resources)
966-
zpci_cleanup_bus_resources(zdev);
967-
zpci_bus_device_unregister(zdev);
968-
zpci_destroy_iommu(zdev);
969-
fallthrough;
970-
default:
971-
break;
972-
}
949+
if (zdev->has_hp_slot)
950+
zpci_exit_slot(zdev);
951+
952+
if (zdev->has_resources)
953+
zpci_cleanup_bus_resources(zdev);
954+
955+
zpci_bus_device_unregister(zdev);
956+
zpci_destroy_iommu(zdev);
973957
zpci_dbg(3, "rem fid:%x\n", zdev->fid);
974958
kfree_rcu(zdev, rcu);
975959
}

0 commit comments

Comments
 (0)