android_kernel_oneplus_msm8998/drivers/usb/gadget/udc
Alan Stern 2fff3c5c2b USB: dummy-hcd: Fix deadlock caused by disconnect detection
commit ab219221a5064abfff9f78c323c4a257b16cdb81 upstream.

The dummy-hcd driver calls the gadget driver's disconnect callback
under the wrong conditions.  It should invoke the callback when Vbus
power is turned off, but instead it does so when the D+ pullup is
turned off.

This can cause a deadlock in the composite core when a gadget driver
is unregistered:

[   88.361471] ============================================
[   88.362014] WARNING: possible recursive locking detected
[   88.362580] 4.14.0-rc2+ #9 Not tainted
[   88.363010] --------------------------------------------
[   88.363561] v4l_id/526 is trying to acquire lock:
[   88.364062]  (&(&cdev->lock)->rlock){....}, at: [<ffffffffa0547e03>] composite_disconnect+0x43/0x100 [libcomposite]
[   88.365051]
[   88.365051] but task is already holding lock:
[   88.365826]  (&(&cdev->lock)->rlock){....}, at: [<ffffffffa0547b09>] usb_function_deactivate+0x29/0x80 [libcomposite]
[   88.366858]
[   88.366858] other info that might help us debug this:
[   88.368301]  Possible unsafe locking scenario:
[   88.368301]
[   88.369304]        CPU0
[   88.369701]        ----
[   88.370101]   lock(&(&cdev->lock)->rlock);
[   88.370623]   lock(&(&cdev->lock)->rlock);
[   88.371145]
[   88.371145]  *** DEADLOCK ***
[   88.371145]
[   88.372211]  May be due to missing lock nesting notation
[   88.372211]
[   88.373191] 2 locks held by v4l_id/526:
[   88.373715]  #0:  (&(&cdev->lock)->rlock){....}, at: [<ffffffffa0547b09>] usb_function_deactivate+0x29/0x80 [libcomposite]
[   88.374814]  #1:  (&(&dum_hcd->dum->lock)->rlock){....}, at: [<ffffffffa05bd48d>] dummy_pullup+0x7d/0xf0 [dummy_hcd]
[   88.376289]
[   88.376289] stack backtrace:
[   88.377726] CPU: 0 PID: 526 Comm: v4l_id Not tainted 4.14.0-rc2+ #9
[   88.378557] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014
[   88.379504] Call Trace:
[   88.380019]  dump_stack+0x86/0xc7
[   88.380605]  __lock_acquire+0x841/0x1120
[   88.381252]  lock_acquire+0xd5/0x1c0
[   88.381865]  ? composite_disconnect+0x43/0x100 [libcomposite]
[   88.382668]  _raw_spin_lock_irqsave+0x40/0x54
[   88.383357]  ? composite_disconnect+0x43/0x100 [libcomposite]
[   88.384290]  composite_disconnect+0x43/0x100 [libcomposite]
[   88.385490]  set_link_state+0x2d4/0x3c0 [dummy_hcd]
[   88.386436]  dummy_pullup+0xa7/0xf0 [dummy_hcd]
[   88.387195]  usb_gadget_disconnect+0xd8/0x160 [udc_core]
[   88.387990]  usb_gadget_deactivate+0xd3/0x160 [udc_core]
[   88.388793]  usb_function_deactivate+0x64/0x80 [libcomposite]
[   88.389628]  uvc_function_disconnect+0x1e/0x40 [usb_f_uvc]

This patch changes the code to test the port-power status bit rather
than the port-connect status bit when deciding whether to isue the
callback.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Reported-by: David Tulloh <david@tulloh.id.au>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-10-18 09:20:41 +02:00
..
bdc usb: gadget: bdc: fix memory leak 2015-09-30 11:20:21 -05:00
amd5536udc.c usb: gadget: amd5536udc: NULL comparison 2015-10-01 12:40:22 -05:00
amd5536udc.h usb: gadget: amd5536udc: remove unnecessary conditions 2015-10-01 12:40:20 -05:00
at91_udc.c usb: gadget: at91_udc: add ep capabilities support 2015-08-04 12:26:38 -05:00
at91_udc.h usb: gadget: at91_udc: move at91_udc_data in at91_udc.h 2015-09-27 10:54:31 -05:00
atmel_usba_udc.c usb: gadget: udc: atmel: set vbus irqflags explicitly 2017-10-12 11:27:31 +02:00
atmel_usba_udc.h
bcm63xx_udc.c usb: gadget: bcm63xx_udc: add ep capabilities support 2015-08-04 12:26:39 -05:00
dummy_hcd.c USB: dummy-hcd: Fix deadlock caused by disconnect detection 2017-10-18 09:20:41 +02:00
fotg210-udc.c usb: gadget: fotg210-udc: add ep capabilities support 2015-08-04 12:26:41 -05:00
fotg210.h
fsl_mxc_udc.c
fsl_qe_udc.c usb: gadget: fsl_qe_udc: signedness bug in qe_get_frame() 2016-10-07 15:23:42 +02:00
fsl_qe_udc.h
fsl_udc_core.c usb: gadget: udc: fsl: Add missing complete function. 2017-03-12 06:37:29 +01:00
fsl_usb2_udc.h
fusb300_udc.c usb: gadget: fusb300_udc: add ep capabilities support 2015-08-04 12:26:44 -05:00
fusb300_udc.h
goku_udc.c usb: gadget: goku_udc: add goku_match_ep() function 2015-08-06 09:34:46 -05:00
goku_udc.h
gr_udc.c usb: gadget: drop null test before destroy functions 2015-09-21 14:42:36 -05:00
gr_udc.h
Kconfig usb: gadget: at91_udc: mention proper dependency 2015-10-01 12:40:23 -05:00
lpc32xx_udc.c usb: gadget: lpc32xx_udc: add ep capabilities support 2015-08-04 12:26:46 -05:00
m66592-udc.c usb: gadget: m66592-udc: add ep capabilities support 2015-08-04 12:26:46 -05:00
m66592-udc.h
Makefile
mv_u3d.h
mv_u3d_core.c usb: gadget: drop null test before destroy functions 2015-09-21 14:42:36 -05:00
mv_udc.h
mv_udc_core.c usb: gadget: drop null test before destroy functions 2015-09-21 14:42:36 -05:00
net2272.c usb: gadget: net2272: add ep capabilities support 2015-08-04 12:26:48 -05:00
net2272.h
net2280.c USB: gadgetfs, dummy-hcd, net2280: fix locking for callbacks 2017-06-26 07:13:10 +02:00
net2280.h
omap_udc.c usb: gadget: omap_udc: add ep capabilities support 2015-08-04 12:26:50 -05:00
omap_udc.h
pch_udc.c usb: gadget: fix a trivial typo 2015-10-19 09:20:05 -05:00
pxa25x_udc.c usb: gadget: epautoconf: remove pxa quirk from ep_matches() 2015-08-04 12:27:15 -05:00
pxa25x_udc.h
pxa27x_udc.c usb: gadget: pxa27x: fix suspend callback 2015-11-19 14:48:35 -06:00
pxa27x_udc.h usb: gadget: pxa27x_udc: add ep capabilities support 2015-08-04 12:26:52 -05:00
r8a66597-udc.c usb: gadget: r8a66597-udc: add ep capabilities support 2015-08-04 12:26:53 -05:00
r8a66597-udc.h
s3c-hsudc.c usb: gadget: s3c-hsudc: add ep capabilities support 2015-08-04 12:26:53 -05:00
s3c2410_udc.c usb: gadget: s3c2410_udc: add ep capabilities support 2015-08-04 12:26:54 -05:00
s3c2410_udc.h
udc-core.c usb: gadget: udc: core: Fix argument of dev_err() in usb_gadget_map_request() 2016-06-01 12:15:52 -07:00
udc-xilinx.c usb: gadget: udc-xilinx: add ep capabilities support 2015-08-04 12:26:55 -05:00