Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752653AbeAFSha (ORCPT + 1 other); Sat, 6 Jan 2018 13:37:30 -0500 Received: from galahad.ideasonboard.com ([185.26.127.97]:43478 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750932AbeAFSh3 (ORCPT ); Sat, 6 Jan 2018 13:37:29 -0500 Subject: Re: [RFC/RFT PATCH 3/6] uvcvideo: Protect queue internals with helper To: Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, laurent.pinchart@ideasonboard.com, Olivier BRAUN , kieran.bingham@ideasonboard.com, Mauro Carvalho Chehab , Hans Verkuil , Jaejoong Kim , Baoyou Xie , Nicolas Dufresne , Greg Kroah-Hartman , Jim Lin , Daniel Patrick Johnson References: From: Kieran Bingham Organization: Ideas on Board Message-ID: Date: Sat, 6 Jan 2018 18:37:24 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Hi Guennadi, On 04/01/18 18:25, Guennadi Liakhovetski wrote: > Hi Kieran, > > On Wed, 3 Jan 2018, Kieran Bingham wrote: > >> From: Kieran Bingham >> >> 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 >> Reviewed-by: Laurent Pinchart >> --- >> 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(...); Ah yes, I believe you are correct. Good spot! Fixed, and looks much neater. -- Kieran > > Thanks > Guennadi >