From patchwork Thu Dec 28 16:29:35 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: 10135095 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 9499060388 for ; Thu, 28 Dec 2017 16:29:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86D002D889 for ; Thu, 28 Dec 2017 16:29:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BA652D894; Thu, 28 Dec 2017 16:29:51 +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 068FD2D889 for ; Thu, 28 Dec 2017 16:29:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751625AbdL1Q3r (ORCPT ); Thu, 28 Dec 2017 11:29:47 -0500 Received: from osg.samsung.com ([64.30.133.232]:59598 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750950AbdL1Q3p (ORCPT ); Thu, 28 Dec 2017 11:29:45 -0500 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id 935A626EFD; Thu, 28 Dec 2017 08:29:45 -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 yN2elT3J9pYE; Thu, 28 Dec 2017 08:29:44 -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 5387326EC1; 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-0006Eg-Sb; Thu, 28 Dec 2017 14:29:39 -0200 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Satendra Singh Thakur , Mauro Carvalho Chehab , Hans Verkuil , Sakari Ailus , Christophe JAILLET , Gustavo Padovan , Mauro Carvalho Chehab Subject: [PATCH 2/5] media: vb2: Fix a bug about unnecessary calls to queue cancel and free Date: Thu, 28 Dec 2017 14:29:35 -0200 Message-Id: <73a2a81d072b56ab25b36c0f40515d83ef45fccc.1514478428.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 Currently, there's a logic with checks if *count is non-zero, q->num_buffers is zero and q->memory is different than memory. That's flawed when the device is initialized, or after the queues are freed, as it does, unnecessary calls to __vb2_queue_cancel() and __vb2_queue_free(). That can be avoided by making sure that q->memory is set to VB2_MEMORY_UNKNOWN at vb2_core_queue_init(), and adding such check at the loop. [mchehab@s-opensource.com: fix checkpatch issues and improve the patch, by setting q->memory to zero at vb2_core_queue_init] Signed-off-by: Satendra Singh Thakur Signed-off-by: Mauro Carvalho Chehab Acked-by: Sakari Ailus --- drivers/media/common/videobuf/videobuf2-core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/media/common/videobuf/videobuf2-core.c b/drivers/media/common/videobuf/videobuf2-core.c index a3b4836fc41d..1793bdb1fe54 100644 --- a/drivers/media/common/videobuf/videobuf2-core.c +++ b/drivers/media/common/videobuf/videobuf2-core.c @@ -523,7 +523,7 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) q->num_buffers -= buffers; if (!q->num_buffers) { - q->memory = 0; + q->memory = VB2_MEMORY_UNKNOWN; INIT_LIST_HEAD(&q->queued_list); } return 0; @@ -665,7 +665,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 != VB2_MEMORY_UNKNOWN && q->memory != memory)) { /* * We already have buffers allocated, so first check if they * are not in use and can be freed. @@ -1997,6 +1998,8 @@ int vb2_core_queue_init(struct vb2_queue *q) mutex_init(&q->mmap_lock); init_waitqueue_head(&q->done_wq); + q->memory = VB2_MEMORY_UNKNOWN; + if (q->buf_struct_size == 0) q->buf_struct_size = sizeof(struct vb2_buffer);