[libvirt] [PATCH 01/18] virpcimock: Move actions checking one level up

Michal Privoznik mprivozn at redhat.com
Wed Aug 14 11:57:30 UTC 2019


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 at redhat.com>
---
 tests/virpcimock.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tests/virpcimock.c b/tests/virpcimock.c
index beb5e1490d..6865f992dc 100644
--- a/tests/virpcimock.c
+++ b/tests/virpcimock.c
@@ -551,8 +551,8 @@ pci_driver_bind(struct pciDriver *driver,
     int ret = -1;
     char *devpath = NULL, *driverpath = NULL;
 
-    if (dev->driver || PCI_ACTION_BIND & driver->fail) {
-        /* Device already bound or failing driver requested */
+    if (dev->driver) {
+        /* Device already bound */
         errno = ENODEV;
         return ret;
     }
@@ -598,8 +598,8 @@ pci_driver_unbind(struct pciDriver *driver,
     int ret = -1;
     char *devpath = NULL, *driverpath = NULL;
 
-    if (dev->driver != driver || PCI_ACTION_UNBIND & driver->fail) {
-        /* Device not bound to the @driver or failing driver used */
+    if (dev->driver != driver) {
+        /* Device not bound to the @driver */
         errno = ENODEV;
         return ret;
     }
@@ -669,8 +669,8 @@ pci_driver_handle_bind(const char *path)
     struct pciDevice *dev = pci_device_find_by_content(path);
     struct pciDriver *driver = pci_driver_find_by_path(path);
 
-    if (!driver || !dev) {
-        /* This should never happen (TM) */
+    if (!driver || !dev || PCI_ACTION_BIND & driver->fail) {
+        /* No driver, no device or failing driver requested */
         errno = ENODEV;
         goto cleanup;
     }
@@ -686,8 +686,8 @@ pci_driver_handle_unbind(const char *path)
     int ret = -1;
     struct pciDevice *dev = pci_device_find_by_content(path);
 
-    if (!dev || !dev->driver) {
-        /* This should never happen (TM) */
+    if (!dev || !dev->driver || PCI_ACTION_UNBIND & dev->driver->fail) {
+        /* No device, device not binded or failing driver requested */
         errno = ENODEV;
         goto cleanup;
     }
-- 
2.21.0




More information about the libvir-list mailing list