Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[xsrc/trunk]: xsrc/external/mit/xorg-server/dist/hw/xfree86/drivers/modesetti...



details:   https://anonhg.NetBSD.org/xsrc/rev/fa150d448a88
branches:  trunk
changeset: 7129:fa150d448a88
user:      mrg <mrg%NetBSD.org@localhost>
date:      Fri Aug 12 08:18:29 2022 +0000

description:
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.

diffstat:

 external/mit/xorg-server/dist/hw/xfree86/drivers/modesetting/drmmode_display.c |  28 ++++++---
 1 files changed, 18 insertions(+), 10 deletions(-)

diffs (60 lines):

diff -r de3f7520a8d7 -r fa150d448a88 external/mit/xorg-server/dist/hw/xfree86/drivers/modesetting/drmmode_display.c
--- a/external/mit/xorg-server/dist/hw/xfree86/drivers/modesetting/drmmode_display.c    Thu Aug 11 23:09:58 2022 +0000
+++ b/external/mit/xorg-server/dist/hw/xfree86/drivers/modesetting/drmmode_display.c    Fri Aug 12 08:18:29 2022 +0000
@@ -1736,16 +1736,23 @@
 }
 
 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 @@
         lut[i].blue = blue[i];
     }
 
-    if (drmModeCreatePropertyBlob(drmmode->fd, lut, sizeof(lut), &blob_id))
-        return;
-
-    drmModeObjectSetProperty(drmmode->fd, crtc_id, DRM_MODE_OBJECT_CRTC,
-                             gamma_lut_info->prop_id, blob_id);
-
-    drmModeDestroyPropertyBlob(drmmode->fd, blob_id);
+    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);
+
+        drmModeDestroyPropertyBlob(drmmode->fd, blob_id);
+    }
+    free(lut);
 }
 
 static void
@@ -1772,7 +1780,7 @@
     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);



Home | Main Index | Thread Index | Old Index