From 92272378064a878ce7a62852b877d674bcad89cd Mon Sep 17 00:00:00 2001 From: Jeffrey Smith Date: Thu, 15 Feb 2018 06:46:55 -0600 Subject: [PATCH] modesetting: Do not close uninitialized dri2 screen If a dri2 screen is not successfully initialized, attempting to close it results in a null dereference. Maintain a flag indicating whether the dri2 screen was successfully initialized, and check it before attempting to close the dri2 screen. https://bugzilla.redhat.com/show_bug.cgi?id=1485811 https://bugzilla.redhat.com/show_bug.cgi?id=1493805 https://bugzilla.redhat.com/show_bug.cgi?id=1534459 https://bugzilla.redhat.com/show_bug.cgi?id=1541745 https://bugs.freedesktop.org/show_bug.cgi?id=101282 Signed-off-by: Jeff Smith --- hw/xfree86/drivers/modesetting/driver.c | 6 +++--- hw/xfree86/drivers/modesetting/drmmode_display.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index e057970a6..4c6726ce5 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -1685,12 +1685,12 @@ ScreenInit(ScreenPtr pScreen, int argc, char **argv) #ifdef GLAMOR_HAS_GBM if (ms->drmmode.glamor) { - if (!ms_dri2_screen_init(pScreen)) { + if (!(ms->drmmode.dri2_enable = ms_dri2_screen_init(pScreen))) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to initialize the DRI2 extension.\n"); } - if (!ms_present_screen_init(pScreen)) { + if (!(ms->drmmode.present_enable = ms_present_screen_init(pScreen))) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to initialize the Present extension.\n"); } @@ -1783,7 +1783,7 @@ CloseScreen(ScreenPtr pScreen) ms_ent->assigned_crtcs = 0; #ifdef GLAMOR_HAS_GBM - if (ms->drmmode.glamor) { + if (ms->drmmode.dri2_enable) { ms_dri2_close_screen(pScreen); } #endif diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h index 2630f9347..65e127c52 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.h +++ b/hw/xfree86/drivers/modesetting/drmmode_display.h @@ -83,6 +83,9 @@ typedef struct { Bool dri2_flipping; Bool present_flipping; + + Bool dri2_enable; + Bool present_enable; } drmmode_rec, *drmmode_ptr; typedef struct {