Re: [RFC/RFT PATCH 3/6] uvcvideo: Protect queue internals with helper
From: Guennadi Liakhovetski
Date: Thu Jan 04 2018 - 13:26:10 EST
Hi Kieran,
On Wed, 3 Jan 2018, Kieran Bingham wrote:
> From: Kieran Bingham <kieran.bingham@xxxxxxxxxxxxxxxx>
>
> The URB completion operation obtains the current buffer by reading
> directly into the queue internal interface.
>
> Protect this queue abstraction by providing a helper
> uvc_queue_get_current_buffer() which can be used by both the decode
> task, and the uvc_queue_next_buffer() functions.
>
> Signed-off-by: Kieran Bingham <kieran.bingham@xxxxxxxxxxxxxxxx>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>
> ---
> drivers/media/usb/uvc/uvc_queue.c | 34 +++++++++++++++++++++++++++-----
> drivers/media/usb/uvc/uvc_video.c | 7 +------
> drivers/media/usb/uvc/uvcvideo.h | 2 ++-
> 3 files changed, 32 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
> index c8d78b2f3de4..0711e3d9ff76 100644
> --- a/drivers/media/usb/uvc/uvc_queue.c
> +++ b/drivers/media/usb/uvc/uvc_queue.c
> @@ -399,6 +399,34 @@ void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect)
> spin_unlock_irqrestore(&queue->irqlock, flags);
> }
>
> +/*
> + * uvc_queue_get_current_buffer: Obtain the current working output buffer
> + *
> + * Buffers may span multiple packets, and even URBs, therefore the active buffer
> + * remains on the queue until the EOF marker.
> + */
> +static struct uvc_buffer *
> +__uvc_queue_get_current_buffer(struct uvc_video_queue *queue)
> +{
> + if (!list_empty(&queue->irqqueue))
> + return list_first_entry(&queue->irqqueue, struct uvc_buffer,
> + queue);
> + else
> + return NULL;
I think the preferred style is not to use "else" in such cases. It might
even be prettier to write
if (list_empty(...))
return NULL;
return list_first_entry(...);
Thanks
Guennadi