Skip to contentSkip to conversation

media: pvrusb2: fix missing cleanup in pvr2_send_request_ex

RFC PATCH syzbot 2 participants 3 messages May 10 – May 12

Subsystems (2)
lore
Share & tools
lore

syzbot

author syzbot
#0 lore raw

media: pvrusb2: fix missing cleanup in pvr2_send_request_ex

In pvr2_send_request_ex(), if usb_urb_ep_type_check() fails on the read or write URB, the function returns directly without proper cleanup. This skips the timer_destroy_on_stack() call, leaking a timer debug object if CONFIG_DEBUG_OBJECTS_TIMERS is enabled.

Additionally, if the write URB was already submitted and the read URB check fails, returning directly leaves the write URB active. The next time pvr2_send_request_ex() is called, it attempts to reuse the active write URB, triggering a "URB submitted while active" warning in usb_submit_urb().

Fix this by replacing the direct returns with goto done and the appropriate cleanup logic, matching the rest of the error handling in the function.

Assisted-by Gemini:gemini-3.1-pro-preview

To: <[email protected]>
To: <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>

---

drivers/media/usb/pvrusb2/pvrusb2-hdw.c +11 -2
index 3c270ef00..dd504b1c4 100644
@@ -3669,7 +3669,9 @@ static int pvr2_send_request_ex(struct pvr2_hdw *hdw,
 			pvr2_trace(
 				PVR2_TRACE_ERROR_LEGS,
 				"Invalid write control endpoint");
-			return -EINVAL;
+			hdw->ctl_write_pend_flag = 0;
+			status = -EINVAL;
+			goto done;
 		}
 		status = usb_submit_urb(hdw->ctl_write_urb,GFP_KERNEL);
 		if (status < 0) {
@@ -3699,7 +3701,14 @@ status);
 			pvr2_trace(
 				PVR2_TRACE_ERROR_LEGS,
 				"Invalid read control endpoint");
-			return -EINVAL;
+			hdw->ctl_read_pend_flag = 0;
+			status = -EINVAL;
+			if (hdw->ctl_write_pend_flag) {
+				usb_unlink_urb(hdw->ctl_write_urb);
+				while (hdw->ctl_write_pend_flag)
+					wait_for_completion(&hdw->ctl_done);
+			}
+			goto done;
 		}
 		status = usb_submit_urb(hdw->ctl_read_urb,GFP_KERNEL);
 		if (status < 0) {

base-commit: 7fd2df204f342fc17d1a0bfcd474b24232fb0f32

Signature · 5 lines
This is an AI-generated patch subject to moderation.
Reply with '#syz upstream' to send it to the mailing list.
Reply with '#syz reject' to reject it.

See  for more information.
#1 lore raw

Why was it correct to replace return with goto done?

Quoted 70 lines · syzbot' via syzkaller-upstream-moderation

media: pvrusb2: fix missing cleanup in pvr2_send_request_ex

In pvr2_send_request_ex(), if usb_urb_ep_type_check() fails on the read or write URB, the function returns directly without proper cleanup. This skips the timer_destroy_on_stack() call, leaking a timer debug object if CONFIG_DEBUG_OBJECTS_TIMERS is enabled.

Additionally, if the write URB was already submitted and the read URB check fails, returning directly leaves the write URB active. The next time pvr2_send_request_ex() is called, it attempts to reuse the active write URB, triggering a "URB submitted while active" warning in usb_submit_urb().

Fix this by replacing the direct returns with goto done and the appropriate cleanup logic, matching the rest of the error handling in the function.

Assisted-by Gemini:gemini-3.1-pro-preview

To: <[email protected]>
To: <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>

---

drivers/media/usb/pvrusb2/pvrusb2-hdw.c +11 -2
index 3c270ef00..dd504b1c4 100644
@@ -3669,7 +3669,9 @@ static int pvr2_send_request_ex(struct pvr2_hdw *hdw,
                        pvr2_trace(
                                PVR2_TRACE_ERROR_LEGS,
                                "Invalid write control endpoint");
-                       return -EINVAL;
+                       hdw->ctl_write_pend_flag = 0;
+                       status = -EINVAL;
+                       goto done;
                }
                status = usb_submit_urb(hdw->ctl_write_urb,GFP_KERNEL);
                if (status < 0) {
@@ -3699,7 +3701,14 @@ status);
                        pvr2_trace(
                                PVR2_TRACE_ERROR_LEGS,
                                "Invalid read control endpoint");
-                       return -EINVAL;
+                       hdw->ctl_read_pend_flag = 0;
+                       status = -EINVAL;
+                       if (hdw->ctl_write_pend_flag) {
+                               usb_unlink_urb(hdw->ctl_write_urb);
+                               while (hdw->ctl_write_pend_flag)
+                                       wait_for_completion(&hdw->ctl_done);
+                       }
+                       goto done;
                }
                status = usb_submit_urb(hdw->ctl_read_urb,GFP_KERNEL);
                if (status < 0) {

base-commit: 7fd2df204f342fc17d1a0bfcd474b24232fb0f32 --
This is an AI-generated patch subject to moderation. Reply with '#syz upstream' to send it to the mailing list. Reply with '#syz reject' to reject it.

See for more information.

--
You received this message because you are subscribed to the Google Groups "syzkaller-upstream-moderation" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/syzkaller-upstream-moderation/8cbeab5b-2812-4567-845f-9baee48062fb%40mail.kernel.org.

author syzbot
#2 lore raw

Aggregated Comment Reply

As explained in the commit message, the `done:` label contains the necessary cleanup code, specifically `timer_destroy_on_stack()`. Returning directly skips this cleanup, which leads to a timer…

As explained in the commit message, the done: label contains the necessary cleanup code, specifically timer_destroy_on_stack(). Returning directly skips this cleanup, which leads to a timer debug object leak if CONFIG_DEBUG_OBJECTS_TIMERS is enabled. Using goto done; ensures the timer is properly destroyed before the function returns.

Signature · 2 lines
This reply was generated by an AI model.
See  for more information.