public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: irtoy: fix race between device disconnection and urb callback
@ 2025-11-14 10:13 Haotian Zhang
  0 siblings, 0 replies; only message in thread
From: Haotian Zhang @ 2025-11-14 10:13 UTC (permalink / raw)
  To: sean, mchehab; +Cc: linux-media, linux-kernel, Haotian Zhang

The irtoy_disconnect() function calls rc_unregister_device() before
usb_kill_urb(), creating a race condition similar to the one fixed in
commit 'f656cfbc7a29'. If rc_unregister_device() executes while
the URB callback irtoy_in_callback() is still running, irtoy_response()
may call ir_raw_event_store_with_timeout() with a freed
irtoy->rc->raw pointer, leading to a NULL pointer dereference.

Call usb_kill_urb() before rc_unregister_device() to ensure all URB
callbacks complete before freeing device resources.

Fixes: 261463dbc34f ("media: rc: add support for Infrared Toy and IR Droid devices")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
 drivers/media/rc/ir_toy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/rc/ir_toy.c b/drivers/media/rc/ir_toy.c
index 533faa117517..630e0cc840e2 100644
--- a/drivers/media/rc/ir_toy.c
+++ b/drivers/media/rc/ir_toy.c
@@ -530,11 +530,11 @@ static void irtoy_disconnect(struct usb_interface *intf)
 {
 	struct irtoy *ir = usb_get_intfdata(intf);
 
+	usb_kill_urb(ir->urb_out);
+	usb_kill_urb(ir->urb_in);
 	rc_unregister_device(ir->rc);
 	usb_set_intfdata(intf, NULL);
-	usb_kill_urb(ir->urb_out);
 	usb_free_urb(ir->urb_out);
-	usb_kill_urb(ir->urb_in);
 	usb_free_urb(ir->urb_in);
 	kfree(ir->in);
 	kfree(ir->out);
-- 
2.50.1.windows.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-11-14 10:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-14 10:13 [PATCH] media: irtoy: fix race between device disconnection and urb callback Haotian Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox