diff mbox series

[4/7] usb: gadget: uvc: only schedule stream in streaming state

Message ID 20210930102717.15720-5-m.grzeschik@pengutronix.de (mailing list archive)
State Superseded
Headers show
Series usb: gadget: uvc: smaller fixes for stability | expand

Commit Message

Michael Grzeschik Sept. 30, 2021, 10:27 a.m. UTC
This patch ensures that the video pump thread will only be scheduled if
the uvc is really in streaming state. This way the worker will not have
to run on an empty queue.

Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
---
 drivers/usb/gadget/function/uvc_v4l2.c  | 3 ++-
 drivers/usb/gadget/function/uvc_video.c | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

Comments

Paul Elder Oct. 1, 2021, 2:54 a.m. UTC | #1
Hi Michael,

On Thu, Sep 30, 2021 at 12:27:14PM +0200, Michael Grzeschik wrote:
> This patch ensures that the video pump thread will only be scheduled if
> the uvc is really in streaming state. This way the worker will not have
> to run on an empty queue.
> 
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  drivers/usb/gadget/function/uvc_v4l2.c  | 3 ++-
>  drivers/usb/gadget/function/uvc_video.c | 4 +++-
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
> index 4ca89eab61590..67922b1355e69 100644
> --- a/drivers/usb/gadget/function/uvc_v4l2.c
> +++ b/drivers/usb/gadget/function/uvc_v4l2.c
> @@ -169,7 +169,8 @@ uvc_v4l2_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
>  	if (ret < 0)
>  		return ret;
>  
> -	schedule_work(&video->pump);
> +	if (uvc->state == UVC_STATE_STREAMING)
> +		schedule_work(&video->pump);
>  
>  	return ret;
>  }
> diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c
> index cdfd3726a86ae..ccee35177411d 100644
> --- a/drivers/usb/gadget/function/uvc_video.c
> +++ b/drivers/usb/gadget/function/uvc_video.c
> @@ -215,6 +215,7 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
>  	struct uvc_request *ureq = req->context;
>  	struct uvc_video *video = ureq->video;
>  	struct uvc_video_queue *queue = &video->queue;
> +	struct uvc_device *uvc = video->uvc;
>  	unsigned long flags;
>  
>  	switch (req->status) {
> @@ -237,7 +238,8 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
>  	list_add_tail(&req->list, &video->req_free);
>  	spin_unlock_irqrestore(&video->req_lock, flags);
>  
> -	schedule_work(&video->pump);
> +	if (uvc->state == UVC_STATE_STREAMING)
> +		schedule_work(&video->pump);
>  }
>  
>  static int
> -- 
> 2.30.2
>
Laurent Pinchart Oct. 4, 2021, 10:21 p.m. UTC | #2
Hi Michael,

Thank you for the patch.

On Thu, Sep 30, 2021 at 12:27:14PM +0200, Michael Grzeschik wrote:
> This patch ensures that the video pump thread will only be scheduled if
> the uvc is really in streaming state. This way the worker will not have
> to run on an empty queue.
> 
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/usb/gadget/function/uvc_v4l2.c  | 3 ++-
>  drivers/usb/gadget/function/uvc_video.c | 4 +++-
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
> index 4ca89eab61590..67922b1355e69 100644
> --- a/drivers/usb/gadget/function/uvc_v4l2.c
> +++ b/drivers/usb/gadget/function/uvc_v4l2.c
> @@ -169,7 +169,8 @@ uvc_v4l2_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
>  	if (ret < 0)
>  		return ret;
>  
> -	schedule_work(&video->pump);
> +	if (uvc->state == UVC_STATE_STREAMING)
> +		schedule_work(&video->pump);
>  
>  	return ret;
>  }
> diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c
> index cdfd3726a86ae..ccee35177411d 100644
> --- a/drivers/usb/gadget/function/uvc_video.c
> +++ b/drivers/usb/gadget/function/uvc_video.c
> @@ -215,6 +215,7 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
>  	struct uvc_request *ureq = req->context;
>  	struct uvc_video *video = ureq->video;
>  	struct uvc_video_queue *queue = &video->queue;
> +	struct uvc_device *uvc = video->uvc;
>  	unsigned long flags;
>  
>  	switch (req->status) {
> @@ -237,7 +238,8 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
>  	list_add_tail(&req->list, &video->req_free);
>  	spin_unlock_irqrestore(&video->req_lock, flags);
>  
> -	schedule_work(&video->pump);
> +	if (uvc->state == UVC_STATE_STREAMING)
> +		schedule_work(&video->pump);
>  }
>  
>  static int
diff mbox series

Patch

diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
index 4ca89eab61590..67922b1355e69 100644
--- a/drivers/usb/gadget/function/uvc_v4l2.c
+++ b/drivers/usb/gadget/function/uvc_v4l2.c
@@ -169,7 +169,8 @@  uvc_v4l2_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
 	if (ret < 0)
 		return ret;
 
-	schedule_work(&video->pump);
+	if (uvc->state == UVC_STATE_STREAMING)
+		schedule_work(&video->pump);
 
 	return ret;
 }
diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c
index cdfd3726a86ae..ccee35177411d 100644
--- a/drivers/usb/gadget/function/uvc_video.c
+++ b/drivers/usb/gadget/function/uvc_video.c
@@ -215,6 +215,7 @@  uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
 	struct uvc_request *ureq = req->context;
 	struct uvc_video *video = ureq->video;
 	struct uvc_video_queue *queue = &video->queue;
+	struct uvc_device *uvc = video->uvc;
 	unsigned long flags;
 
 	switch (req->status) {
@@ -237,7 +238,8 @@  uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
 	list_add_tail(&req->list, &video->req_free);
 	spin_unlock_irqrestore(&video->req_lock, flags);
 
-	schedule_work(&video->pump);
+	if (uvc->state == UVC_STATE_STREAMING)
+		schedule_work(&video->pump);
 }
 
 static int