From patchwork Thu Dec 28 16:29:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10135091 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8EBE360388 for ; Thu, 28 Dec 2017 16:29:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80F242D889 for ; Thu, 28 Dec 2017 16:29:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7443E2D894; Thu, 28 Dec 2017 16:29:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7B9B2D889 for ; Thu, 28 Dec 2017 16:29:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751376AbdL1Q3p (ORCPT ); Thu, 28 Dec 2017 11:29:45 -0500 Received: from osg.samsung.com ([64.30.133.232]:35730 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750950AbdL1Q3o (ORCPT ); Thu, 28 Dec 2017 11:29:44 -0500 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id 8BF8A26ED8; Thu, 28 Dec 2017 08:29:43 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from osg.samsung.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BB0aQACUEbST; Thu, 28 Dec 2017 08:29:42 -0800 (PST) Received: from smtp.s-opensource.com (179.176.121.132.dynamic.adsl.gvt.net.br [179.176.121.132]) by osg.samsung.com (Postfix) with ESMTPSA id 3289926EBD; Thu, 28 Dec 2017 08:29:42 -0800 (PST) Received: from mchehab by smtp.s-opensource.com with local (Exim 4.89) (envelope-from ) id 1eUb3r-0006Ek-T8; Thu, 28 Dec 2017 14:29:39 -0200 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Sakari Ailus , Mauro Carvalho Chehab , Hans Verkuil , Christophe JAILLET , Hirokazu Honda , Stanimir Varbanov , Satendra Singh Thakur , Mauro Carvalho Chehab Subject: [PATCH 3/5] media: vb2: Enforce VB2_MAX_FRAME in vb2_core_reqbufs better Date: Thu, 28 Dec 2017 14:29:36 -0200 Message-Id: X-Mailer: git-send-email 2.14.3 In-Reply-To: References: In-Reply-To: References: Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sakari Ailus The check for the number of buffers requested against the maximum, VB2_MAX_FRAME, was performed before checking queue's minimum number of buffers. Reverse the order, thus ensuring that under no circumstances num_buffers exceeds VB2_MAX_FRAME here. Also add a warning of the condition. Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/media/common/videobuf/videobuf2-core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/common/videobuf/videobuf2-core.c b/drivers/media/common/videobuf/videobuf2-core.c index 1793bdb1fe54..ba04103f2f32 100644 --- a/drivers/media/common/videobuf/videobuf2-core.c +++ b/drivers/media/common/videobuf/videobuf2-core.c @@ -700,8 +700,9 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, /* * Make sure the requested values and current defaults are sane. */ - num_buffers = min_t(unsigned int, *count, VB2_MAX_FRAME); - num_buffers = max_t(unsigned int, num_buffers, q->min_buffers_needed); + WARN_ON(q->min_buffers_needed > VB2_MAX_FRAME); + num_buffers = max_t(unsigned int, *count, q->min_buffers_needed); + num_buffers = min_t(unsigned int, num_buffers, VB2_MAX_FRAME); memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); q->memory = memory;