summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2010-05-19 15:09:29 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2010-05-28 09:24:28 +1000
commite6e20c1b3e5977830a2b78046c0a8c49e38746fd (patch)
tree97728d83f0f198db6616da1bd6ec4434506c7e85
parentb27d03b248e36ec7a674113baa494b82e3ad728b (diff)
Move error handling in PreInit down to the end.
Just have one exit path instead of different ones. Guards are in place to avoid freeing/deleting something that shouldn't be. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Jamey Sharp <jamey@minilop.net>
-rw-r--r--src/evdev.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/evdev.c b/src/evdev.c
index 27c28cb..fd8e68c 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1993,6 +1993,7 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
return NULL;
/* Initialise the InputInfoRec. */
+ pInfo->fd = -1;
pInfo->name = dev->identifier;
pInfo->flags = 0;
pInfo->type_name = "UNKNOWN";
@@ -2008,9 +2009,10 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
pInfo->private_flags = 0;
pInfo->always_core_feedback = NULL;
pInfo->conf_idev = dev;
+ pInfo->private = NULL;
if (!(pEvdev = xcalloc(sizeof(EvdevRec), 1)))
- return pInfo;
+ goto error;
pInfo->private = pEvdev;
@@ -2026,8 +2028,7 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
device = xf86CheckStrOption(dev->commonOptions, "Device", NULL);
if (!device) {
xf86Msg(X_ERROR, "%s: No device specified.\n", pInfo->name);
- xf86DeleteInput(pInfo, 0);
- return NULL;
+ goto error;
}
pEvdev->device = device;
@@ -2039,8 +2040,7 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
if (pInfo->fd < 0) {
xf86Msg(X_ERROR, "Unable to open evdev device \"%s\".\n", device);
- xf86DeleteInput(pInfo, 0);
- return NULL;
+ goto error;
}
/* Check major/minor of device node to avoid adding duplicate devices. */
@@ -2049,9 +2049,7 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
{
xf86Msg(X_WARNING, "%s: device file already in use. Ignoring.\n",
pInfo->name);
- close(pInfo->fd);
- xf86DeleteInput(pInfo, 0);
- return NULL;
+ goto error;
}
pEvdev->invert_x = xf86SetBoolOption(pInfo->options, "InvertX", FALSE);
@@ -2081,9 +2079,7 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
if (EvdevCacheCompare(pInfo, FALSE) ||
EvdevProbe(pInfo)) {
- close(pInfo->fd);
- xf86DeleteInput(pInfo, 0);
- return NULL;
+ goto error;
}
EvdevAddDevice(pInfo);
@@ -2096,6 +2092,12 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
}
return pInfo;
+
+error:
+ if (pInfo->fd >= 0)
+ close(pInfo->fd);
+ xf86DeleteInput(pInfo, 0);
+ return NULL;
}
_X_EXPORT InputDriverRec EVDEV = {