[PATCH xserver 4/7] modesetting: Check mode in drmmode_set_mode_major() first

Daniel Martin consume.noise at gmail.com
Mon Nov 20 10:02:07 UTC 2017


We don't do anything in drmmode_set_mode_major() without a mode. Check
it at the beginning and may bail out. With that, we can remove one
indention level. No functional changes.

Signed-off-by: Daniel Martin <consume.noise at gmail.com>
---
 hw/xfree86/drivers/modesetting/drmmode_display.c | 165 +++++++++++------------
 1 file changed, 82 insertions(+), 83 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index d8dd4d75f..66cc9c06a 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -597,17 +597,18 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
     uint32_t fb_id = 0;
     drmModeModeInfo kmode;
 
+    if (!mode)
+        return TRUE;
+
     saved_mode = crtc->mode;
     saved_x = crtc->x;
     saved_y = crtc->y;
     saved_rotation = crtc->rotation;
 
-    if (mode) {
-        crtc->mode = *mode;
-        crtc->x = x;
-        crtc->y = y;
-        crtc->rotation = rotation;
-    }
+    crtc->mode = *mode;
+    crtc->x = x;
+    crtc->y = y;
+    crtc->rotation = rotation;
 
     output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
     if (!output_ids) {
@@ -615,91 +616,89 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
         goto done;
     }
 
-    if (mode) {
-        for (i = 0; i < xf86_config->num_output; i++) {
-            xf86OutputPtr output = xf86_config->output[i];
-            drmmode_output_private_ptr drmmode_output;
+    for (i = 0; i < xf86_config->num_output; i++) {
+        xf86OutputPtr output = xf86_config->output[i];
+        drmmode_output_private_ptr drmmode_output;
 
-            if (output->crtc != crtc)
-                continue;
+        if (output->crtc != crtc)
+            continue;
 
-            drmmode_output = output->driver_private;
-            if (drmmode_output->output_id == -1)
-                continue;
-            output_ids[output_count] = drmmode_output->output_id;
-            output_count++;
-        }
+        drmmode_output = output->driver_private;
+        if (drmmode_output->output_id == -1)
+            continue;
+        output_ids[output_count] = drmmode_output->output_id;
+        output_count++;
+    }
 
-        if (!xf86CrtcRotate(crtc)) {
-            goto done;
-        }
-        crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green,
-                               crtc->gamma_blue, crtc->gamma_size);
+    if (!xf86CrtcRotate(crtc)) {
+        goto done;
+    }
+    crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green,
+                           crtc->gamma_blue, crtc->gamma_size);
 
-        drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
+    drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
 
-        fb_id = drmmode->fb_id;
-        if (drmmode_crtc->prime_pixmap) {
-            if (!drmmode->reverse_prime_offload_mode) {
-                msPixmapPrivPtr ppriv =
-                    msGetPixmapPriv(drmmode, drmmode_crtc->prime_pixmap);
-                fb_id = ppriv->fb_id;
-                x = 0;
-            } else
-                x = drmmode_crtc->prime_pixmap_x;
-            y = 0;
-        }
-        else if (drmmode_crtc->rotate_fb_id) {
-            fb_id = drmmode_crtc->rotate_fb_id;
-            x = y = 0;
-        }
-
-        if (fb_id == 0) {
-            ret = drmModeAddFB(drmmode->fd,
-                               pScrn->virtualX, pScrn->virtualY,
-                               pScrn->depth, drmmode->kbpp,
-                               drmmode_bo_get_pitch(&drmmode->front_bo),
-                               drmmode_bo_get_handle(&drmmode->front_bo),
-                               &drmmode->fb_id);
-            if (ret < 0) {
-                ErrorF("failed to add fb %d\n", ret);
-                ret = FALSE;
-                goto done;
-            }
-            fb_id = drmmode->fb_id;
-        }
-
-        if (drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
-                           fb_id, x, y, output_ids, output_count, &kmode)) {
-            xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
-                       "failed to set mode: %s\n", strerror(errno));
-            ret = FALSE;
-            goto done;
+    fb_id = drmmode->fb_id;
+    if (drmmode_crtc->prime_pixmap) {
+        if (!drmmode->reverse_prime_offload_mode) {
+            msPixmapPrivPtr ppriv =
+                msGetPixmapPriv(drmmode, drmmode_crtc->prime_pixmap);
+            fb_id = ppriv->fb_id;
+            x = 0;
         } else
-            ret = TRUE;
+            x = drmmode_crtc->prime_pixmap_x;
+        y = 0;
+    }
+    else if (drmmode_crtc->rotate_fb_id) {
+        fb_id = drmmode_crtc->rotate_fb_id;
+        x = y = 0;
+    }
 
-        if (crtc->scrn->pScreen)
-            xf86CrtcSetScreenSubpixelOrder(crtc->scrn->pScreen);
-
-        drmmode_crtc->need_modeset = FALSE;
-        crtc->funcs->dpms(crtc, DPMSModeOn);
-
-        if (drmmode_crtc->prime_pixmap_back)
-            drmmode_InitSharedPixmapFlipping(crtc, drmmode);
-
-        /* go through all the outputs and force DPMS them back on? */
-        for (i = 0; i < xf86_config->num_output; i++) {
-            xf86OutputPtr output = xf86_config->output[i];
-            drmmode_output_private_ptr drmmode_output;
-
-            if (output->crtc != crtc)
-                continue;
-
-            drmmode_output = output->driver_private;
-            if (drmmode_output->output_id == -1)
-                continue;
-            output->funcs->dpms(output, DPMSModeOn);
+    if (fb_id == 0) {
+        ret = drmModeAddFB(drmmode->fd,
+                           pScrn->virtualX, pScrn->virtualY,
+                           pScrn->depth, drmmode->kbpp,
+                           drmmode_bo_get_pitch(&drmmode->front_bo),
+                           drmmode_bo_get_handle(&drmmode->front_bo),
+                           &drmmode->fb_id);
+        if (ret < 0) {
+            ErrorF("failed to add fb %d\n", ret);
+            ret = FALSE;
+            goto done;
         }
+        fb_id = drmmode->fb_id;
+    }
+
+    if (drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+                       fb_id, x, y, output_ids, output_count, &kmode)) {
+        xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
+                   "failed to set mode: %s\n", strerror(errno));
+        ret = FALSE;
+        goto done;
+    } else
+        ret = TRUE;
+
+    if (crtc->scrn->pScreen)
+        xf86CrtcSetScreenSubpixelOrder(crtc->scrn->pScreen);
+
+    drmmode_crtc->need_modeset = FALSE;
+    crtc->funcs->dpms(crtc, DPMSModeOn);
+
+    if (drmmode_crtc->prime_pixmap_back)
+        drmmode_InitSharedPixmapFlipping(crtc, drmmode);
+
+    /* go through all the outputs and force DPMS them back on? */
+    for (i = 0; i < xf86_config->num_output; i++) {
+        xf86OutputPtr output = xf86_config->output[i];
+        drmmode_output_private_ptr drmmode_output;
+
+        if (output->crtc != crtc)
+            continue;
+
+        drmmode_output = output->driver_private;
+        if (drmmode_output->output_id == -1)
+            continue;
+        output->funcs->dpms(output, DPMSModeOn);
     }
 
  done:
-- 
2.13.6



More information about the xorg-devel mailing list