loader: simplify codeflow in drm_get_pci_id_for_fd
authorEmil Velikov <emil.velikov@collabora.com>
Thu, 5 Mar 2020 13:50:46 +0000 (13:50 +0000)
committerEmil Velikov <emil.l.velikov@gmail.com>
Wed, 1 Apr 2020 15:57:22 +0000 (16:57 +0100)
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4084>

src/loader/loader.c

index 1a438a4fcc76695af1a789a88394d7eec49983e7..a2e726465af87726179e56b07cadb35adfbdbcc7 100644 (file)
@@ -385,26 +385,22 @@ static bool
 drm_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
 {
    drmDevicePtr device;
 drm_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
 {
    drmDevicePtr device;
-   bool ret;
 
 
-   if (drmGetDevice2(fd, 0, &device) == 0) {
-      if (device->bustype == DRM_BUS_PCI) {
-         *vendor_id = device->deviceinfo.pci->vendor_id;
-         *chip_id = device->deviceinfo.pci->device_id;
-         ret = true;
-      }
-      else {
-         log_(_LOADER_DEBUG, "MESA-LOADER: device is not located on the PCI bus\n");
-         ret = false;
-      }
-      drmFreeDevice(&device);
-   }
-   else {
+   if (drmGetDevice2(fd, 0, &device) != 0) {
       log_(_LOADER_WARNING, "MESA-LOADER: failed to retrieve device information\n");
       log_(_LOADER_WARNING, "MESA-LOADER: failed to retrieve device information\n");
-      ret = false;
+      return false;
    }
 
    }
 
-   return ret;
+   if (device->bustype != DRM_BUS_PCI) {
+      drmFreeDevice(&device);
+      log_(_LOADER_DEBUG, "MESA-LOADER: device is not located on the PCI bus\n");
+      return false;
+   }
+
+   *vendor_id = device->deviceinfo.pci->vendor_id;
+   *chip_id = device->deviceinfo.pci->device_id;
+   drmFreeDevice(&device);
+   return true;
 }
 #endif
 
 }
 #endif