Input: wacom - isolate input registration
authorChris Bagwell <chris@cnpbagwell.com>
Mon, 26 Mar 2012 06:25:45 +0000 (23:25 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 26 Mar 2012 06:31:27 +0000 (23:31 -0700)
Although this better co-locates input registration logic,
the main goal is to make it easier to optionally create
input devices or delay creation to later time periods.

Signed-off-by: Chris Bagwell <chris@cnpbagwell.com>
Tested-by: Jason Gerecke <killertofu@gmail.com>
Acked-by: Ping Cheng <pingc@wacom.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
drivers/input/tablet/wacom_sys.c

index 39205eddf71301466e993419180d159c88af7307..f6da2f8a9c18a08f5de28aa04d97805a08251fd3 100644 (file)
@@ -822,6 +822,37 @@ static void wacom_destroy_leds(struct wacom *wacom)
        }
 }
 
+static int wacom_register_input(struct wacom *wacom)
+{
+       struct input_dev *input_dev;
+       struct usb_interface *intf = wacom->intf;
+       struct usb_device *dev = interface_to_usbdev(intf);
+       struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
+       int error;
+
+       input_dev = input_allocate_device();
+       if (!input_dev)
+               return -ENOMEM;
+
+       input_dev->name = wacom_wac->name;
+       input_dev->dev.parent = &intf->dev;
+       input_dev->open = wacom_open;
+       input_dev->close = wacom_close;
+       usb_to_input_id(dev, &input_dev->id);
+       input_set_drvdata(input_dev, wacom);
+
+       wacom_wac->input = input_dev;
+       wacom_setup_input_capabilities(input_dev, wacom_wac);
+
+       error = input_register_device(input_dev);
+       if (error) {
+               input_free_device(input_dev);
+               wacom_wac->input = NULL;
+       }
+
+       return error;
+}
+
 static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
 {
        struct usb_device *dev = interface_to_usbdev(intf);
@@ -829,18 +860,12 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
        struct wacom *wacom;
        struct wacom_wac *wacom_wac;
        struct wacom_features *features;
-       struct input_dev *input_dev;
        int error;
 
        if (!id->driver_info)
                return -EINVAL;
 
        wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
-       input_dev = input_allocate_device();
-       if (!wacom || !input_dev) {
-               error = -ENOMEM;
-               goto fail1;
-       }
 
        wacom_wac = &wacom->wacom_wac;
        wacom_wac->features = *((struct wacom_features *)id->driver_info);
@@ -869,8 +894,6 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
        usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
        strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
 
-       wacom_wac->input = input_dev;
-
        endpoint = &intf->cur_altsetting->endpoint[0].desc;
 
        /* Retrieve the physical and logical size for OEM devices */
@@ -894,15 +917,6 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
                        goto fail3;
        }
 
-       input_dev->name = wacom_wac->name;
-       input_dev->dev.parent = &intf->dev;
-       input_dev->open = wacom_open;
-       input_dev->close = wacom_close;
-       usb_to_input_id(dev, &input_dev->id);
-       input_set_drvdata(input_dev, wacom);
-
-       wacom_setup_input_capabilities(input_dev, wacom_wac);
-
        usb_fill_int_urb(wacom->irq, dev,
                         usb_rcvintpipe(dev, endpoint->bEndpointAddress),
                         wacom_wac->data, features->pktlen,
@@ -914,7 +928,7 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
        if (error)
                goto fail4;
 
-       error = input_register_device(input_dev);
+       error = wacom_register_input(wacom);
        if (error)
                goto fail5;
 
@@ -928,8 +942,7 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
  fail4:        wacom_remove_shared_data(wacom_wac);
  fail3:        usb_free_urb(wacom->irq);
  fail2:        usb_free_coherent(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma);
- fail1:        input_free_device(input_dev);
-       kfree(wacom);
+ fail1:        kfree(wacom);
        return error;
 }