diff mbox series

PCI: Simplify pci_dev_reset_slot_function()

Message ID c6aab5af096f7b1b3db57f6335cebba8f0fcca89.1595330431.git.lukas@wunner.de
State New
Headers show
Series PCI: Simplify pci_dev_reset_slot_function() | expand

Commit Message

Lukas Wunner July 21, 2020, 11:24 a.m. UTC
pci_dev_reset_slot_function() refuses to reset a hotplug slot if it is
shared by multiple pci_devs.  That's the case if and only if the slot is
occupied by a multifunction device.

Simplify the function to check the device's multifunction flag instead
of iterating over the devices on the bus.  (Iterating over the devices
requires holding pci_bus_sem, which the function erroneously does not
acquire.)

Signed-off-by: Lukas Wunner <lukas@wunner.de>
Cc: Alex Williamson <alex.williamson@redhat.com>
---
 drivers/pci/pci.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

Comments

Bjorn Helgaas Sept. 17, 2020, 9:26 p.m. UTC | #1
On Tue, Jul 21, 2020 at 01:24:51PM +0200, Lukas Wunner wrote:
> pci_dev_reset_slot_function() refuses to reset a hotplug slot if it is
> shared by multiple pci_devs.  That's the case if and only if the slot is
> occupied by a multifunction device.
> 
> Simplify the function to check the device's multifunction flag instead
> of iterating over the devices on the bus.  (Iterating over the devices
> requires holding pci_bus_sem, which the function erroneously does not
> acquire.)
> 
> Signed-off-by: Lukas Wunner <lukas@wunner.de>
> Cc: Alex Williamson <alex.williamson@redhat.com>

Applied to pci/misc for v5.10, thanks!

> ---
>  drivers/pci/pci.c | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 455da72..b406611 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -4914,16 +4914,10 @@ static int pci_reset_hotplug_slot(struct hotplug_slot *hotplug, int probe)
>  
>  static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
>  {
> -	struct pci_dev *pdev;
> -
> -	if (dev->subordinate || !dev->slot ||
> +	if (dev->multifunction || dev->subordinate || !dev->slot ||
>  	    dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET)
>  		return -ENOTTY;
>  
> -	list_for_each_entry(pdev, &dev->bus->devices, bus_list)
> -		if (pdev != dev && pdev->slot == dev->slot)
> -			return -ENOTTY;
> -
>  	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
>  }
>  
> -- 
> 2.27.0
>
diff mbox series

Patch

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 455da72..b406611 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4914,16 +4914,10 @@  static int pci_reset_hotplug_slot(struct hotplug_slot *hotplug, int probe)
 
 static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
 {
-	struct pci_dev *pdev;
-
-	if (dev->subordinate || !dev->slot ||
+	if (dev->multifunction || dev->subordinate || !dev->slot ||
 	    dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET)
 		return -ENOTTY;
 
-	list_for_each_entry(pdev, &dev->bus->devices, bus_list)
-		if (pdev != dev && pdev->slot == dev->slot)
-			return -ENOTTY;
-
 	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
 }