pipe-loader: simplify pipe_loader_drm_probe
authorEmil Velikov <emil.l.velikov@gmail.com>
Tue, 30 Jun 2015 14:53:27 +0000 (15:53 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Mon, 13 Jul 2015 18:56:39 +0000 (19:56 +0100)
Do not iterate and (attempt to) open the render device, if we're over
the requested number of devices.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c

index 009e1dfdf6fc707251a5c1d4dd3ca998ba1043bc..1ff5f3e8df8256b9beb7bb22e26c7e8271ed63a7 100644 (file)
@@ -180,12 +180,13 @@ open_drm_render_node_minor(int minor)
 int
 pipe_loader_drm_probe(struct pipe_loader_device **devs, int ndev)
 {
+   struct pipe_loader_device *dev;
    int i, j, fd;
 
    for (i = DRM_RENDER_NODE_MIN_MINOR, j = 0;
-        i <= DRM_RENDER_NODE_MAX_MINOR; i++) {
+        i <= DRM_RENDER_NODE_MAX_MINOR && j < ndev; i++) {
+
       fd = open_drm_render_node_minor(i);
-      struct pipe_loader_device *dev;
       if (fd < 0)
          continue;
 
@@ -194,13 +195,7 @@ pipe_loader_drm_probe(struct pipe_loader_device **devs, int ndev)
          continue;
       }
 
-      if (j < ndev) {
-         devs[j] = dev;
-      } else {
-         close(fd);
-         dev->ops->release(&dev);
-      }
-      j++;
+      devs[j++] = dev;
    }
 
    return j;