Input: joysticks - handle errors when registering input devices
authorDmitry Torokhov <dtor@insightbb.com>
Mon, 6 Nov 2006 03:40:09 +0000 (22:40 -0500)
committerDmitry Torokhov <dtor@insightbb.com>
Mon, 6 Nov 2006 03:40:09 +0000 (22:40 -0500)
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
16 files changed:
drivers/input/joystick/adi.c
drivers/input/joystick/amijoy.c
drivers/input/joystick/analog.c
drivers/input/joystick/cobra.c
drivers/input/joystick/gf2k.c
drivers/input/joystick/grip_mp.c
drivers/input/joystick/guillemot.c
drivers/input/joystick/iforce/iforce-main.c
drivers/input/joystick/iforce/iforce-serio.c
drivers/input/joystick/interact.c
drivers/input/joystick/magellan.c
drivers/input/joystick/spaceball.c
drivers/input/joystick/spaceorb.c
drivers/input/joystick/stinger.c
drivers/input/joystick/twidjoy.c
drivers/input/joystick/warrior.c

index 704bf70f1db739b7860b0a3b4c67b10e867c06ab..6279ced8a35b61d07bf9f27ec8c97ead8a7306f1 100644 (file)
@@ -521,11 +521,19 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
        for (i = 0; i < 2; i++)
                if (port->adi[i].length > 0) {
                        adi_init_center(port->adi + i);
-                       input_register_device(port->adi[i].dev);
+                       err = input_register_device(port->adi[i].dev);
+                       if (err)
+                               goto fail3;
                }
 
        return 0;
 
+ fail3: while (--i >= 0) {
+               if (port->adi[i].length > 0) {
+                       input_unregister_device(port->adi[i].dev);
+                       port->adi[i].dev = NULL;
+               }
+       }
  fail2:        for (i = 0; i < 2; i++)
                if (port->adi[i].dev)
                        input_free_device(port->adi[i].dev);
index 650acf3a30b70878b8075e58c8ac9d265600ee1d..e608691b5a61963b1928f9185e6c8f317af2a612 100644 (file)
@@ -147,7 +147,11 @@ static int __init amijoy_init(void)
                        amijoy_dev[i]->absmax[ABS_X + j] = 1;
                }
 
-               input_register_device(amijoy_dev[i]);
+               err = input_register_device(amijoy_dev[i]);
+               if (err) {
+                       input_free_device(amijoy_dev[i]);
+                       goto fail;
+               }
        }
        return 0;
 
index e9a02db36eccc3b0d431f1276f94fe090d4f2923..7ef68456d7d65c3cddc339a9018c828de48b3dcd 100644 (file)
@@ -434,6 +434,7 @@ static int analog_init_device(struct analog_port *port, struct analog *analog, i
 {
        struct input_dev *input_dev;
        int i, j, t, v, w, x, y, z;
+       int error;
 
        analog_name(analog);
        snprintf(analog->phys, sizeof(analog->phys),
@@ -505,7 +506,11 @@ static int analog_init_device(struct analog_port *port, struct analog *analog, i
 
        analog_decode(analog, port->axes, port->initial, port->buttons);
 
-       input_register_device(analog->dev);
+       error = input_register_device(analog->dev);
+       if (error) {
+               input_free_device(analog->dev);
+               return error;
+       }
 
        return 0;
 }
@@ -668,7 +673,8 @@ static int analog_connect(struct gameport *gameport, struct gameport_driver *drv
        return 0;
 
  fail3: while (--i >= 0)
-               input_unregister_device(port->analog[i].dev);
+               if (port->analog[i].mask)
+                       input_unregister_device(port->analog[i].dev);
  fail2:        gameport_close(gameport);
  fail1:        gameport_set_drvdata(gameport, NULL);
        kfree(port);
index d5e42eb88a207a610d7addab264a9c9fe58659fb..034ec39c251d3e732fe5f1f2913f9bfdd2b5ed01 100644 (file)
@@ -223,12 +223,15 @@ static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv)
                for (j = 0; cobra_btn[j]; j++)
                        set_bit(cobra_btn[j], input_dev->keybit);
 
-               input_register_device(cobra->dev[i]);
+               err = input_register_device(cobra->dev[i]);
+               if (err)
+                       goto fail4;
        }
 
        return 0;
 
- fail3:        for (i = 0; i < 2; i++)
+ fail4:        input_free_device(cobra->dev[i]);
+ fail3:        while (--i >= 0)
                if (cobra->dev[i])
                        input_unregister_device(cobra->dev[i]);
  fail2:        gameport_close(gameport);
index e4a699f6ec87603d9f9e840f3353419cded537a4..bacbab5d1b6f5655d26fedb2e23e4d7f6fccd228 100644 (file)
@@ -341,7 +341,9 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
                input_dev->absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0;
        }
 
-       input_register_device(gf2k->dev);
+       err = input_register_device(gf2k->dev);
+       if (err)
+               goto fail2;
 
        return 0;
 
index 62438944a69a558c8e7d0e1eb5b808a11d65464e..8120a9c40773ecc41c8d73837a50bfd287e0c65a 100644 (file)
@@ -423,7 +423,10 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags)
 
                if (!port->registered) {
                        dbg("New Grip pad in multiport slot %d.\n", slot);
-                       register_slot(slot, grip);
+                       if (register_slot(slot, grip)) {
+                               port->mode = GRIP_MODE_RESET;
+                               port->dirty = 0;
+                       }
                }
                return flags;
        }
@@ -585,6 +588,7 @@ static int register_slot(int slot, struct grip_mp *grip)
        struct grip_port *port = grip->port[slot];
        struct input_dev *input_dev;
        int j, t;
+       int err;
 
        port->dev = input_dev = input_allocate_device();
        if (!input_dev)
@@ -610,7 +614,12 @@ static int register_slot(int slot, struct grip_mp *grip)
                if (t > 0)
                        set_bit(t, input_dev->keybit);
 
-       input_register_device(port->dev);
+       err = input_register_device(port->dev);
+       if (err) {
+               input_free_device(port->dev);
+               return err;
+       }
+
        port->registered = 1;
 
        if (port->dirty)                    /* report initial state, if any */
index 840ed9b512b26b5695e530545ba585741b1e9555..dbc5d92858b82f885e3c3758f4af9f1d624282ce 100644 (file)
@@ -250,7 +250,9 @@ static int guillemot_connect(struct gameport *gameport, struct gameport_driver *
        for (i = 0; (t = guillemot->type->btn[i]) >= 0; i++)
                set_bit(t, input_dev->keybit);
 
-       input_register_device(guillemot->dev);
+       err = input_register_device(guillemot->dev);
+       if (err)
+               goto fail2;
 
        return 0;
 
index 24c684bc63375917e44a06b3eae67947a501497d..706e0aea793c6377fc05325fe00f52cff8d914ed 100644 (file)
@@ -325,8 +325,8 @@ int iforce_init_device(struct iforce *iforce)
 
        if (i == 20) { /* 5 seconds */
                printk(KERN_ERR "iforce-main.c: Timeout waiting for response from device.\n");
-               input_free_device(input_dev);
-               return -ENODEV;
+               error = -ENODEV;
+               goto fail;
        }
 
 /*
@@ -439,10 +439,8 @@ int iforce_init_device(struct iforce *iforce)
                        set_bit(iforce->type->ff[i], input_dev->ffbit);
 
                error = input_ff_create(input_dev, ff_effects);
-               if (error) {
-                       input_free_device(input_dev);
-                       return error;
-               }
+               if (error)
+                       goto fail;
 
                ff = input_dev->ff;
                ff->upload = iforce_upload_effect;
@@ -455,11 +453,16 @@ int iforce_init_device(struct iforce *iforce)
  * Register input device.
  */
 
-       input_register_device(iforce->dev);
+       error = input_register_device(iforce->dev);
+       if (error)
+               goto fail;
 
        printk(KERN_DEBUG "iforce->dev->open = %p\n", iforce->dev->open);
 
        return 0;
+
+ fail: input_free_device(input_dev);
+       return error;
 }
 
 static int __init iforce_init(void)
index ca08f45c2040a5338e7987bd177a490c42eeac72..ec4be535f48391fc38c01dacc236d9ad3196cbe2 100644 (file)
@@ -141,21 +141,19 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv)
        serio_set_drvdata(serio, iforce);
 
        err = serio_open(serio, drv);
-       if (err) {
-               serio_set_drvdata(serio, NULL);
-               kfree(iforce);
-               return err;
-       }
+       if (err)
+               goto fail1;
 
        err = iforce_init_device(iforce);
-       if (err) {
-               serio_close(serio);
-               serio_set_drvdata(serio, NULL);
-               kfree(iforce);
-               return -ENODEV;
-       }
+       if (err)
+               goto fail2;
 
        return 0;
+
+ fail2:        serio_close(serio);
+ fail1:        serio_set_drvdata(serio, NULL);
+       kfree(iforce);
+       return err;
 }
 
 static void iforce_serio_disconnect(struct serio *serio)
index bbfeb9c59b874c763158a1e458ce35e8a4844ebc..fec8b3d0967d937fdbee3f166937f0c5ea638bac 100644 (file)
@@ -283,7 +283,9 @@ static int interact_connect(struct gameport *gameport, struct gameport_driver *d
        for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++)
                set_bit(t, input_dev->keybit);
 
-       input_register_device(interact->dev);
+       err = input_register_device(interact->dev);
+       if (err)
+               goto fail2;
 
        return 0;
 
index e3d19444ba2e42300c38ceacf7a5b336fea838bd..d512b0a0282e90bbd1444b777ef1a6cc86ea0cc4 100644 (file)
@@ -157,7 +157,7 @@ static int magellan_connect(struct serio *serio, struct serio_driver *drv)
        magellan = kzalloc(sizeof(struct magellan), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!magellan || !input_dev)
-               goto fail;
+               goto fail1;
 
        magellan->dev = input_dev;
        snprintf(magellan->phys, sizeof(magellan->phys), "%s/input0", serio->phys);
@@ -183,13 +183,17 @@ static int magellan_connect(struct serio *serio, struct serio_driver *drv)
 
        err = serio_open(serio, drv);
        if (err)
-               goto fail;
+               goto fail2;
+
+       err = input_register_device(magellan->dev);
+       if (err)
+               goto fail3;
 
-       input_register_device(magellan->dev);
        return 0;
 
- fail: serio_set_drvdata(serio, NULL);
-       input_free_device(input_dev);
+ fail3:        serio_close(serio);
+ fail2:        serio_set_drvdata(serio, NULL);
+ fail1:        input_free_device(input_dev);
        kfree(magellan);
        return err;
 }
index 2a9808cf826f146182e8e4e9bc33e9883c08610e..9b3597343c1cb87db0143b7faafbbe83e490f528 100644 (file)
@@ -215,7 +215,7 @@ static int spaceball_connect(struct serio *serio, struct serio_driver *drv)
        spaceball = kmalloc(sizeof(struct spaceball), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!spaceball || !input_dev)
-               goto fail;
+               goto fail1;
 
        spaceball->dev = input_dev;
        snprintf(spaceball->phys, sizeof(spaceball->phys), "%s/input0", serio->phys);
@@ -252,13 +252,17 @@ static int spaceball_connect(struct serio *serio, struct serio_driver *drv)
 
        err = serio_open(serio, drv);
        if (err)
-               goto fail;
+               goto fail2;
+
+       err = input_register_device(spaceball->dev);
+       if (err)
+               goto fail3;
 
-       input_register_device(spaceball->dev);
        return 0;
 
- fail: serio_set_drvdata(serio, NULL);
-       input_free_device(input_dev);
+ fail3:        serio_close(serio);
+ fail2:        serio_set_drvdata(serio, NULL);
+ fail1:        input_free_device(input_dev);
        kfree(spaceball);
        return err;
 }
index c4db0247c5fb13b8a4c1ba499665307ae874c46f..ea9d51e70a125424ad4e97c9e63993ad90f8edff 100644 (file)
@@ -172,7 +172,7 @@ static int spaceorb_connect(struct serio *serio, struct serio_driver *drv)
        spaceorb = kzalloc(sizeof(struct spaceorb), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!spaceorb || !input_dev)
-               goto fail;
+               goto fail1;
 
        spaceorb->dev = input_dev;
        snprintf(spaceorb->phys, sizeof(spaceorb->phys), "%s/input0", serio->phys);
@@ -198,13 +198,17 @@ static int spaceorb_connect(struct serio *serio, struct serio_driver *drv)
 
        err = serio_open(serio, drv);
        if (err)
-               goto fail;
+               goto fail2;
+
+       err = input_register_device(spaceorb->dev);
+       if (err)
+               goto fail3;
 
-       input_register_device(spaceorb->dev);
        return 0;
 
- fail: serio_set_drvdata(serio, NULL);
-       input_free_device(input_dev);
+ fail3:        serio_close(serio);
+ fail2:        serio_set_drvdata(serio, NULL);
+ fail1:        input_free_device(input_dev);
        kfree(spaceorb);
        return err;
 }
index 1ffb0322331112cf4f38126aef36fb1600c64270..b51a4a4c7f60050aa4779f6be44e82c62f50026b 100644 (file)
@@ -143,7 +143,7 @@ static int stinger_connect(struct serio *serio, struct serio_driver *drv)
        stinger = kmalloc(sizeof(struct stinger), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!stinger || !input_dev)
-               goto fail;
+               goto fail1;
 
        stinger->dev = input_dev;
        snprintf(stinger->phys, sizeof(stinger->phys), "%s/serio0", serio->phys);
@@ -168,13 +168,17 @@ static int stinger_connect(struct serio *serio, struct serio_driver *drv)
 
        err = serio_open(serio, drv);
        if (err)
-               goto fail;
+               goto fail2;
+
+       err = input_register_device(stinger->dev);
+       if (err)
+               goto fail3;
 
-       input_register_device(stinger->dev);
        return 0;
 
- fail: serio_set_drvdata(serio, NULL);
-       input_free_device(input_dev);
+ fail3:        serio_close(serio);
+ fail2:        serio_set_drvdata(serio, NULL);
+ fail1:        input_free_device(input_dev);
        kfree(stinger);
        return err;
 }
index 49085df2d63156eded4d4388ba94230a6a9e7d0b..3c1c83e8609aec92ded893d475803a3bff3e2645 100644 (file)
@@ -194,7 +194,7 @@ static int twidjoy_connect(struct serio *serio, struct serio_driver *drv)
        twidjoy = kzalloc(sizeof(struct twidjoy), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!twidjoy || !input_dev)
-               goto fail;
+               goto fail1;
 
        twidjoy->dev = input_dev;
        snprintf(twidjoy->phys, sizeof(twidjoy->phys), "%s/input0", serio->phys);
@@ -221,13 +221,17 @@ static int twidjoy_connect(struct serio *serio, struct serio_driver *drv)
 
        err = serio_open(serio, drv);
        if (err)
-               goto fail;
+               goto fail2;
+
+       err = input_register_device(twidjoy->dev);
+       if (err)
+               goto fail3;
 
-       input_register_device(twidjoy->dev);
        return 0;
 
- fail: serio_set_drvdata(serio, NULL);
-       input_free_device(input_dev);
+ fail3:        serio_close(serio);
+ fail2:        serio_set_drvdata(serio, NULL);
+ fail1:        input_free_device(input_dev);
        kfree(twidjoy);
        return err;
 }
index 35edea1ab955cd81688cccd17a2de87195e6c69d..1e4828b9a1ab97327b7ec9dbf60db519f3f9e13a 100644 (file)
@@ -149,7 +149,7 @@ static int warrior_connect(struct serio *serio, struct serio_driver *drv)
        warrior = kzalloc(sizeof(struct warrior), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!warrior || !input_dev)
-               goto fail;
+               goto fail1;
 
        warrior->dev = input_dev;
        snprintf(warrior->phys, sizeof(warrior->phys), "%s/input0", serio->phys);
@@ -176,13 +176,17 @@ static int warrior_connect(struct serio *serio, struct serio_driver *drv)
 
        err = serio_open(serio, drv);
        if (err)
-               goto fail;
+               goto fail2;
+
+       err = input_register_device(warrior->dev);
+       if (err)
+               goto fail3;
 
-       input_register_device(warrior->dev);
        return 0;
 
- fail: serio_set_drvdata(serio, NULL);
-       input_free_device(input_dev);
+ fail3:        serio_close(serio);
+ fail2:        serio_set_drvdata(serio, NULL);
+ fail1:        input_free_device(input_dev);
        kfree(warrior);
        return err;
 }