Allow for missing or disabled compat_output

When the compat output is missing (I don't think this is actually
possible), or is disabled (and hence has no crtc), we would like to
avoid dereferencing NULL pointers. This patch creates inline functions
to extract the current compat output, crtc or associated RandR crtc
structure, carefully checking for NULL pointers everywhere.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit de86a3a344)
This commit is contained in:
Keith Packard 2010-02-25 11:37:05 -08:00 committed by Brice Goglin
parent 7def5cdf7d
commit d023b78c73
4 changed files with 46 additions and 17 deletions

View File

@ -1001,8 +1001,7 @@ xf86ChangeGammaRamp(
CMapLinkPtr pLink;
if (xf86_crtc_supports_gamma(pScrn)) {
xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
RRCrtcPtr crtc = config->output[config->compat_output]->crtc->randr_crtc;
RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn);
if (crtc) {
if (crtc->gammaSize != size)
@ -1076,8 +1075,7 @@ xf86GetGammaRampSize(ScreenPtr pScreen)
CMapScreenPtr pScreenPriv;
if (xf86_crtc_supports_gamma(pScrn)) {
xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
RRCrtcPtr crtc = config->output[config->compat_output]->crtc->randr_crtc;
RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn);
if (crtc)
return crtc->gammaSize;
@ -1106,8 +1104,7 @@ xf86GetGammaRamp(
int shift, sigbits;
if (xf86_crtc_supports_gamma(pScrn)) {
xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
RRCrtcPtr crtc = config->output[config->compat_output]->crtc->randr_crtc;
RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn);
if (crtc) {
if (crtc->gammaSize < size)

View File

@ -2571,8 +2571,8 @@ xf86SetDesiredModes (ScrnInfoPtr scrn)
if (!crtc->enabled)
continue;
if (config->output[config->compat_output]->crtc == crtc)
output = config->output[config->compat_output];
if (xf86CompatOutput(scrn) && xf86CompatCrtc(scrn) == crtc)
output = xf86CompatOutput(scrn);
else
{
for (o = 0; o < config->num_output; o++)
@ -2692,14 +2692,16 @@ xf86SetSingleMode (ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation)
{
xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
Bool ok = TRUE;
xf86OutputPtr compat_output = config->output[config->compat_output];
DisplayModePtr compat_mode;
xf86OutputPtr compat_output;
DisplayModePtr compat_mode = NULL;
int c;
/*
* Let the compat output drive the final mode selection
*/
compat_mode = xf86OutputFindClosestMode (compat_output, desired);
compat_output = xf86CompatOutput(pScrn);
if (compat_output)
compat_mode = xf86OutputFindClosestMode (compat_output, desired);
if (compat_mode)
desired = compat_mode;
@ -2894,7 +2896,7 @@ xf86OutputSetEDID (xf86OutputPtr output, xf86MonPtr edid_mon)
}
/* Set the DDC properties for the 'compat' output */
if (output == config->output[config->compat_output])
if (output == xf86CompatOutput(scrn))
xf86SetDDCproperties(scrn, edid_mon);
#ifdef RANDR_12_INTERFACE

View File

@ -689,6 +689,32 @@ extern _X_EXPORT int xf86CrtcConfigPrivateIndex;
#define XF86_CRTC_CONFIG_PTR(p) ((xf86CrtcConfigPtr) ((p)->privates[xf86CrtcConfigPrivateIndex].ptr))
static _X_INLINE xf86OutputPtr
xf86CompatOutput(ScrnInfoPtr pScrn)
{
xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
return config->output[config->compat_output];
}
static _X_INLINE xf86CrtcPtr
xf86CompatCrtc(ScrnInfoPtr pScrn)
{
xf86OutputPtr compat_output = xf86CompatOutput(pScrn);
if (!compat_output)
return NULL;
return compat_output->crtc;
}
static _X_INLINE RRCrtcPtr
xf86CompatRRCrtc(ScrnInfoPtr pScrn)
{
xf86CrtcPtr compat_crtc = xf86CompatCrtc(pScrn);
if (!compat_crtc)
return NULL;
return compat_crtc->randr_crtc;
}
/*
* Initialize xf86CrtcConfig structure
*/

View File

@ -805,9 +805,10 @@ xf86RandR12CreateScreenResources (ScreenPtr pScreen)
}
else
{
xf86OutputPtr output = config->output[config->compat_output];
xf86OutputPtr output = xf86CompatOutput(pScrn);
if (output->conf_monitor &&
if (output &&
output->conf_monitor &&
(output->conf_monitor->mon_width > 0 &&
output->conf_monitor->mon_height > 0))
{
@ -1719,10 +1720,13 @@ xf86RandR12ChangeGamma(int scrnIndex, Gamma gamma)
{
CARD16 *points, *red, *green, *blue;
ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
RRCrtcPtr crtc = config->output[config->compat_output]->crtc->randr_crtc;
int size = max(0, crtc->gammaSize);
RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn);
int size;
if (!crtc)
return Success;
size = max(0, crtc->gammaSize);
if (!size)
return Success;