Merge branch 'bkl' into for-linus

+12 -42
+12 -42
drivers/hid/usbhid/hiddev.c
··· 67 struct mutex thread_lock; 68 }; 69 70 - static struct hiddev *hiddev_table[HIDDEV_MINORS]; 71 72 /* 73 * Find a report, given the report's type and ID. The ID can be specified ··· 265 static int hiddev_open(struct inode *inode, struct file *file) 266 { 267 struct hiddev_list *list; 268 - int res, i; 269 270 - /* See comment in hiddev_connect() for BKL explanation */ 271 - lock_kernel(); 272 - i = iminor(inode) - HIDDEV_MINOR_BASE; 273 - 274 - if (i >= HIDDEV_MINORS || i < 0 || !hiddev_table[i]) 275 return -ENODEV; 276 277 if (!(list = kzalloc(sizeof(struct hiddev_list), GFP_KERNEL))) 278 return -ENOMEM; 279 mutex_init(&list->thread_lock); 280 - 281 - list->hiddev = hiddev_table[i]; 282 - 283 - 284 file->private_data = list; 285 286 /* ··· 286 */ 287 if (list->hiddev->exist) { 288 if (!list->hiddev->open++) { 289 - res = usbhid_open(hiddev_table[i]->hid); 290 if (res < 0) { 291 res = -EIO; 292 goto bail; ··· 298 } 299 300 spin_lock_irq(&list->hiddev->list_lock); 301 - list_add_tail(&list->node, &hiddev_table[i]->list); 302 spin_unlock_irq(&list->hiddev->list_lock); 303 304 if (!list->hiddev->open++) 305 if (list->hiddev->exist) { 306 - struct hid_device *hid = hiddev_table[i]->hid; 307 res = usbhid_get_power(hid); 308 if (res < 0) { 309 res = -EIO; ··· 311 } 312 usbhid_open(hid); 313 } 314 - 315 - unlock_kernel(); 316 return 0; 317 bail: 318 file->private_data = NULL; 319 kfree(list); 320 - unlock_kernel(); 321 return res; 322 } 323 ··· 888 hid->hiddev = hiddev; 889 hiddev->hid = hid; 890 hiddev->exist = 1; 891 - 892 - /* 893 - * BKL here is used to avoid race after usb_register_dev(). 894 - * Once the device node has been created, open() could happen on it. 895 - * The code below will then fail, as hiddev_table hasn't been 896 - * updated. 897 - * 898 - * The obvious fix -- introducing mutex to guard hiddev_table[] 899 - * doesn't work, as usb_open() and usb_register_dev() both take 900 - * minor_rwsem, thus we'll have ABBA deadlock. 901 - * 902 - * Before BKL pushdown, usb_open() had been acquiring it in right 903 - * order, so _open() was safe to use it to protect from this race. 904 - * Now the order is different, but AB-BA deadlock still doesn't occur 905 - * as BKL is dropped on schedule() (i.e. while sleeping on 906 - * minor_rwsem). Fugly. 907 - */ 908 - lock_kernel(); 909 retval = usb_register_dev(usbhid->intf, &hiddev_class); 910 if (retval) { 911 err_hid("Not able to get a minor for this device."); 912 hid->hiddev = NULL; 913 - unlock_kernel(); 914 kfree(hiddev); 915 return -1; 916 - } else { 917 - hid->minor = usbhid->intf->minor; 918 - hiddev_table[usbhid->intf->minor - HIDDEV_MINOR_BASE] = hiddev; 919 } 920 - unlock_kernel(); 921 - 922 return 0; 923 } 924 ··· 913 hiddev->exist = 0; 914 mutex_unlock(&hiddev->existancelock); 915 916 - hiddev_table[hiddev->hid->minor - HIDDEV_MINOR_BASE] = NULL; 917 usb_deregister_dev(usbhid->intf, &hiddev_class); 918 919 if (hiddev->open) {
··· 67 struct mutex thread_lock; 68 }; 69 70 + static struct usb_driver hiddev_driver; 71 72 /* 73 * Find a report, given the report's type and ID. The ID can be specified ··· 265 static int hiddev_open(struct inode *inode, struct file *file) 266 { 267 struct hiddev_list *list; 268 + struct usb_interface *intf; 269 + struct hiddev *hiddev; 270 + int res; 271 272 + intf = usb_find_interface(&hiddev_driver, iminor(inode)); 273 + if (!intf) 274 return -ENODEV; 275 + hiddev = usb_get_intfdata(intf); 276 277 if (!(list = kzalloc(sizeof(struct hiddev_list), GFP_KERNEL))) 278 return -ENOMEM; 279 mutex_init(&list->thread_lock); 280 + list->hiddev = hiddev; 281 file->private_data = list; 282 283 /* ··· 289 */ 290 if (list->hiddev->exist) { 291 if (!list->hiddev->open++) { 292 + res = usbhid_open(hiddev->hid); 293 if (res < 0) { 294 res = -EIO; 295 goto bail; ··· 301 } 302 303 spin_lock_irq(&list->hiddev->list_lock); 304 + list_add_tail(&list->node, &hiddev->list); 305 spin_unlock_irq(&list->hiddev->list_lock); 306 307 if (!list->hiddev->open++) 308 if (list->hiddev->exist) { 309 + struct hid_device *hid = hiddev->hid; 310 res = usbhid_get_power(hid); 311 if (res < 0) { 312 res = -EIO; ··· 314 } 315 usbhid_open(hid); 316 } 317 return 0; 318 bail: 319 file->private_data = NULL; 320 kfree(list); 321 return res; 322 } 323 ··· 894 hid->hiddev = hiddev; 895 hiddev->hid = hid; 896 hiddev->exist = 1; 897 + usb_set_intfdata(usbhid->intf, usbhid); 898 retval = usb_register_dev(usbhid->intf, &hiddev_class); 899 if (retval) { 900 err_hid("Not able to get a minor for this device."); 901 hid->hiddev = NULL; 902 kfree(hiddev); 903 return -1; 904 } 905 return 0; 906 } 907 ··· 942 hiddev->exist = 0; 943 mutex_unlock(&hiddev->existancelock); 944 945 usb_deregister_dev(usbhid->intf, &hiddev_class); 946 947 if (hiddev->open) {