···6767 struct mutex thread_lock;6868};69697070-static struct hiddev *hiddev_table[HIDDEV_MINORS];7070+static struct usb_driver hiddev_driver;71717272/*7373 * Find a report, given the report's type and ID. The ID can be specified···265265static int hiddev_open(struct inode *inode, struct file *file)266266{267267 struct hiddev_list *list;268268- int res, i;268268+ struct usb_interface *intf;269269+ struct hiddev *hiddev;270270+ int res;269271270270- /* See comment in hiddev_connect() for BKL explanation */271271- lock_kernel();272272- i = iminor(inode) - HIDDEV_MINOR_BASE;273273-274274- if (i >= HIDDEV_MINORS || i < 0 || !hiddev_table[i])272272+ intf = usb_find_interface(&hiddev_driver, iminor(inode));273273+ if (!intf)275274 return -ENODEV;275275+ hiddev = usb_get_intfdata(intf);276276277277 if (!(list = kzalloc(sizeof(struct hiddev_list), GFP_KERNEL)))278278 return -ENOMEM;279279 mutex_init(&list->thread_lock);280280-281281- list->hiddev = hiddev_table[i];282282-283283-280280+ list->hiddev = hiddev;284281 file->private_data = list;285282286283 /*···286289 */287290 if (list->hiddev->exist) {288291 if (!list->hiddev->open++) {289289- res = usbhid_open(hiddev_table[i]->hid);292292+ res = usbhid_open(hiddev->hid);290293 if (res < 0) {291294 res = -EIO;292295 goto bail;···298301 }299302300303 spin_lock_irq(&list->hiddev->list_lock);301301- list_add_tail(&list->node, &hiddev_table[i]->list);304304+ list_add_tail(&list->node, &hiddev->list);302305 spin_unlock_irq(&list->hiddev->list_lock);303306304307 if (!list->hiddev->open++)305308 if (list->hiddev->exist) {306306- struct hid_device *hid = hiddev_table[i]->hid;309309+ struct hid_device *hid = hiddev->hid;307310 res = usbhid_get_power(hid);308311 if (res < 0) {309312 res = -EIO;···311314 }312315 usbhid_open(hid);313316 }314314-315315- unlock_kernel();316317 return 0;317318bail:318319 file->private_data = NULL;319320 kfree(list);320320- unlock_kernel();321321 return res;322322}323323···888894 hid->hiddev = hiddev;889895 hiddev->hid = hid;890896 hiddev->exist = 1;891891-892892- /*893893- * BKL here is used to avoid race after usb_register_dev().894894- * Once the device node has been created, open() could happen on it.895895- * The code below will then fail, as hiddev_table hasn't been896896- * updated.897897- *898898- * The obvious fix -- introducing mutex to guard hiddev_table[]899899- * doesn't work, as usb_open() and usb_register_dev() both take900900- * minor_rwsem, thus we'll have ABBA deadlock.901901- *902902- * Before BKL pushdown, usb_open() had been acquiring it in right903903- * order, so _open() was safe to use it to protect from this race.904904- * Now the order is different, but AB-BA deadlock still doesn't occur905905- * as BKL is dropped on schedule() (i.e. while sleeping on906906- * minor_rwsem). Fugly.907907- */908908- lock_kernel();897897+ usb_set_intfdata(usbhid->intf, usbhid);909898 retval = usb_register_dev(usbhid->intf, &hiddev_class);910899 if (retval) {911900 err_hid("Not able to get a minor for this device.");912901 hid->hiddev = NULL;913913- unlock_kernel();914902 kfree(hiddev);915903 return -1;916916- } else {917917- hid->minor = usbhid->intf->minor;918918- hiddev_table[usbhid->intf->minor - HIDDEV_MINOR_BASE] = hiddev;919904 }920920- unlock_kernel();921921-922905 return 0;923906}924907···913942 hiddev->exist = 0;914943 mutex_unlock(&hiddev->existancelock);915944916916- hiddev_table[hiddev->hid->minor - HIDDEV_MINOR_BASE] = NULL;917945 usb_deregister_dev(usbhid->intf, &hiddev_class);918946919947 if (hiddev->open) {