st/dri: NULL check the pscreen earlier
authorEmil Velikov <emil.l.velikov@gmail.com>
Wed, 14 Oct 2015 23:46:26 +0000 (00:46 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Sat, 21 Nov 2015 12:52:20 +0000 (12:52 +0000)
We delay the null check only to jump through hoops to work around that.
Check early to make our lives easier.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Acked-by: Rob Clark <robclark@freedesktop.org>
src/gallium/state_trackers/dri/dri2.c
src/gallium/state_trackers/dri/dri_screen.c
src/gallium/state_trackers/dri/drisw.c

index 5b7be64ba5a0bc1b5a4e24f4c69ba87845a9b308..beb0866c83fac605d49228b76c3e83052cef25fd 100644 (file)
@@ -1444,8 +1444,8 @@ dri2_init_screen(__DRIscreen * sPriv)
    const __DRIconfig **configs;
    struct dri_screen *screen;
    struct pipe_screen *pscreen = NULL;
-   const struct drm_conf_ret *throttle_ret = NULL;
-   const struct drm_conf_ret *dmabuf_ret = NULL;
+   const struct drm_conf_ret *throttle_ret;
+   const struct drm_conf_ret *dmabuf_ret;
 
    screen = CALLOC_STRUCT(dri_screen);
    if (!screen)
@@ -1457,12 +1457,14 @@ dri2_init_screen(__DRIscreen * sPriv)
 
    sPriv->driverPrivate = (void *)screen;
 
-   if (pipe_loader_drm_probe_fd(&screen->dev, dup(screen->fd))) {
+   if (pipe_loader_drm_probe_fd(&screen->dev, dup(screen->fd)))
       pscreen = pipe_loader_create_screen(screen->dev);
 
-      throttle_ret = pipe_loader_configuration(screen->dev, DRM_CONF_THROTTLE);
-      dmabuf_ret = pipe_loader_configuration(screen->dev, DRM_CONF_SHARE_FD);
-   }
+   if (!pscreen)
+       goto fail;
+
+   throttle_ret = pipe_loader_configuration(screen->dev, DRM_CONF_THROTTLE);
+   dmabuf_ret = pipe_loader_configuration(screen->dev, DRM_CONF_SHARE_FD);
 
    if (throttle_ret && throttle_ret->val.val_int != -1) {
       screen->throttling_enabled = TRUE;
@@ -1479,15 +1481,13 @@ dri2_init_screen(__DRIscreen * sPriv)
       }
    }
 
-   if (pscreen && pscreen->get_param(pscreen, PIPE_CAP_DEVICE_RESET_STATUS_QUERY)) {
+   if (pscreen->get_param(pscreen, PIPE_CAP_DEVICE_RESET_STATUS_QUERY)) {
       sPriv->extensions = dri_robust_screen_extensions;
       screen->has_reset_status_query = true;
    }
    else
       sPriv->extensions = dri_screen_extensions;
 
-   /* dri_init_screen_helper checks pscreen for us */
-
    configs = dri_init_screen_helper(screen, pscreen, screen->dev->driver_name);
    if (!configs)
       goto fail;
@@ -1532,6 +1532,9 @@ dri_kms_init_screen(__DRIscreen * sPriv)
    if (pipe_loader_sw_probe_kms(&screen->dev, dup(screen->fd)))
       pscreen = pipe_loader_create_screen(screen->dev);
 
+   if (!pscreen)
+       goto fail;
+
    if (drmGetCap(sPriv->fd, DRM_CAP_PRIME, &cap) == 0 &&
           (cap & DRM_PRIME_CAP_IMPORT)) {
       dri2ImageExtension.createImageFromFds = dri2_from_fds;
@@ -1540,7 +1543,6 @@ dri_kms_init_screen(__DRIscreen * sPriv)
 
    sPriv->extensions = dri_screen_extensions;
 
-   /* dri_init_screen_helper checks pscreen for us */
    configs = dri_init_screen_helper(screen, pscreen, "swrast");
    if (!configs)
       goto fail;
index cf0f26554d37ed550d341d6f28733a68344fc005..2ac55c88926c3785ca463162db0c547efd178f46 100644 (file)
@@ -414,11 +414,6 @@ dri_init_screen_helper(struct dri_screen *screen,
                        const char* driver_name)
 {
    screen->base.screen = pscreen;
-   if (!screen->base.screen) {
-      debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__);
-      return NULL;
-   }
-
    screen->base.get_egl_image = dri_get_egl_image;
    screen->base.get_param = dri_get_param;
 
index 06fa94276675f4b35bbda1be5b74191bf6818b01..b85a73c57d2fe35eb812ea447d9f031504b77053 100644 (file)
@@ -400,7 +400,8 @@ drisw_init_screen(__DRIscreen * sPriv)
    if (pipe_loader_sw_probe_dri(&screen->dev, &drisw_lf))
       pscreen = pipe_loader_create_screen(screen->dev);
 
-   /* dri_init_screen_helper checks pscreen for us */
+   if (!pscreen)
+      goto fail;
 
    configs = dri_init_screen_helper(screen, pscreen, "swrast");
    if (!configs)