Module Name:    xsrc
Committed By:   mrg
Date:           Fri Aug 12 08:18:29 UTC 2022

Modified Files:
        xsrc/external/mit/xorg-server/dist/hw/xfree86/drivers/modesetting:
            drmmode_display.c

Log Message:
avoid variable stack arrays.

USE_SSP=yes builds don't work with this new xorg-server version, adjust
the drmmode_set_gamma_lut() call to use malloc() instead of the stack,
and pass down a higher level pointer to gain access to the screen index
so error messages with xf86DrvMsg() work.

tested on pinebookpro.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 \
    
xsrc/external/mit/xorg-server/dist/hw/xfree86/drivers/modesetting/drmmode_display.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: xsrc/external/mit/xorg-server/dist/hw/xfree86/drivers/modesetting/drmmode_display.c
diff -u xsrc/external/mit/xorg-server/dist/hw/xfree86/drivers/modesetting/drmmode_display.c:1.10 xsrc/external/mit/xorg-server/dist/hw/xfree86/drivers/modesetting/drmmode_display.c:1.11
--- xsrc/external/mit/xorg-server/dist/hw/xfree86/drivers/modesetting/drmmode_display.c:1.10	Wed Jul 20 03:51:16 2022
+++ xsrc/external/mit/xorg-server/dist/hw/xfree86/drivers/modesetting/drmmode_display.c	Fri Aug 12 08:18:29 2022
@@ -1736,16 +1736,23 @@ drmmode_show_cursor(xf86CrtcPtr crtc)
 }
 
 static void
-drmmode_set_gamma_lut(drmmode_crtc_private_ptr drmmode_crtc,
+drmmode_set_gamma_lut(xf86CrtcPtr crtc,
                       uint16_t * red, uint16_t * green, uint16_t * blue,
                       int size)
 {
+    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
     drmmode_ptr drmmode = drmmode_crtc->drmmode;
     drmmode_prop_info_ptr gamma_lut_info =
         &drmmode_crtc->props[DRMMODE_CRTC_GAMMA_LUT];
     const uint32_t crtc_id = drmmode_crtc->mode_crtc->crtc_id;
     uint32_t blob_id;
-    struct drm_color_lut lut[size];
+    struct drm_color_lut *lut = malloc(sizeof(*lut) * size);
+
+    if (lut == NULL) {
+        xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
+                   "Failed to allocate memory for %d LUT entries.\n", size);
+	return;
+    }
 
     assert(gamma_lut_info->prop_id != 0);
 
@@ -1755,13 +1762,14 @@ drmmode_set_gamma_lut(drmmode_crtc_priva
         lut[i].blue = blue[i];
     }
 
-    if (drmModeCreatePropertyBlob(drmmode->fd, lut, sizeof(lut), &blob_id))
-        return;
+    if (!drmModeCreatePropertyBlob(drmmode->fd, lut, sizeof(lut), &blob_id)) {
 
-    drmModeObjectSetProperty(drmmode->fd, crtc_id, DRM_MODE_OBJECT_CRTC,
-                             gamma_lut_info->prop_id, blob_id);
+        drmModeObjectSetProperty(drmmode->fd, crtc_id, DRM_MODE_OBJECT_CRTC,
+                                 gamma_lut_info->prop_id, blob_id);
 
-    drmModeDestroyPropertyBlob(drmmode->fd, blob_id);
+        drmModeDestroyPropertyBlob(drmmode->fd, blob_id);
+    }
+    free(lut);
 }
 
 static void
@@ -1772,7 +1780,7 @@ drmmode_crtc_gamma_set(xf86CrtcPtr crtc,
     drmmode_ptr drmmode = drmmode_crtc->drmmode;
 
     if (drmmode_crtc->use_gamma_lut) {
-        drmmode_set_gamma_lut(drmmode_crtc, red, green, blue, size);
+        drmmode_set_gamma_lut(crtc, red, green, blue, size);
     } else {
         drmModeCrtcSetGamma(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
                             size, red, green, blue);

Reply via email to