Commit a4210fe0 authored by Łukasz Spintzyk's avatar Łukasz Spintzyk
Browse files

xfree86: Change displays array to pointers array to fix invalid pointer issues...


xfree86: Change displays array to pointers array to fix invalid pointer issues after table reallocation

There are rare cases when xf86SetDepthBpp is resizing displays array in confScreen.
As that array is shared between set of ScrnInfoRec's then realloc might invalidate chached DispPtr display values in
otheres ScrnInfoRec objects.

If we will change displays array as an array of pointers to DispRec then cached DispRec pointers in ScrnInfoRec
won't be invalid after reallocation of displays array.
Signed-off-by: Łukasz Spintzyk's avatarŁukasz Spintzyk <lukasz.spintzyk@synaptics.com>
(cherry picked from commit f8a6be04)
parent 22449f63
Pipeline #339807 passed with stages
in 6 minutes and 15 seconds
......@@ -1760,7 +1760,7 @@ configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum,
count++;
dispptr = (XF86ConfDisplayPtr) dispptr->list.next;
}
screenp->displays = xnfallocarray(count, sizeof(DispRec));
screenp->displays = xnfallocarray(count, sizeof(DispPtr));
screenp->numdisplays = count;
/* Fill in the default Virtual size, if any */
......@@ -1768,8 +1768,9 @@ configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum,
for (count = 0, dispptr = conf_screen->scrn_display_lst;
dispptr;
dispptr = (XF86ConfDisplayPtr) dispptr->list.next, count++) {
screenp->displays[count].virtualX = conf_screen->scrn_virtualX;
screenp->displays[count].virtualY = conf_screen->scrn_virtualY;
screenp->displays[count] = xnfcalloc(1, sizeof(DispRec));
screenp->displays[count]->virtualX = conf_screen->scrn_virtualX;
screenp->displays[count]->virtualY = conf_screen->scrn_virtualY;
}
}
......@@ -1777,7 +1778,7 @@ configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum,
count = 0;
dispptr = conf_screen->scrn_display_lst;
while (dispptr) {
configDisplay(&(screenp->displays[count]), dispptr);
configDisplay(screenp->displays[count], dispptr);
count++;
dispptr = (XF86ConfDisplayPtr) dispptr->list.next;
}
......@@ -1785,6 +1786,7 @@ configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum,
/*
* figure out how many videoadaptor references there are and fill them in
*/
count = 0;
conf_adaptor = conf_screen->scrn_adaptor_lst;
while (conf_adaptor) {
count++;
......
......@@ -525,8 +525,8 @@ xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp,
* Find the Display subsection matching the depth/fbbpp and initialise
* scrp->display with it.
*/
for (i = 0, disp = scrp->confScreen->displays;
i < scrp->confScreen->numdisplays; i++, disp++) {
for (i = 0; i < scrp->confScreen->numdisplays; i++) {
disp = scrp->confScreen->displays[i];
if ((disp->depth == scrp->depth && disp->fbbpp == scrp->bitsPerPixel)
|| (disp->depth == scrp->depth && disp->fbbpp <= 0)
|| (disp->fbbpp == scrp->bitsPerPixel && disp->depth <= 0)) {
......@@ -540,8 +540,8 @@ xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp,
* depth or fbbpp specified.
*/
if (i == scrp->confScreen->numdisplays) {
for (i = 0, disp = scrp->confScreen->displays;
i < scrp->confScreen->numdisplays; i++, disp++) {
for (i = 0; i < scrp->confScreen->numdisplays; i++) {
disp = scrp->confScreen->displays[i];
if (disp->depth <= 0 && disp->fbbpp <= 0) {
scrp->display = disp;
break;
......@@ -556,24 +556,25 @@ xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp,
scrp->confScreen->numdisplays++;
scrp->confScreen->displays =
xnfreallocarray(scrp->confScreen->displays,
scrp->confScreen->numdisplays, sizeof(DispRec));
scrp->confScreen->numdisplays, sizeof(DispPtr));
xf86DrvMsg(scrp->scrnIndex, X_INFO,
"Creating default Display subsection in Screen section\n"
"\t\"%s\" for depth/fbbpp %d/%d\n",
scrp->confScreen->id, scrp->depth, scrp->bitsPerPixel);
memset(&scrp->confScreen->displays[i], 0, sizeof(DispRec));
scrp->confScreen->displays[i].blackColour.red = -1;
scrp->confScreen->displays[i].blackColour.green = -1;
scrp->confScreen->displays[i].blackColour.blue = -1;
scrp->confScreen->displays[i].whiteColour.red = -1;
scrp->confScreen->displays[i].whiteColour.green = -1;
scrp->confScreen->displays[i].whiteColour.blue = -1;
scrp->confScreen->displays[i].defaultVisual = -1;
scrp->confScreen->displays[i].modes = xnfalloc(sizeof(char *));
scrp->confScreen->displays[i].modes[0] = NULL;
scrp->confScreen->displays[i].depth = depth;
scrp->confScreen->displays[i].fbbpp = fbbpp;
scrp->display = &scrp->confScreen->displays[i];
scrp->confScreen->displays[i] = xnfcalloc(1, sizeof(DispRec));
memset(scrp->confScreen->displays[i], 0, sizeof(DispRec));
scrp->confScreen->displays[i]->blackColour.red = -1;
scrp->confScreen->displays[i]->blackColour.green = -1;
scrp->confScreen->displays[i]->blackColour.blue = -1;
scrp->confScreen->displays[i]->whiteColour.red = -1;
scrp->confScreen->displays[i]->whiteColour.green = -1;
scrp->confScreen->displays[i]->whiteColour.blue = -1;
scrp->confScreen->displays[i]->defaultVisual = -1;
scrp->confScreen->displays[i]->modes = xnfalloc(sizeof(char *));
scrp->confScreen->displays[i]->modes[0] = NULL;
scrp->confScreen->displays[i]->depth = depth;
scrp->confScreen->displays[i]->fbbpp = fbbpp;
scrp->display = scrp->confScreen->displays[i];
}
/*
......
......@@ -349,7 +349,7 @@ typedef struct _confscreenrec {
MonPtr monitor;
GDevPtr device;
int numdisplays;
DispPtr displays;
DispPtr *displays;
int numxvadaptors;
confXvAdaptorPtr xvadaptors;
void *options;
......
Markdown is supported
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