Message ID | 20231024183605.908253-3-arakesh@google.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [v8,1/4] usb: gadget: uvc: prevent use of disabled endpoint | expand |
Hi Avichal On 24/10/2023 19:36, Avichal Rakesh wrote: > This patch refactors the video disable logic in uvcg_video_enable > into its own separate function 'uvcg_video_disable'. In that case, can we just replace any calls to uvcg_video_enable(video, 0) with calls to uvcg_video_disable() directly and drop the enable argument from uvcg_video_enable()? > Suggested-by: Michael Grzeschik <m.grzeschik@pengutronix.de> > Signed-off-by: Avichal Rakesh <arakesh@google.com> > --- > v6: Introduced this patch to make the next one easier to review > v6 -> v7: Add Suggested-by > v7 -> v8: No change. Getting back in review queue > > drivers/usb/gadget/function/uvc_video.c | 37 +++++++++++++++---------- > 1 file changed, 23 insertions(+), 14 deletions(-) > > diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c > index c180866c8e34..80b8eaea2d39 100644 > --- a/drivers/usb/gadget/function/uvc_video.c > +++ b/drivers/usb/gadget/function/uvc_video.c > @@ -493,13 +493,33 @@ static void uvcg_video_pump(struct work_struct *work) > return; > } > > +/* > + * Disable video stream > + */ > +static int > +uvcg_video_disable(struct uvc_video *video) > +{ > + struct uvc_request *ureq; > + > + cancel_work_sync(&video->pump); > + uvcg_queue_cancel(&video->queue, 0); > + > + list_for_each_entry(ureq, &video->ureqs, list) { > + if (ureq->req) > + usb_ep_dequeue(video->ep, ureq->req); > + } > + > + uvc_video_free_requests(video); > + uvcg_queue_enable(&video->queue, 0); > + return 0; > +} > + > /* > * Enable or disable the video stream. > */ > int uvcg_video_enable(struct uvc_video *video, int enable) > { > int ret; > - struct uvc_request *ureq; > > if (video->ep == NULL) { > uvcg_info(&video->uvc->func, > @@ -507,19 +527,8 @@ int uvcg_video_enable(struct uvc_video *video, int enable) > return -ENODEV; > } > > - if (!enable) { > - cancel_work_sync(&video->pump); > - uvcg_queue_cancel(&video->queue, 0); > - > - list_for_each_entry(ureq, &video->ureqs, list) { > - if (ureq->req) > - usb_ep_dequeue(video->ep, ureq->req); > - } > - > - uvc_video_free_requests(video); > - uvcg_queue_enable(&video->queue, 0); > - return 0; > - } > + if (!enable) > + return uvcg_video_disable(video); > > if ((ret = uvcg_queue_enable(&video->queue, 1)) < 0) > return ret; > -- > 2.42.0.758.gaed0368e0e-goog
diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c index c180866c8e34..80b8eaea2d39 100644 --- a/drivers/usb/gadget/function/uvc_video.c +++ b/drivers/usb/gadget/function/uvc_video.c @@ -493,13 +493,33 @@ static void uvcg_video_pump(struct work_struct *work) return; } +/* + * Disable video stream + */ +static int +uvcg_video_disable(struct uvc_video *video) +{ + struct uvc_request *ureq; + + cancel_work_sync(&video->pump); + uvcg_queue_cancel(&video->queue, 0); + + list_for_each_entry(ureq, &video->ureqs, list) { + if (ureq->req) + usb_ep_dequeue(video->ep, ureq->req); + } + + uvc_video_free_requests(video); + uvcg_queue_enable(&video->queue, 0); + return 0; +} + /* * Enable or disable the video stream. */ int uvcg_video_enable(struct uvc_video *video, int enable) { int ret; - struct uvc_request *ureq; if (video->ep == NULL) { uvcg_info(&video->uvc->func, @@ -507,19 +527,8 @@ int uvcg_video_enable(struct uvc_video *video, int enable) return -ENODEV; } - if (!enable) { - cancel_work_sync(&video->pump); - uvcg_queue_cancel(&video->queue, 0); - - list_for_each_entry(ureq, &video->ureqs, list) { - if (ureq->req) - usb_ep_dequeue(video->ep, ureq->req); - } - - uvc_video_free_requests(video); - uvcg_queue_enable(&video->queue, 0); - return 0; - } + if (!enable) + return uvcg_video_disable(video); if ((ret = uvcg_queue_enable(&video->queue, 1)) < 0) return ret;
This patch refactors the video disable logic in uvcg_video_enable into its own separate function 'uvcg_video_disable'. Suggested-by: Michael Grzeschik <m.grzeschik@pengutronix.de> Signed-off-by: Avichal Rakesh <arakesh@google.com> --- v6: Introduced this patch to make the next one easier to review v6 -> v7: Add Suggested-by v7 -> v8: No change. Getting back in review queue drivers/usb/gadget/function/uvc_video.c | 37 +++++++++++++++---------- 1 file changed, 23 insertions(+), 14 deletions(-) -- 2.42.0.758.gaed0368e0e-goog