From d00fdcc875322edd20d97781c3e83d2e2fbd4d0e Mon Sep 17 00:00:00 2001 From: Stuart Bennett Date: Sat, 7 Feb 2009 16:40:46 +0000 Subject: [PATCH] randr12: anti-crash measures and consistency fix for #19854 --- src/nv_output.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/src/nv_output.c b/src/nv_output.c index a28a342..e4218d4 100644 --- a/src/nv_output.c +++ b/src/nv_output.c @@ -147,6 +147,16 @@ update_output_fields(xf86OutputPtr output, struct nouveau_encoder *det_encoder) } } +static void clear_output_fields(xf86OutputPtr output) +{ + struct nouveau_connector *nv_connector = to_nouveau_connector(output); + + nv_connector->detected_encoder = NULL; + output->possible_crtcs = 0; + output->doubleScanAllowed = false; + output->interlaceAllowed = false; +} + static bool edid_sink_connected(xf86OutputPtr output) { struct nouveau_connector *nv_connector = to_nouveau_connector(output); @@ -215,6 +225,8 @@ nv_output_detect(xf86OutputPtr output) if (ret != XF86OutputStatusDisconnected) update_output_fields(output, det_encoder); + else /* return to "as started" state, for consistency */ + clear_output_fields(output); return ret; } @@ -321,6 +333,12 @@ static int nv_output_mode_valid(xf86OutputPtr output, DisplayModePtr mode) struct nouveau_encoder *nv_encoder = to_nouveau_connector(output)->detected_encoder; NVPtr pNv = NVPTR(output->scrn); + /* mode_valid can be called by someone doing addmode on an output + * which is disconnected and so without an encoder; avoid crashing + */ + if (!nv_encoder) + return MODE_ERROR; + if (!output->doubleScanAllowed && mode->Flags & V_DBLSCAN) return MODE_NO_DBLESCAN; if (!output->interlaceAllowed && mode->Flags & V_INTERLACE) -- 1.5.4.4