From c704eb884adfc83c8733c2a2f92200f0d97ff78a Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 18 Jul 2024 18:37:08 +0200 Subject: [PATCH] dri: use static struct init on declaration & drop useless assignments Make the code a bit easier to read by using initialization of the reply structs, at the point of declaration. Most of them aren't written to later, just passed into WriteReplyToClient(). Also dropping some useless zero assignments (struct initializers automatically zero-out unmentioned fields). Signed-off-by: Enrico Weigelt, metux IT consult --- hw/xfree86/dri/xf86dri.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/hw/xfree86/dri/xf86dri.c b/hw/xfree86/dri/xf86dri.c index de4206d18..464396f9d 100644 --- a/hw/xfree86/dri/xf86dri.c +++ b/hw/xfree86/dri/xf86dri.c @@ -80,7 +80,6 @@ ProcXF86DRIQueryVersion(register ClientPtr client) xXF86DRIQueryVersionReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, - .length = 0, .majorVersion = SERVER_XF86DRI_MAJOR_VERSION, .minorVersion = SERVER_XF86DRI_MINOR_VERSION, .patchVersion = SERVER_XF86DRI_PATCH_VERSION @@ -101,7 +100,6 @@ ProcXF86DRIQueryVersion(register ClientPtr client) static int ProcXF86DRIQueryDirectRenderingCapable(register ClientPtr client) { - xXF86DRIQueryDirectRenderingCapableReply rep; Bool isCapable; REQUEST(xXF86DRIQueryDirectRenderingCapableReq); @@ -119,10 +117,9 @@ ProcXF86DRIQueryDirectRenderingCapable(register ClientPtr client) if (!client->local || client->swapped) isCapable = 0; - rep = (xXF86DRIQueryDirectRenderingCapableReply) { + xXF86DRIQueryDirectRenderingCapableReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, - .length = 0, .isCapable = isCapable }; @@ -140,7 +137,6 @@ ProcXF86DRIQueryDirectRenderingCapable(register ClientPtr client) static int ProcXF86DRIOpenConnection(register ClientPtr client) { - xXF86DRIOpenConnectionReply rep; drm_handle_t hSAREA; char *busIdString; CARD32 busIdStringLength = 0; @@ -160,7 +156,7 @@ ProcXF86DRIOpenConnection(register ClientPtr client) if (busIdString) busIdStringLength = strlen(busIdString); - rep = (xXF86DRIOpenConnectionReply) { + xXF86DRIOpenConnectionReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, .length = bytes_to_int32(SIZEOF(xXF86DRIOpenConnectionReply) - @@ -171,8 +167,6 @@ ProcXF86DRIOpenConnection(register ClientPtr client) .hSAREALow = (CARD32) (hSAREA & 0xffffffff), #if defined(LONG64) && !defined(__linux__) .hSAREAHigh = (CARD32) (hSAREA >> 32), -#else - .hSAREAHigh = 0 #endif }; @@ -188,7 +182,6 @@ ProcXF86DRIAuthConnection(register ClientPtr client) xXF86DRIAuthConnectionReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, - .length = 0, .authenticated = 1 }; @@ -228,7 +221,6 @@ ProcXF86DRIGetClientDriverName(register ClientPtr client) xXF86DRIGetClientDriverNameReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, - .clientDriverNameLength = 0 }; char *clientDriverName; @@ -263,7 +255,6 @@ ProcXF86DRICreateContext(register ClientPtr client) xXF86DRICreateContextReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, - .length = 0 }; ScreenPtr pScreen; @@ -309,7 +300,6 @@ ProcXF86DRICreateDrawable(ClientPtr client) xXF86DRICreateDrawableReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, - .length = 0 }; DrawablePtr pDrawable; int rc; @@ -368,11 +358,10 @@ ProcXF86DRIGetDrawableInfo(register ClientPtr client) xXF86DRIGetDrawableInfoReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, - .length = 0 }; DrawablePtr pDrawable; int X, Y, W, H; - drm_clip_rect_t *pClipRects, *pClippedRects; + drm_clip_rect_t *pClipRects, *pClippedRects = NULL; drm_clip_rect_t *pBackClipRects; int backX, backY, rc; @@ -416,8 +405,6 @@ ProcXF86DRIGetDrawableInfo(register ClientPtr client) if (rep.numBackClipRects) rep.length += sizeof(drm_clip_rect_t) * rep.numBackClipRects; - pClippedRects = pClipRects; - if (rep.numClipRects) { /* Clip cliprects to screen dimensions (redirected windows) */ pClippedRects = xallocarray(rep.numClipRects, sizeof(drm_clip_rect_t)); @@ -429,10 +416,12 @@ ProcXF86DRIGetDrawableInfo(register ClientPtr client) int i, j; for (i = 0, j = 0; i < rep.numClipRects; i++) { - pClippedRects[j].x1 = max(pClipRects[i].x1, 0); - pClippedRects[j].y1 = max(pClipRects[i].y1, 0); - pClippedRects[j].x2 = min(pClipRects[i].x2, pScreen->width); - pClippedRects[j].y2 = min(pClipRects[i].y2, pScreen->height); + pClippedRects[j] = (drm_clip_rect_t) { + .x1 = max(pClipRects[i].x1, 0), + .y1 = max(pClipRects[i].y1, 0), + .x2 = min(pClipRects[i].x2, pScreen->width), + .y2 = min(pClipRects[i].y2, pScreen->height), + }; if (pClippedRects[j].x1 < pClippedRects[j].x2 && pClippedRects[j].y1 < pClippedRects[j].y2) { @@ -470,7 +459,6 @@ ProcXF86DRIGetDeviceInfo(register ClientPtr client) xXF86DRIGetDeviceInfoReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, - .length = 0 }; drm_handle_t hFrameBuffer; void *pDevPrivate; @@ -494,8 +482,6 @@ ProcXF86DRIGetDeviceInfo(register ClientPtr client) rep.hFrameBufferLow = (CARD32) (hFrameBuffer & 0xffffffff); #if defined(LONG64) && !defined(__linux__) rep.hFrameBufferHigh = (CARD32) (hFrameBuffer >> 32); -#else - rep.hFrameBufferHigh = 0; #endif if (rep.devPrivateSize) {