linux/drivers/media/usb
Ricardo Ribalda 8e62139840 media: uvcvideo: Fix race condition with usb_kill_urb
commit 619d9b710c upstream.

usb_kill_urb warranties that all the handlers are finished when it
returns, but does not protect against threads that might be handling
asynchronously the urb.

For UVC, the function uvc_ctrl_status_event_async() takes care of
control changes asynchronously.

If the code is executed in the following order:

CPU 0					CPU 1
===== 					=====
uvc_status_complete()
					uvc_status_stop()
uvc_ctrl_status_event_work()
					uvc_status_start() -> FAIL

Then uvc_status_start will keep failing and this error will be shown:

<4>[    5.540139] URB 0000000000000000 submitted while active
drivers/usb/core/urb.c:378 usb_submit_urb+0x4c3/0x528

Let's improve the current situation, by not re-submiting the urb if
we are stopping the status event. Also process the queued work
(if any) during stop.

CPU 0					CPU 1
===== 					=====
uvc_status_complete()
					uvc_status_stop()
					uvc_status_start()
uvc_ctrl_status_event_work() -> FAIL

Hopefully, with the usb layer protection this should be enough to cover
all the cases.

Cc: stable@vger.kernel.org
Fixes: e5225c820c ("media: uvcvideo: Send a control event when a Control Change interrupt arrives")
Reviewed-by: Yunke Cao <yunkec@chromium.org>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2023-03-11 13:57:39 +01:00
..
airspy media: rtl2832_sdr/vivid/airspy/hackrf/msi2500: drop memset of fmt.sdr.reserved 2021-05-19 09:51:39 +02:00
as102 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 118 2019-05-24 17:39:02 +02:00
au0828 media: au0828: fix a NULL vs IS_ERR() check 2021-06-02 13:30:28 +02:00
b2c2 media: flexcop-usb: fix endpoint type check 2022-09-28 11:11:42 +02:00
cpia2 media: cpia2: fix control-message timeouts 2022-01-27 11:02:55 +01:00
cx231xx media: cx231xx/cx231xx.h: Remove repeated struct declaration 2021-04-06 16:10:19 +02:00
dvb-usb media: dvb-usb: fix memory leak in dvb_usb_adapter_init() 2022-12-31 13:14:43 +01:00
dvb-usb-v2 media: mxl111sf: change mutex_init() location 2021-12-22 09:32:50 +01:00
em28xx media: Revert "media: em28xx: add missing em28xx_close_extension" 2022-04-08 14:24:02 +02:00
go7007 media: usb: go7007: s2250-board: fix leak in probe() 2022-04-08 14:23:17 +02:00
gspca media: drivers/media/usb/gspca: fix typo Fliker -> Flicker 2021-07-12 09:16:33 +02:00
hackrf media: rtl2832_sdr/vivid/airspy/hackrf/msi2500: drop memset of fmt.sdr.reserved 2021-05-19 09:51:39 +02:00
hdpvr media: hdpvr: fix error value returns in hdpvr_read 2022-08-17 14:23:23 +02:00
msi2500 media: rtl2832_sdr/vivid/airspy/hackrf/msi2500: drop memset of fmt.sdr.reserved 2021-05-19 09:51:39 +02:00
pvrusb2 media: pvrusb2: fix memory leak in pvr_probe 2022-09-05 10:30:07 +02:00
pwc treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
s2255 media: s2255: fix control-message timeouts 2022-01-27 11:02:55 +01:00
siano media: usb: siano: Fix use after free bugs caused by do_submit_urb 2023-03-10 09:39:46 +01:00
stk1160 media: stk1160: If start stream fails, return buffers with VB2_BUF_STATE_QUEUED 2022-04-08 14:23:20 +02:00
stkwebcam media: stkwebcam: fix memory leak in stk_camera_probe 2021-07-22 14:01:55 +02:00
tm6000 media: tm6000: Avoid card name truncation 2021-11-18 19:16:29 +01:00
ttusb-budget media: dvb-ttusb-budget: cleanup printk logic 2020-09-03 11:15:47 +02:00
ttusb-dec media: ttusb-dec: avoid release of non-acquired mutex 2021-11-18 19:16:27 +01:00
usbtv media updates for v5.13-rc1 2021-04-28 09:24:36 -07:00
uvc media: uvcvideo: Fix race condition with usb_kill_urb 2023-03-11 13:57:39 +01:00
zr364xx media: zr364xx: fix memory leak in zr364xx_start_readpipe 2021-06-02 13:35:15 +02:00
Kconfig media: move ttpci-eeprom to common 2021-06-02 11:16:15 +02:00
Makefile media: move CEC USB drivers to a separate directory 2020-04-15 12:06:40 +02:00