Move two ioctls up so that if they fail we don't have to clean up an alloc.

Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net>
---
 src/wcmUSB.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/wcmUSB.c b/src/wcmUSB.c
index f0951d4..b7c81c1 100644
--- a/src/wcmUSB.c
+++ b/src/wcmUSB.c
@@ -401,6 +401,14 @@ static Bool usbWcmInit(InputInfoPtr pInfo, char* id, 
size_t id_len, float *versi
 
        DBG(1, priv, "initializing USB tablet\n");
 
+       /* fetch vendor, product, and model name */
+       if (ioctl(pInfo->fd, EVIOCGID, &sID) == -1 ||
+           ioctl(pInfo->fd, EVIOCGNAME(id_len), id) == -1) {
+               xf86Msg(X_ERROR, "%s: failed to ioctl ID or name.\n",
+                                       pInfo->name);
+               return !Success;
+       }
+
        if (!common->private &&
            !(common->private = calloc(1, sizeof(wcmUSBData))))
        {
@@ -412,10 +420,6 @@ static Bool usbWcmInit(InputInfoPtr pInfo, char* id, 
size_t id_len, float *versi
        usbdata = common->private;
        *version = 0.0;
 
-       /* fetch vendor, product, and model name */
-       ioctl(pInfo->fd, EVIOCGID, &sID);
-       ioctl(pInfo->fd, EVIOCGNAME(id_len), id);
-
        for (i = 0; i < ARRAY_SIZE(WacomModelDesc); i++)
        {
                if (sID.vendor == WacomModelDesc[i].vendor_id &&
@@ -774,7 +778,8 @@ int usbWcmGetRanges(InputInfoPtr pInfo)
 
                memset(sw, 0, sizeof(sw));
 
-               ioctl(pInfo->fd, EVIOCGSW(sizeof(sw)), sw);
+               if (ioctl(pInfo->fd, EVIOCGSW(sizeof(sw)), sw) < 0)
+                       xf86Msg(X_ERROR, "%s: unable to ioctl sw state.\n", 
pInfo->name);
 
                if (ISBITSET(sw, SW_MUTE_DEVICE))
                        common->wcmHWTouchSwitchState = 0;
-- 
2.1.0


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to