staging: usbip: stub: update refcounts for devices and interfaces

The stub driver expects to access the usb interface
and usb device structures even if the device has been
disconnected in the meantime.

This change gets a reference to them in the stub probe
function using usb_get_intf()/usb_get_dev() and drops them
in the disconnect function.

This fixes an oops observed with a Logic Controls Line
display (0fa8:a030) which disconnects itself when it is
reset:

[ 1348.562274] BUG: unable to handle kernel paging request at 5f7433e5
[ 1348.562327] IP: [<c0393b02>] usb_lock_device_for_reset+0x22/0xd0
[ 1348.562374] *pde = 00000000
[ 1348.562397] Oops: 0000 [#1]
[ 1348.562418] last sysfs file: /sys/devices/pci0000:00/0000:00:10.2/usb4/4-1/bConfigurationValue
[ 1348.562454] Modules linked in: usbip vhci_hcd usbip_common_mod fbcon tileblit font bitblit softcursor serio_raw uvesafb pcspkr via_rng snd_via82xx gameport snd_ac97_codec ac97_bus snd_pcm_oss snd_mixer_oss snd_pcm snd_page_alloc snd_mpu401_uart snd_rawmidi snd_seq_oss snd_seq_midi_event snd_seq snd_timer snd_seq_device snd usbhid hid via_rhine soundcore mii igel_flash aufs pata_via
[ 1348.562649]
[ 1348.562670] Pid: 2855, comm: usbip_eh Not tainted (2.6.32 #23.37-ud-r113) M300C
[ 1348.562704] EIP: 0060:[<c0393b02>] EFLAGS: 00010216 CPU: 0
[ 1348.562734] EIP is at usb_lock_device_for_reset+0x22/0xd0
[ 1348.562762] EAX: 5f7433cd EBX: 5f7433cd ECX: de293a5c EDX: dd326a00
[ 1348.562793] ESI: 5f7433cd EDI: 000400f6 EBP: cf43ff48 ESP: cf43ff38
[ 1348.562824] DS: 007b ES: 007b FS: 0000 GS: 00e0 SS: 0068
[ 1348.562854] Process usbip_eh (pid: 2855, ti=cf43e000 task=d2c7f230 task.ti=cf43e000)
[ 1348.562884] Stack:
[ 1348.562900] d6ec9960 de2939cc 5f7433cd 5f743431 cf43ff70 df8fd32f de2939cc d2c7f230
[ 1348.562940] <0> cf43ff70 00000282 00000282 de2939cc d2c7f230 d2c7f230 cf43ffa8 df84416d
[ 1348.562987] <0> cf43ff88 d2c7f230 de293a24 d2c7f230 00000000 d2c7f230 c014e760 cf43ff94
[ 1348.563042] Call Trace:
[ 1348.563073] [<df8fd32f>] ? stub_device_reset+0x3f/0x110 [usbip]
[ 1348.563114] [<df84416d>] ? event_handler_loop+0xcd/0xe8 [usbip_common_mod]
[ 1348.563156] [<c014e760>] ? autoremove_wake_function+0x0/0x50
[ 1348.563193] [<df843d80>] ? usbip_thread+0x0/0x60 [usbip_common_mod]
[ 1348.563230] [<df843dd1>] ? usbip_thread+0x51/0x60 [usbip_common_mod]
[ 1348.563265] [<c014e374>] ? kthread+0x74/0x80
[ 1348.563294] [<c014e300>] ? kthread+0x0/0x80
[ 1348.563326] [<c0103c47>] ? kernel_thread_helper+0x7/0x10
[ 1348.563351] Code: 00 e8 73 4d 00 00 5d c3 90 55 89 e5 83 ec 10 89 5d f4 89 75 f8 89 7d fc 0f 1f 44 00 00 8b 3d c0 2e 67 c0 81 c7 fa 00 00 00 89 c3 <8b> 40 18 89 d6 85 c0 75 15 b8 ed ff ff ff 8b 5d f4 8b 75 f8 8b
[ 1348.563528] EIP: [<c0393b02>] usb_lock_device_for_reset+0x22/0xd0 SS:ESP 0068:cf43ff38
[ 1348.563570] CR2: 000000005f7433e5
[ 1348.563593] ---[ end trace 9c3f1e3a2e5299d9 ]---

Signed-off-by: Max Vozeler <max@vozeler.com>
Tested-by: Mark Wehby <MWehby@luxotticaRetail.com>
Tested-by: Steven Harms <sharms@luxotticaRetail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by Max Vozeler and committed by Greg Kroah-Hartman 2d8f4595 85d139c9

+17 -6
+1
drivers/staging/usbip/stub.h
··· 32 32 33 33 struct stub_device { 34 34 struct usb_interface *interface; 35 + struct usb_device *udev; 35 36 struct list_head list; 36 37 37 38 struct usbip_device ud;
+14 -4
drivers/staging/usbip/stub_dev.c
··· 258 258 static void stub_device_reset(struct usbip_device *ud) 259 259 { 260 260 struct stub_device *sdev = container_of(ud, struct stub_device, ud); 261 - struct usb_device *udev = interface_to_usbdev(sdev->interface); 261 + struct usb_device *udev = sdev->udev; 262 262 int ret; 263 263 264 264 usbip_udbg("device reset"); 265 + 265 266 ret = usb_lock_device_for_reset(udev, sdev->interface); 266 267 if (ret < 0) { 267 268 dev_err(&udev->dev, "lock for reset\n"); ··· 310 309 * 311 310 * Allocates and initializes a new stub_device struct. 312 311 */ 313 - static struct stub_device *stub_device_alloc(struct usb_interface *interface) 312 + static struct stub_device *stub_device_alloc(struct usb_device *udev, 313 + struct usb_interface *interface) 314 314 { 315 315 struct stub_device *sdev; 316 316 int busnum = interface_to_busnum(interface); ··· 326 324 return NULL; 327 325 } 328 326 329 - sdev->interface = interface; 327 + sdev->interface = usb_get_intf(interface); 328 + sdev->udev = usb_get_dev(udev); 330 329 331 330 /* 332 331 * devid is defined with devnum when this driver is first allocated. ··· 453 450 return err; 454 451 } 455 452 453 + usb_get_intf(interface); 456 454 return 0; 457 455 } 458 456 459 457 /* ok. this is my device. */ 460 - sdev = stub_device_alloc(interface); 458 + sdev = stub_device_alloc(udev, interface); 461 459 if (!sdev) 462 460 return -ENOMEM; 463 461 ··· 480 476 dev_err(&interface->dev, "create sysfs files for %s\n", 481 477 udev_busid); 482 478 usb_set_intfdata(interface, NULL); 479 + usb_put_intf(interface); 480 + 483 481 busid_priv->interf_count = 0; 484 482 485 483 busid_priv->sdev = NULL; ··· 551 545 if (busid_priv->interf_count > 1) { 552 546 busid_priv->interf_count--; 553 547 shutdown_busid(busid_priv); 548 + usb_put_intf(interface); 554 549 return; 555 550 } 556 551 ··· 560 553 561 554 /* 1. shutdown the current connection */ 562 555 shutdown_busid(busid_priv); 556 + 557 + usb_put_dev(sdev->udev); 558 + usb_put_intf(interface); 563 559 564 560 /* 3. free sdev */ 565 561 busid_priv->sdev = NULL;
+2 -2
drivers/staging/usbip/stub_rx.c
··· 364 364 365 365 static int get_pipe(struct stub_device *sdev, int epnum, int dir) 366 366 { 367 - struct usb_device *udev = interface_to_usbdev(sdev->interface); 367 + struct usb_device *udev = sdev->udev; 368 368 struct usb_host_endpoint *ep; 369 369 struct usb_endpoint_descriptor *epd = NULL; 370 370 ··· 484 484 int ret; 485 485 struct stub_priv *priv; 486 486 struct usbip_device *ud = &sdev->ud; 487 - struct usb_device *udev = interface_to_usbdev(sdev->interface); 487 + struct usb_device *udev = sdev->udev; 488 488 int pipe = get_pipe(sdev, pdu->base.ep, pdu->base.direction); 489 489 490 490