From patchwork Thu Jul 14 21:09:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Corbet X-Patchwork-Id: 975772 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6EL9c5E007677 for ; Thu, 14 Jul 2011 21:09:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932179Ab1GNVJg (ORCPT ); Thu, 14 Jul 2011 17:09:36 -0400 Received: from tex.lwn.net ([70.33.254.29]:54274 "EHLO vena.lwn.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754455Ab1GNVJf (ORCPT ); Thu, 14 Jul 2011 17:09:35 -0400 Received: from bike.lwn.net (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by vena.lwn.net (Postfix) with ESMTP id 490C8154004A; Thu, 14 Jul 2011 15:09:35 -0600 (MDT) Date: Thu, 14 Jul 2011 15:09:34 -0600 From: Jonathan Corbet To: linux-media@vger.kernel.org Cc: Marek Szyprowski , Mauro Carvalho Chehab Subject: [PATCH] videobuf2: call buf_finish() on unprocessed buffers Message-ID: <20110714150934.74777696@bike.lwn.net> Organization: LWN.net X-Mailer: Claws Mail 3.7.9 (GTK+ 2.24.5; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 14 Jul 2011 21:09:39 +0000 (UTC) When user space stops streaming, there may be buffers which have been given to buf_prepare() and which may or may not have been passed to buf_queue(). The videobuf2 core simply takes those buffers back; if buf_prepare() does work that needs cleaning up (like setting up a DMA mapping), that cleanup will not happen. This patch establishes a simple contract with drivers: buffers given to buf_prepare() will eventually see a buf_finish() call. Signed-off-by: Jonathan Corbet Acked-by: Marek Szyprowski --- drivers/media/video/videobuf2-core.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/drivers/media/video/videobuf2-core.c b/drivers/media/video/videobuf2-core.c index 6ba1461..2ba08ab 100644 --- a/drivers/media/video/videobuf2-core.c +++ b/drivers/media/video/videobuf2-core.c @@ -1177,6 +1177,7 @@ EXPORT_SYMBOL_GPL(vb2_streamon); */ static void __vb2_queue_cancel(struct vb2_queue *q) { + struct vb2_buffer *vb; unsigned int i; /* @@ -1188,13 +1189,18 @@ static void __vb2_queue_cancel(struct vb2_queue *q) q->streaming = 0; /* - * Remove all buffers from videobuf's list... + * Remove all buffers from videobuf's list... Give the driver + * a chance to clean them up first, though. */ + list_for_each_entry(vb, &q->queued_list, queued_entry) + call_qop(q, buf_finish, vb); INIT_LIST_HEAD(&q->queued_list); /* * ...and done list; userspace will not receive any buffers it * has not already dequeued before initiating cancel. */ + list_for_each_entry(vb, &q->done_list, done_entry) + call_qop(q, buf_finish, vb); INIT_LIST_HEAD(&q->done_list); wake_up_all(&q->done_wq);