Commit cba2af9a authored by Keith Packard's avatar Keith Packard
Browse files

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.

Signed-off-by: Keith Packard's avatarKeith Packard <keithp@keithp.com>
parent 04aa75ae
......@@ -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)
......
......@@ -2595,8 +2595,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++)
......@@ -2716,14 +2716,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;
......@@ -2947,7 +2949,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
......
......@@ -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
*/
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment