| .. | .. |
|---|
| 30 | 30 | #define IOCTL_GET_DRV_VERSION 2 |
|---|
| 31 | 31 | |
|---|
| 32 | 32 | |
|---|
| 33 | | -static DEFINE_MUTEX(lcd_mutex); |
|---|
| 34 | 33 | static const struct usb_device_id id_table[] = { |
|---|
| 35 | 34 | { .idVendor = 0x10D2, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, }, |
|---|
| 36 | 35 | { }, |
|---|
| 37 | 36 | }; |
|---|
| 38 | 37 | MODULE_DEVICE_TABLE(usb, id_table); |
|---|
| 39 | | - |
|---|
| 40 | | -static DEFINE_MUTEX(open_disc_mutex); |
|---|
| 41 | | - |
|---|
| 42 | 38 | |
|---|
| 43 | 39 | struct usb_lcd { |
|---|
| 44 | 40 | struct usb_device *udev; /* init: probe_lcd */ |
|---|
| .. | .. |
|---|
| 84 | 80 | struct usb_interface *interface; |
|---|
| 85 | 81 | int subminor, r; |
|---|
| 86 | 82 | |
|---|
| 87 | | - mutex_lock(&lcd_mutex); |
|---|
| 88 | 83 | subminor = iminor(inode); |
|---|
| 89 | 84 | |
|---|
| 90 | 85 | interface = usb_find_interface(&lcd_driver, subminor); |
|---|
| 91 | 86 | if (!interface) { |
|---|
| 92 | | - mutex_unlock(&lcd_mutex); |
|---|
| 93 | | - printk(KERN_ERR "USBLCD: %s - error, can't find device for minor %d\n", |
|---|
| 87 | + pr_err("USBLCD: %s - error, can't find device for minor %d\n", |
|---|
| 94 | 88 | __func__, subminor); |
|---|
| 95 | 89 | return -ENODEV; |
|---|
| 96 | 90 | } |
|---|
| 97 | 91 | |
|---|
| 98 | | - mutex_lock(&open_disc_mutex); |
|---|
| 99 | 92 | dev = usb_get_intfdata(interface); |
|---|
| 100 | | - if (!dev) { |
|---|
| 101 | | - mutex_unlock(&open_disc_mutex); |
|---|
| 102 | | - mutex_unlock(&lcd_mutex); |
|---|
| 103 | | - return -ENODEV; |
|---|
| 104 | | - } |
|---|
| 105 | 93 | |
|---|
| 106 | 94 | /* increment our usage count for the device */ |
|---|
| 107 | 95 | kref_get(&dev->kref); |
|---|
| 108 | | - mutex_unlock(&open_disc_mutex); |
|---|
| 109 | 96 | |
|---|
| 110 | 97 | /* grab a power reference */ |
|---|
| 111 | 98 | r = usb_autopm_get_interface(interface); |
|---|
| 112 | 99 | if (r < 0) { |
|---|
| 113 | 100 | kref_put(&dev->kref, lcd_delete); |
|---|
| 114 | | - mutex_unlock(&lcd_mutex); |
|---|
| 115 | 101 | return r; |
|---|
| 116 | 102 | } |
|---|
| 117 | 103 | |
|---|
| 118 | 104 | /* save our object in the file's private structure */ |
|---|
| 119 | 105 | file->private_data = dev; |
|---|
| 120 | | - mutex_unlock(&lcd_mutex); |
|---|
| 121 | 106 | |
|---|
| 122 | 107 | return 0; |
|---|
| 123 | 108 | } |
|---|
| .. | .. |
|---|
| 186 | 171 | |
|---|
| 187 | 172 | switch (cmd) { |
|---|
| 188 | 173 | case IOCTL_GET_HARD_VERSION: |
|---|
| 189 | | - mutex_lock(&lcd_mutex); |
|---|
| 190 | 174 | bcdDevice = le16_to_cpu((dev->udev)->descriptor.bcdDevice); |
|---|
| 191 | 175 | sprintf(buf, "%1d%1d.%1d%1d", |
|---|
| 192 | 176 | (bcdDevice & 0xF000)>>12, |
|---|
| 193 | 177 | (bcdDevice & 0xF00)>>8, |
|---|
| 194 | 178 | (bcdDevice & 0xF0)>>4, |
|---|
| 195 | 179 | (bcdDevice & 0xF)); |
|---|
| 196 | | - mutex_unlock(&lcd_mutex); |
|---|
| 197 | 180 | if (copy_to_user((void __user *)arg, buf, strlen(buf)) != 0) |
|---|
| 198 | 181 | return -EFAULT; |
|---|
| 199 | 182 | break; |
|---|
| .. | .. |
|---|
| 204 | 187 | break; |
|---|
| 205 | 188 | default: |
|---|
| 206 | 189 | return -ENOTTY; |
|---|
| 207 | | - break; |
|---|
| 208 | 190 | } |
|---|
| 209 | 191 | |
|---|
| 210 | 192 | return 0; |
|---|
| .. | .. |
|---|
| 388 | 370 | /* something prevented us from registering this driver */ |
|---|
| 389 | 371 | dev_err(&interface->dev, |
|---|
| 390 | 372 | "Not able to get a minor for this device.\n"); |
|---|
| 391 | | - usb_set_intfdata(interface, NULL); |
|---|
| 392 | 373 | goto error; |
|---|
| 393 | 374 | } |
|---|
| 394 | 375 | |
|---|
| .. | .. |
|---|
| 434 | 415 | |
|---|
| 435 | 416 | static void lcd_disconnect(struct usb_interface *interface) |
|---|
| 436 | 417 | { |
|---|
| 437 | | - struct usb_lcd *dev; |
|---|
| 418 | + struct usb_lcd *dev = usb_get_intfdata(interface); |
|---|
| 438 | 419 | int minor = interface->minor; |
|---|
| 439 | | - |
|---|
| 440 | | - mutex_lock(&open_disc_mutex); |
|---|
| 441 | | - dev = usb_get_intfdata(interface); |
|---|
| 442 | | - usb_set_intfdata(interface, NULL); |
|---|
| 443 | | - mutex_unlock(&open_disc_mutex); |
|---|
| 444 | 420 | |
|---|
| 445 | 421 | /* give back our minor */ |
|---|
| 446 | 422 | usb_deregister_dev(interface, &lcd_class); |
|---|