From patchwork Tue Mar 11 22:52:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Sheu X-Patchwork-Id: 3814821 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D21BEBF540 for ; Tue, 11 Mar 2014 22:52:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C04B320260 for ; Tue, 11 Mar 2014 22:52:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 950F220263 for ; Tue, 11 Mar 2014 22:52:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755565AbaCKWwg (ORCPT ); Tue, 11 Mar 2014 18:52:36 -0400 Received: from mail-oa0-f73.google.com ([209.85.219.73]:48280 "EHLO mail-oa0-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755364AbaCKWwf (ORCPT ); Tue, 11 Mar 2014 18:52:35 -0400 Received: by mail-oa0-f73.google.com with SMTP id n16so1963236oag.2 for ; Tue, 11 Mar 2014 15:52:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aiyUGnlgCPSRk9+ju+RsGE7Tpw1yVxO+PaqfIA2M6P0=; b=auAlgmIwT6SvcOmvaKuVDXQXwMEffmZ9pP7alLA7aDtDi7ODO1xJPyAP3DcC9dR6/V pRKzKjjAtyjODAW6aDU/eu87A74aft9HXanQKbHLZmUWGWlHfH4xwDnj0bfTUKzJfyXB 6p5LmX3/RcVefpA1Db5zA4rgfH4l7AhZMzGktpPzhPRlLskBgxhYHaSGuDJnzL4TWhzq EB3Og3ktGQxmLhPN4OECpoZgXx+OhFvpgfaiOtQqqC2PFr1jnQqSH88psHlF+bSBQJpR MkfPYBdkrs/WCgfu9fG7GU1RKtXIzY3dFaOYb8dr0x5ODAeAjEau46zduhN8iPUJL9CA vQkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aiyUGnlgCPSRk9+ju+RsGE7Tpw1yVxO+PaqfIA2M6P0=; b=fu8PMVqaCqiJM3zQ3x/BPR5LVlmKA9eyntqbnMNxuicWh+jtbHylK2tXomcoOZ/tCf sZKAsM7/tXn2vyYelSEmjWSljBXJGzTQZ7KKPhOMdSYsMzRJiMnfOUsbnfpMFUsFdyhC AvJB3aF/N5lAFtv79xXnpEXpQ4I5E+VjBd/V044U2cJ/ZzY4XJRcD/+Z78iLAZhlrRo5 NQXoT9mkNKy9af6O0t7qGRMS4zx5JaX9fzt+PL24zuur0QXWCXM367psFMh3QMkU4l98 gGg6EqMC2uz32zC6Zqe5eucZlTIVKJOLEfA8o4lslgqlUfX9qWXluL6h5Vnu6Btan49q L6Hg== X-Gm-Message-State: ALoCoQmey6YmZYOhRpIZlq/04HqLw1AJVBCjsxLQItGRSC27cf5XYl4bSwOpazKFhqMsxDF6+ds3XsInBPdlqOHvByAWnlTWypQbON1y+SULsSG0sXE78Vp1Yx6d1eJH5snlKiMjDx0Amuoh94kzktu1FDVyd1XQLXJ19hv036rGjLRCxzKkmuSGORdmnx6nQdlv2erNN1dpHDxnTNBRQt5cgxPGZEh3dA== X-Received: by 10.50.78.231 with SMTP id e7mr11096012igx.5.1394578354861; Tue, 11 Mar 2014 15:52:34 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id s66si626166yhs.6.2014.03.11.15.52.34 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Mar 2014 15:52:34 -0700 (PDT) Received: from shortskirt.mtv.corp.google.com (shortskirt.mtv.corp.google.com [172.22.70.255]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 8DDD55A42C3; Tue, 11 Mar 2014 15:52:34 -0700 (PDT) Received: by shortskirt.mtv.corp.google.com (Postfix, from userid 157237) id 49E4BC0575; Tue, 11 Mar 2014 15:52:34 -0700 (PDT) From: John Sheu To: linux-media@vger.kernel.org Cc: m.chehab@samsung.com, k.debski@samsung.com, posciak@google.com, arun.m@samsung.com, kgene.kim@samsung.com, John Sheu Subject: [PATCH 4/4] v4l2-mem2mem: allow reqbufs(0) with "in use" MMAP buffers Date: Tue, 11 Mar 2014 15:52:05 -0700 Message-Id: <1394578325-11298-5-git-send-email-sheu@google.com> X-Mailer: git-send-email 1.9.0.279.gdc9e3eb In-Reply-To: <1394578325-11298-1-git-send-email-sheu@google.com> References: <1394578325-11298-1-git-send-email-sheu@google.com> 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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD, 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 v4l2-mem2mem presently does not allow VIDIOC_REQBUFS to destroy outstanding buffers if the queue is of type V4L2_MEMORY_MMAP, and if the buffers are considered "in use". This is different behavior than for other memory types, and prevents us for deallocating buffers in a few cases: * In the case that there are outstanding mmap()ed views on the buffer, refcounting on the videobuf2 buffer backing the vm_area will track lifetime appropriately, * In the case that the buffer has been exported as a DMABUF, refcounting on the videobuf2 bufer backing the DMABUF will track lifetime appropriately. Remove the specific check for type V4L2_MEMOMRY_MMAP when freeing all buffers through VIDIOC_REQBUFS. Signed-off-by: John Sheu --- drivers/media/v4l2-core/videobuf2-core.c | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index 8e6695c9..5b6f9da6 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -414,8 +414,7 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b) } /** - * __buffer_in_use() - return true if the buffer is in use and - * the queue cannot be freed (by the means of REQBUFS(0)) call + * __buffer_in_use() - return true if the buffer is in use. */ static bool __buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb) { @@ -435,20 +434,6 @@ static bool __buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb) } /** - * __buffers_in_use() - return true if any buffers on the queue are in use and - * the queue cannot be freed (by the means of REQBUFS(0)) call - */ -static bool __buffers_in_use(struct vb2_queue *q) -{ - unsigned int buffer; - for (buffer = 0; buffer < q->num_buffers; ++buffer) { - if (__buffer_in_use(q, q->bufs[buffer])) - return true; - } - return false; -} - -/** * __fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be * returned to userspace */ @@ -681,15 +666,6 @@ static int __reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) } if (req->count == 0 || q->num_buffers != 0 || q->memory != req->memory) { - /* - * We already have buffers allocated, so first check if they - * are not in use and can be freed. - */ - if (q->memory == V4L2_MEMORY_MMAP && __buffers_in_use(q)) { - dprintk(1, "reqbufs: memory in use, cannot free\n"); - return -EBUSY; - } - ret = __vb2_queue_free(q, q->num_buffers); if (ret) return ret;