From patchwork Wed Oct 9 23:49:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Sheu X-Patchwork-Id: 3013251 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 EBB02BF924 for ; Wed, 9 Oct 2013 23:50:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 14F1E202A7 for ; Wed, 9 Oct 2013 23:50:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 31198202A1 for ; Wed, 9 Oct 2013 23:50:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756061Ab3JIXuj (ORCPT ); Wed, 9 Oct 2013 19:50:39 -0400 Received: from mail-pb0-f74.google.com ([209.85.160.74]:40432 "EHLO mail-pb0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754384Ab3JIXuh (ORCPT ); Wed, 9 Oct 2013 19:50:37 -0400 Received: by mail-pb0-f74.google.com with SMTP id rq2so131287pbb.3 for ; Wed, 09 Oct 2013 16:50:36 -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=YO+8pQNdRz7gdhGi/uguh4SRU+HKMA41Iy0hklSNxk8=; b=ZzAJOv+jSEyi29SCA1h2sV85IsxVtfWicpOvkTz6RxCrAADTFbeYXAsmAw2/vu7zKX jZaBmUYpmHau5Wfb5gOtFsylaCxQ/8BTm1aFYiQIATu9fhc6apS/KQgWBKV6T9iMsvtl jMDjU6J6PZ560baX9xrzGaW+5DPoT44YVvZh6mt/UuA8eFrBSTMSd+Isxs8rKgRpbPn/ c7vJJg9D/E/XYpYfUKLkCUGIAOUT10ijV0Ym+l73H9NQ8g29ad9kUXs/BQHF4Bbue6+N yXJq5HuIsJY39xKOP9w6S33soJI3wEDrH4jwMBRJW9ABbLWrY6X3z4WftVmDIsXpi3Tr LZFA== 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=YO+8pQNdRz7gdhGi/uguh4SRU+HKMA41Iy0hklSNxk8=; b=HQ9YWMhagajA3latx4IxN8lpadNzaHKy8lLAoJJAnObUmQ4b/seSBYibxjM8kcHRCN 4/R6rhq+ls0PCfswAkT9qa935TLaQfx/TAWH4ZmhCW8wxPeWEBS9gIghQI+lnwSVCqap rrA/aGPBH2FzpuVZtGvYmco3OYOy3jh5dXnQYaOyIuRrlWEYz1HIUZMNGOUeiH8SlYcp REn22/p6CuHwXCF/otgzXp5SSsz7uxeJ9CZKch+UTWa7cKV0qavPbCSSWmbZiOeLNjgJ 1P06O4dm1NahS4YAoZPf3IrGGUWB55BDTRgGpM/T4dPfyo2L0MBwtc0sWsLGAUIaGVD1 bokA== X-Gm-Message-State: ALoCoQkfbIyQaEdcauuEJCx6N8RWDUJDA1EErjSp/YSEYyz/bYpa6RdLlZUvk/oivELRBq8Q+1HvWIgYpoXp6UtEy9vgwotp7uspjd01X9Vq0ONvf3nsfOYkvmeyXoM22S5vcCDsc4HAjSFbwwUuwNvowHewfQNclCabUoFVcpQWLEE/aCIdqwFbXpoZay0c4Ef6ZOeAlKXF7kkswLPWhCBGTQB8Ph13Uw== X-Received: by 10.66.20.100 with SMTP id m4mr3424847pae.36.1381362636695; Wed, 09 Oct 2013 16:50:36 -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 k47si68281yha.2.1969.12.31.16.00.00 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Wed, 09 Oct 2013 16:50:36 -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 7CC5A5A4173; Wed, 9 Oct 2013 16:50:36 -0700 (PDT) Received: by shortskirt.mtv.corp.google.com (Postfix, from userid 157237) id 1BB18C0F2E; Wed, 9 Oct 2013 16:50:36 -0700 (PDT) From: John Sheu To: linux-media@vger.kernel.org Cc: John Sheu , m.chehab@samsung.com, k.debski@samsung.com, pawel@osciak.com Subject: [PATCH 6/6] [media] v4l2-mem2mem: allow reqbufs(0) with "in use" MMAP buffers Date: Wed, 9 Oct 2013 16:49:49 -0700 Message-Id: <1381362589-32237-7-git-send-email-sheu@google.com> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1381362589-32237-1-git-send-email-sheu@google.com> References: <1381362589-32237-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=-7.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, 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 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 fc8af50..3c31efb 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -369,8 +369,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) { @@ -390,20 +389,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 */ @@ -626,15 +611,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; - } - __vb2_queue_free(q, q->num_buffers); /*