]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/hid/usbhid/hiddev.c
Merge branch 'autosuspend' into for-next
[linux-2.6-omap-h63xx.git] / drivers / hid / usbhid / hiddev.c
index 4940e4d70c2d1ef6ef02804cc45222c7e5201c60..e9b436d2d94434c17fb1030d50528341edd71659 100644 (file)
@@ -227,12 +227,9 @@ void hiddev_report_event(struct hid_device *hid, struct hid_report *report)
  */
 static int hiddev_fasync(int fd, struct file *file, int on)
 {
-       int retval;
        struct hiddev_list *list = file->private_data;
 
-       retval = fasync_helper(fd, file, on, &list->fasync);
-
-       return retval < 0 ? retval : 0;
+       return fasync_helper(fd, file, on, &list->fasync);
 }
 
 
@@ -249,10 +246,12 @@ static int hiddev_release(struct inode * inode, struct file * file)
        spin_unlock_irqrestore(&list->hiddev->list_lock, flags);
 
        if (!--list->hiddev->open) {
-               if (list->hiddev->exist)
+               if (list->hiddev->exist) {
                        usbhid_close(list->hiddev->hid);
-               else
+                       usbhid_put_power(list->hiddev->hid);
+               } else {
                        kfree(list->hiddev);
+               }
        }
 
        kfree(list);
@@ -303,10 +302,21 @@ static int hiddev_open(struct inode *inode, struct file *file)
        list_add_tail(&list->node, &hiddev_table[i]->list);
        spin_unlock_irq(&list->hiddev->list_lock);
 
+       if (!list->hiddev->open++)
+               if (list->hiddev->exist) {
+                       struct hid_device *hid = hiddev_table[i]->hid;
+                       res = usbhid_get_power(hid);
+                       if (res < 0) {
+                               res = -EIO;
+                               goto bail;
+                       }
+                       usbhid_open(hid);
+               }
+
        return 0;
 bail:
        file->private_data = NULL;
-       kfree(list->hiddev);
+       kfree(list);
        return res;
 }
 
@@ -323,7 +333,7 @@ static ssize_t hiddev_write(struct file * file, const char __user * buffer, size
  */
 static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos)
 {
-       DECLARE_WAITQUEUE(wait, current);
+       DEFINE_WAIT(wait);
        struct hiddev_list *list = file->private_data;
        int event_size;
        int retval;
@@ -878,16 +888,21 @@ int hiddev_connect(struct hid_device *hid, unsigned int force)
        hiddev->hid = hid;
        hiddev->exist = 1;
 
+       /* when lock_kernel() usage is fixed in usb_open(),
+        * we could also fix it here */
+       lock_kernel();
        retval = usb_register_dev(usbhid->intf, &hiddev_class);
        if (retval) {
                err_hid("Not able to get a minor for this device.");
                hid->hiddev = NULL;
+               unlock_kernel();
                kfree(hiddev);
                return -1;
        } else {
                hid->minor = usbhid->intf->minor;
                hiddev_table[usbhid->intf->minor - HIDDEV_MINOR_BASE] = hiddev;
        }
+       unlock_kernel();
 
        return 0;
 }