Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752887AbeADS0H (ORCPT + 1 other); Thu, 4 Jan 2018 13:26:07 -0500 Received: from mout.gmx.net ([212.227.17.20]:50210 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750990AbeADS0D (ORCPT ); Thu, 4 Jan 2018 13:26:03 -0500 Date: Thu, 4 Jan 2018 19:25:02 +0100 (CET) From: Guennadi Liakhovetski X-X-Sender: lyakh@axis700.grange To: Kieran Bingham 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 Subject: Re: [RFC/RFT PATCH 3/6] uvcvideo: Protect queue internals with helper In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Provags-ID: V03:K0:ax4d5f3jWmiN9bhl660elOGLwfwyDs3+NFpdtA2QIaXqxmEJ/0u eUvngerdG8Vqnoo5Dp/gtJk8ylRj7vATURMHrDudddc7YhGUbKS16FTCd+mQFtEr+nhQWxK A8GloYT4iZQmbdDBzjKn5G5voQX02gEGskWeSRwrQkpPNvTBzp5tVLbSmeXz9Negefn4UpF 7jZDr/g5omaos+KSiWZXg== X-UI-Out-Filterresults: notjunk:1;V01:K0:KOOq0rphD88=:LWM2rX6funirurOEhMsSRo LiGjpM0UMsPaQYZTdpQXuBI5EnaVq+u0Ip6BqGbJZK/rkqJohATSQLPJPELI5FCGUAw7nJCiF vQjz4y3SlT93sNDgkcFvcyxqKuHj1uCaMqHeZX7T67Y5OS1iKBhCMq/4gwycaq1Nj5yB429l2 AD32wDLh9jm08K5wB8kbtcaEGUrmZ2FUxFEnHL0P4qBBNGYaRFokOibVdQnHi/MzS/0TpVobg k1dtqtIdV+30vmDaDg4AxrOPdBKyPCoPq6muRGu3N+A9xyZwHhZaN/g0vsKeuuqY88kixfasP ByzC/Llz3nN5dP+jUH4uEAmNtfXblugvHnGYxzEokr5V0Do4kUFyQJo9Xp9c+WaM02jcpLx8Z 6JaAq0HGnC2utipQaBWtEllCmEi23tMdJArAgtSSPatbsiqMi4DEyE7i5RBa7Gb6qiX0VtF0s b8B8BDZ3UwKkF9imuJBFqBcnyVyhl8ux+bU9qWjrANxmjg8cuu6ytd40/DVs6zlksXAUAcPBY inXKCC+eJcCk9S2nISovbVx0im9numi2sWSeY70xmjfAMuzN5BSDwXkW9PcNSgoTr2GyHg9I4 5YqC4yNR5H9myqylBEQKmUYmLth/qgjyuQBLrtYFk1emB3YH7l4+pepmER8P7PCPxd6aotJ01 ZBXoClfz16X7X5sPiTvc+oy7DtA85Y0HHsCm84s8KYGcIhc7TpDsdz2es/fDatKtvVGbOuzHu SO4xAKs7cj6OIW4rVukc/NFeBehZ+idlzWyq2lyLkZJPXFH36wqyVxHwgKHKpaHuRCJjG0KIn j53HGxqEP/a2GKHq3HPxiq90Dry15DykRIrbtFre+RSk7FRFLc= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: 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(...); Thanks Guennadi