From patchwork Wed Jan 8 08:01:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 3452391 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8FD899F1C4 for ; Wed, 8 Jan 2014 08:02:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 88D6F200D7 for ; Wed, 8 Jan 2014 08:02:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5DB03200E7 for ; Wed, 8 Jan 2014 08:02:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755574AbaAHIBy (ORCPT ); Wed, 8 Jan 2014 03:01:54 -0500 Received: from mail-lb0-f173.google.com ([209.85.217.173]:61593 "EHLO mail-lb0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755529AbaAHIBj (ORCPT ); Wed, 8 Jan 2014 03:01:39 -0500 Received: by mail-lb0-f173.google.com with SMTP id z5so1039473lbh.4 for ; Wed, 08 Jan 2014 00:01:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=jW39sf/rQxGzRTYaclCj1c6C+PgCQ3PCKznDEjV2tF4=; b=ATlLiH4+u0DBLTC1t40uPr3emPTtr6xC0It4WQPjCd365m3YWoTlzIilCGNj1GkJHG Zqab+sYP0iqKMKgtzAl2SkhMrO/ycjeSbvNtbRtL47OnlFmD1gdNpUwHMFl3DCfAOZ5a m0xUZz//TcvHGTlFMge5aapxjwSPz6+uWSCHPuIqfMuI/iONpNR0YbZiwn2JfoqBHf4g yNj1wrqmRG0nPuNbkS6V1K3uqQbF7g2LafRpIj7NyAL8y5y8Le4HRdxW+UpENqcjD8OB MBNXdtszKHwsEHh6r3WHLfRgkN5ZLowv/4INvq9bYR34Mbp16erXhxKzMIAMnnuLiWNn gfbw== X-Received: by 10.152.234.75 with SMTP id uc11mr5381969lac.30.1389168097760; Wed, 08 Jan 2014 00:01:37 -0800 (PST) Received: from neopili.qtec.com (0x4dd4aed9.adsl.cybercity.dk. [77.212.174.217]) by mx.google.com with ESMTPSA id z3sm59721111lag.10.2014.01.08.00.01.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Jan 2014 00:01:36 -0800 (PST) From: Ricardo Ribalda Delgado To: Marek Szyprowski , Hans Verkuil , Pawel Osciak , Kyungmin Park , Mauro Carvalho Chehab , "open list:VIDEOBUF2 FRAMEWORK" , open list Cc: Ricardo Ribalda Delgado Subject: [PATCH v3] vb2: Check if there are buffers before streamon Date: Wed, 8 Jan 2014 09:01:33 +0100 Message-Id: <1389168093-4923-1-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 1.8.5.2 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds a test preventing streamon() if there is no buffer ready. Without this patch, a user could call streamon() before preparing any buffer. This leads to a situation where if he calls close() before calling streamoff() the device is kept streaming. Signed-off-by: Ricardo Ribalda Delgado Reviewed-by: Marek Szyprowski --- v2: Comment by Marek Szyprowski: Reword error message v3: Comment by Marek Szyprowski: Actualy do the reword :) drivers/media/v4l2-core/videobuf2-core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index 098df28..6409e0a 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -1776,6 +1776,11 @@ static int vb2_internal_streamon(struct vb2_queue *q, enum v4l2_buf_type type) return 0; } + if (!q->num_buffers) { + dprintk(1, "streamon: no buffers have been allocated\n"); + return -EINVAL; + } + /* * If any buffers were queued before streamon, * we can now pass them to driver for processing.