From patchwork Thu Dec 21 16:18:00 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: 10128005 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 04C0F6019C for ; Thu, 21 Dec 2017 16:18:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBCEA29D51 for ; Thu, 21 Dec 2017 16:18:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E097C29D54; Thu, 21 Dec 2017 16:18:19 +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 1108329D56 for ; Thu, 21 Dec 2017 16:18:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752957AbdLUQSR (ORCPT ); Thu, 21 Dec 2017 11:18:17 -0500 Received: from osg.samsung.com ([64.30.133.232]:61596 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751655AbdLUQSQ (ORCPT ); Thu, 21 Dec 2017 11:18:16 -0500 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id 5EFB919230; Thu, 21 Dec 2017 08:18:15 -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 TEp8QTtLMnQC; Thu, 21 Dec 2017 08:18:14 -0800 (PST) Received: from smtp.s-opensource.com (unknown [177.159.255.83]) by osg.samsung.com (Postfix) with ESMTPSA id E2ED819219; Thu, 21 Dec 2017 08:18:13 -0800 (PST) Received: from mchehab by smtp.s-opensource.com with local (Exim 4.89) (envelope-from ) id 1eS3Xv-0005RW-9z; Thu, 21 Dec 2017 14:18:11 -0200 From: Mauro Carvalho Chehab To: Linux Media Mailing List , Jonathan Corbet Cc: Satendra Singh Thakur , Mauro Carvalho Chehab , Linux Doc Mailing List , Pawel Osciak , Marek Szyprowski , Kyungmin Park , Mauro Carvalho Chehab Subject: [PATCH 01/11] media: vb2-core: Fix a bug about unnecessary calls to queue cancel and free Date: Thu, 21 Dec 2017 14:18:00 -0200 Message-Id: <4a42c988b7b63fa2804b3ffcb3a1f122e3b9836e.1513872637.git.mchehab@s-opensource.com> 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: Satendra Singh Thakur When the func vb2_core_reqbufs is called first time after vb2_core_queue_init(), the condition q->memory != memory always gets satisfied, since q->memory was set to 0 at vb2_core_queue_init(). After the condition is true, unnecessary calls to __vb2_queue_cancel() and __vb2_queue_free() are done. in such case, *count is non-zero, q->num_buffers is zero and q->memory is 0, which is not equal to memory field *count=N, q->num_buffers=0, q->memory != memory. [mchehab@s-opensource.com: fix checkpatch issues] Signed-off-by: Satendra Singh Thakur Signed-off-by: Mauro Carvalho Chehab --- drivers/media/v4l2-core/videobuf2-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index cb115ba6a1d2..21017b478a34 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -662,7 +662,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, return -EBUSY; } - if (*count == 0 || q->num_buffers != 0 || q->memory != memory) { + if (*count == 0 || q->num_buffers != 0 || + (q->memory && q->memory != memory)) { /* * We already have buffers allocated, so first check if they * are not in use and can be freed.