dix: factor out the duplicate the RemoveDevice code paths
This is the same loop twice, once over inputInfo.devices and once over inputInfo.off_devices, let's make both the same.
This commit is contained in:
parent
e44e9262df
commit
0a9f223eec
|
@ -1134,6 +1134,26 @@ UndisplayDevices(void)
|
||||||
screen->DisplayCursor(dev, screen, NullCursor);
|
screen->DisplayCursor(dev, screen, NullCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
CloseOneDevice(const DeviceIntPtr dev, DeviceIntPtr *listHead)
|
||||||
|
{
|
||||||
|
DeviceIntPtr tmp, next, prev = NULL;
|
||||||
|
|
||||||
|
for (tmp = *listHead; tmp; (prev = tmp), (tmp = next)) {
|
||||||
|
next = tmp->next;
|
||||||
|
if (tmp == dev) {
|
||||||
|
if (prev == NULL)
|
||||||
|
*listHead = next;
|
||||||
|
else
|
||||||
|
prev->next = next;
|
||||||
|
|
||||||
|
CloseDevice(tmp);
|
||||||
|
return Success;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return BadMatch;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a device from the device list, closes it and thus frees all
|
* Remove a device from the device list, closes it and thus frees all
|
||||||
* resources.
|
* resources.
|
||||||
|
@ -1150,12 +1170,12 @@ UndisplayDevices(void)
|
||||||
int
|
int
|
||||||
RemoveDevice(DeviceIntPtr dev, BOOL sendevent)
|
RemoveDevice(DeviceIntPtr dev, BOOL sendevent)
|
||||||
{
|
{
|
||||||
DeviceIntPtr prev, tmp, next;
|
|
||||||
int ret = BadMatch;
|
int ret = BadMatch;
|
||||||
ScreenPtr screen = screenInfo.screens[0];
|
ScreenPtr screen = screenInfo.screens[0];
|
||||||
int deviceid;
|
int deviceid;
|
||||||
int initialized;
|
int initialized;
|
||||||
int flags[MAXDEVICES] = { 0 };
|
int flags[MAXDEVICES] = { 0 };
|
||||||
|
int flag;
|
||||||
|
|
||||||
DebugF("(dix) removing device %d\n", dev->id);
|
DebugF("(dix) removing device %d\n", dev->id);
|
||||||
|
|
||||||
|
@ -1173,41 +1193,13 @@ RemoveDevice(DeviceIntPtr dev, BOOL sendevent)
|
||||||
flags[dev->id] = XIDeviceDisabled;
|
flags[dev->id] = XIDeviceDisabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flag = IsMaster(dev) ? XIMasterRemoved : XISlaveRemoved;
|
||||||
|
|
||||||
input_lock();
|
input_lock();
|
||||||
|
|
||||||
prev = NULL;
|
if ((ret = CloseOneDevice(dev, &inputInfo.devices)) == Success ||
|
||||||
for (tmp = inputInfo.devices; tmp; (prev = tmp), (tmp = next)) {
|
(ret = CloseOneDevice(dev, &inputInfo.off_devices)) == Success)
|
||||||
next = tmp->next;
|
flags[deviceid] = flag;
|
||||||
if (tmp == dev) {
|
|
||||||
|
|
||||||
if (prev == NULL)
|
|
||||||
inputInfo.devices = next;
|
|
||||||
else
|
|
||||||
prev->next = next;
|
|
||||||
|
|
||||||
flags[tmp->id] = IsMaster(tmp) ? XIMasterRemoved : XISlaveRemoved;
|
|
||||||
CloseDevice(tmp);
|
|
||||||
ret = Success;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
prev = NULL;
|
|
||||||
for (tmp = inputInfo.off_devices; tmp; (prev = tmp), (tmp = next)) {
|
|
||||||
next = tmp->next;
|
|
||||||
if (tmp == dev) {
|
|
||||||
flags[tmp->id] = IsMaster(tmp) ? XIMasterRemoved : XISlaveRemoved;
|
|
||||||
CloseDevice(tmp);
|
|
||||||
|
|
||||||
if (prev == NULL)
|
|
||||||
inputInfo.off_devices = next;
|
|
||||||
else
|
|
||||||
prev->next = next;
|
|
||||||
|
|
||||||
ret = Success;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
input_unlock();
|
input_unlock();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue