diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c index d58ce9326..41181b066 100644 --- a/hw/xfree86/common/xf86Helper.c +++ b/hw/xfree86/common/xf86Helper.c @@ -308,12 +308,11 @@ xf86AllocateScrnInfoPrivateIndex(void) return idx; } -/* Allocate a new InputInfoRec and add it to the head xf86InputDevs. */ - +/* Allocate a new InputInfoRec and append it to the tail of xf86InputDevs. */ _X_EXPORT InputInfoPtr xf86AllocateInput(InputDriverPtr drv, int flags) { - InputInfoPtr new; + InputInfoPtr new, *prev = NULL; if (!(new = xcalloc(sizeof(InputInfoRec), 1))) return NULL; @@ -321,8 +320,13 @@ xf86AllocateInput(InputDriverPtr drv, int flags) new->drv = drv; drv->refCount++; new->module = DuplicateModule(drv->module, NULL); - new->next = xf86InputDevs; - xf86InputDevs = new; + + for (prev = &xf86InputDevs; *prev; prev = &(*prev)->next) + ; + + *prev = new; + new->next = NULL; + return new; }