pcistub_device_put() shouldn't be called under spinlock, as it can
sleep.
For this reason pcistub_device_get_pci_dev() needs to be modified:
instead of always calling pcistub_device_get() just do the call of
pcistub_device_get() only if it is really needed. This removes the
need to call pcistub_device_put().
Reported-by: Dan Carpenter <error27@gmail.com>
Link: https://lore.kernel.org/lkml/Y+JUIl64UDmdkboh@kadam/
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Link: https://lore.kernel.org/r/20230328084549.20695-1-jgross@suse.com
Signed-off-by: Juergen Gross <jgross@suse.com>
        struct pci_dev *pci_dev = NULL;
        unsigned long flags;
 
-       pcistub_device_get(psdev);
-
        spin_lock_irqsave(&psdev->lock, flags);
        if (!psdev->pdev) {
                psdev->pdev = pdev;
        }
        spin_unlock_irqrestore(&psdev->lock, flags);
 
-       if (!pci_dev)
-               pcistub_device_put(psdev);
+       if (pci_dev)
+               pcistub_device_get(psdev);
 
        return pci_dev;
 }