[PATCH v2] Allow driver to call DeleteInputDeviceRequest during UnInit

Simon Thum simon.thum at gmx.de
Mon Jan 18 00:30:55 PST 2010


Peter Hutterer wrote:
> On Fri, Jan 15, 2010 at 10:40:02AM +0100, Simon Thum wrote:
>> Oldřich Jedlička wrote:
>>> When the input driver (like xf86-input-wacom) removes it's devices
>>> during a call to UnInit, the CloseDownDevices() cannot handle it. The
>>> "next" variable can become a pointer to freed memory.
>>>
>>> The patch introduces order-independent device freeing mechanism by
>>> remembering the already freed device ids. The devices can reorder any
>>> time during freeing. No device will be double-freed - if the removing
>>> failed for any reason; some implementations of DeleteInputDeviceRequest
>>> don't free the devices already.
>>>
>>> Signed-off-by: Oldřich Jedlička <oldium.pro at seznam.cz>
>>> ---
>>>  dix/devices.c |   42 +++++++++++++++++++++++++++++++-----------
>>>  1 files changed, 31 insertions(+), 11 deletions(-)
>>>
>>> diff --git dix/devices.c dix/devices.c
>>> index 245a95b..dce0f12 100644
>>> --- dix/devices.c
>>> +++ dix/devices.c
>>> @@ -878,13 +878,41 @@ CloseDevice(DeviceIntPtr dev)
>>>  }
>>>  
>>>  /**
>>> + * Shut down all devices of one list and free all resources.
>>> + */
>>> +static
>>> +void
>>> +CloseListDevices(DeviceIntPtr *listHead)
>>> +{
>>> +    /* Used to mark devices that we tried to free */
>>> +    Bool freedIds[MAXDEVICES] = { 0 };
>> This would only work if UnInit()s removals are somehow forced onto
>> freedIds. In any case the freed array is a sort of context that's not
>> easy to get right. I'm CC'ing Peter, maybe he's got a better idea.
> 
> yes, you're right. this solution could work though if the ID array was
> shared between CloseDevice and this function here. Any device calls
> CloseDevice at some point, so this is the best point you can fill in the ID
> array.
Yes, that's what I thought initially. I rethought because CD may be
called twice on any ID if it was reused during server lifetime.

But more importantly, I'm not right. Oldrichs solution works because he
always re-travels the list from start, which should properly exclude
devices removed in-between. Heck, it would probably even work for
devices added during UnInit().

I already apologized and added my reviewed-by in another mail, which is
probably elsewhere in your queue ;)
> 
> Cheers,
>   Peter
> 



More information about the xorg-devel mailing list