virpcimock: Move actions checking one level up

The pci_driver_bind() and pci_driver_unbind() functions are
"internal implementation", meaning other parts of the code should
be able to call them and get the job done. Checking for actions
(PCI_ACTION_BIND and PCI_ACTION_UNBIND) should be done in
handlers (pci_driver_handle_bind() and
pci_driver_handle_unbind()). Surprisingly, the other two actions
(PCI_ACTION_NEW_ID and PCI_ACTION_REMOVE_ID) are checked already
at this level.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Michal Privoznik 2019-06-17 17:33:06 +02:00
parent 39de732aa7
commit 038e6f069f

View File

@ -552,8 +552,8 @@ pci_driver_bind(struct pciDriver *driver,
int ret = -1; int ret = -1;
char *devpath = NULL, *driverpath = NULL; char *devpath = NULL, *driverpath = NULL;
if (dev->driver || PCI_ACTION_BIND & driver->fail) { if (dev->driver) {
/* Device already bound or failing driver requested */ /* Device already bound */
errno = ENODEV; errno = ENODEV;
return ret; return ret;
} }
@ -599,8 +599,8 @@ pci_driver_unbind(struct pciDriver *driver,
int ret = -1; int ret = -1;
char *devpath = NULL, *driverpath = NULL; char *devpath = NULL, *driverpath = NULL;
if (dev->driver != driver || PCI_ACTION_UNBIND & driver->fail) { if (dev->driver != driver) {
/* Device not bound to the @driver or failing driver used */ /* Device not bound to the @driver */
errno = ENODEV; errno = ENODEV;
return ret; return ret;
} }
@ -670,8 +670,8 @@ pci_driver_handle_bind(const char *path)
struct pciDevice *dev = pci_device_find_by_content(path); struct pciDevice *dev = pci_device_find_by_content(path);
struct pciDriver *driver = pci_driver_find_by_path(path); struct pciDriver *driver = pci_driver_find_by_path(path);
if (!driver || !dev) { if (!driver || !dev || PCI_ACTION_BIND & driver->fail) {
/* This should never happen (TM) */ /* No driver, no device or failing driver requested */
errno = ENODEV; errno = ENODEV;
goto cleanup; goto cleanup;
} }
@ -687,8 +687,8 @@ pci_driver_handle_unbind(const char *path)
int ret = -1; int ret = -1;
struct pciDevice *dev = pci_device_find_by_content(path); struct pciDevice *dev = pci_device_find_by_content(path);
if (!dev || !dev->driver) { if (!dev || !dev->driver || PCI_ACTION_UNBIND & dev->driver->fail) {
/* This should never happen (TM) */ /* No device, device not binded or failing driver requested */
errno = ENODEV; errno = ENODEV;
goto cleanup; goto cleanup;
} }