Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp851641ybi; Fri, 12 Jul 2019 05:42:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqw3SJXZaOgZ4Qel+BDXJR7k7kX6rB1tghRHxfNGMMYSCvdjt4KC13TYD1Iz1IOKlkR+tQgp X-Received: by 2002:a17:90a:fa18:: with SMTP id cm24mr11305768pjb.120.1562935369180; Fri, 12 Jul 2019 05:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562935369; cv=none; d=google.com; s=arc-20160816; b=T9pSJ1864lUpvSm2/STdmx+kdt4pbPHyAG7kYIeD9h51njdqpFaMilEbUkIPOqbBDi QD94G/EaO9R9Y3t5SGMV++pLi29Ws4w6fE5oZbbxtyfemjExQXlOU36Cj6L0vL2kgTiu fsp1E7L3iqNuzL/NisSfeg1vYCnqju1W39MLEBZoLtNbWdtidRTwWCFO96S63Od0hkQI CSnEaWXK9cATNeF1DOHj4iCT+l7g3i4k7s/ELlpGAVHuzKfmxTTFIxTAfWRLfdZpYyp0 6/ko8v87gZ4OGZ9EwAw8a/C3TgL0pxP4Z4qZ4oaImfzjKOQp4qKQ1PbLKRSuxgPG0sJG whpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=reiZJBpr4LZ/e1AMR/m635YT0QqRuncAK7z5HHNaPXc=; b=FZdEDm9uPx6YjA6eu4PqU5BIDmbw8vYWVtafL1bO6j6n8jsV7RbiTnezLsJuQOzCck xNXJqvViOvfz21eLgr03pFV+N9PexmB3wemuk4OahVWpW62P6DAs8l67ON3o/U/1BxdW 9P3rxI/qYBgDZhUc0vJs4jRiJHYIzwbVmorHEoCGpLYbpwnsN4+dm4YShW0WSEKlfrDz 7HSzgg9L5bueu9BN9c+2A1RV6BBly4+JqcJfnOxslOik/G21nBijB8B7UlV+vutqOxB6 E/Gme9D6sx+JvX+IrkAYsYARKhd0X/xRoyya1umMWdRA1TAYgMy7UC6/9to5qrV5hV3l XDPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v7YcYilz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si7615918plb.188.2019.07.12.05.42.34; Fri, 12 Jul 2019 05:42:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v7YcYilz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728115AbfGLMY1 (ORCPT + 99 others); Fri, 12 Jul 2019 08:24:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:33002 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728108AbfGLMY0 (ORCPT ); Fri, 12 Jul 2019 08:24:26 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6DC8B208E4; Fri, 12 Jul 2019 12:24:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934264; bh=LOu9gpXwDt0xriCWK3knQMKIaK3cMl0hEygW7ULkYuc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v7YcYilzlt64fZj0R4kXHwUwwtaYwP+6zj4oEXFJGie5J1Ji9Bwo3n9rzMTnw7vML PDbOyY+iYpSw77GwCXopu4Xor5IygcmB3r5CNH1VGaDV2BC6tsMYoUU7BCyo/hEK/y k5+EqEed2dBZNVS6YKuXo4Gue4as9Z9zyEluxuzw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Stevenson , Stefan Wahren , Hans Verkuil , Mauro Carvalho Chehab Subject: [PATCH 4.19 88/91] staging: bcm2835-camera: Ensure all buffers are returned on disable Date: Fri, 12 Jul 2019 14:19:31 +0200 Message-Id: <20190712121626.436694777@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121621.422224300@linuxfoundation.org> References: <20190712121621.422224300@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Stevenson commit 70ec64ccdaac5d8f634338e33b016c1c99831499 upstream. With the recent change to match MMAL and V4L2 buffers there is a need to wait for all MMAL buffers to be returned during stop_streaming. Fixes: 938416707071 ("staging: bcm2835-camera: Remove V4L2/MMAL buffer remapping") Signed-off-by: Dave Stevenson Signed-off-by: Stefan Wahren Acked-by: Hans Verkuil Acked-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c | 22 +++++++--- drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c | 4 + drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h | 3 + 3 files changed, 23 insertions(+), 6 deletions(-) --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c @@ -582,6 +582,7 @@ static void stop_streaming(struct vb2_qu int ret; unsigned long timeout; struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq); + struct vchiq_mmal_port *port = dev->capture.port; v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n", __func__, dev); @@ -605,12 +606,6 @@ static void stop_streaming(struct vb2_qu &dev->capture.frame_count, sizeof(dev->capture.frame_count)); - /* wait for last frame to complete */ - timeout = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ); - if (timeout == 0) - v4l2_err(&dev->v4l2_dev, - "timed out waiting for frame completion\n"); - v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "disabling connection\n"); @@ -625,6 +620,21 @@ static void stop_streaming(struct vb2_qu ret); } + /* wait for all buffers to be returned */ + while (atomic_read(&port->buffers_with_vpu)) { + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, + "%s: Waiting for buffers to be returned - %d outstanding\n", + __func__, atomic_read(&port->buffers_with_vpu)); + timeout = wait_for_completion_timeout(&dev->capture.frame_cmplt, + HZ); + if (timeout == 0) { + v4l2_err(&dev->v4l2_dev, "%s: Timeout waiting for buffers to be returned - %d outstanding\n", + __func__, + atomic_read(&port->buffers_with_vpu)); + break; + } + } + if (disable_camera(dev) < 0) v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n"); } --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c @@ -241,6 +241,8 @@ static void buffer_work_cb(struct work_s struct mmal_msg_context *msg_context = container_of(work, struct mmal_msg_context, u.bulk.work); + atomic_dec(&msg_context->u.bulk.port->buffers_with_vpu); + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance, msg_context->u.bulk.port, msg_context->u.bulk.status, @@ -381,6 +383,8 @@ buffer_from_host(struct vchiq_mmal_insta /* initialise work structure ready to schedule callback */ INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb); + atomic_inc(&port->buffers_with_vpu); + /* prep the buffer from host message */ memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */ --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h @@ -71,6 +71,9 @@ struct vchiq_mmal_port { struct list_head buffers; /* lock to serialise adding and removing buffers from list */ spinlock_t slock; + + /* Count of buffers the VPU has yet to return */ + atomic_t buffers_with_vpu; /* callback on buffer completion */ vchiq_mmal_buffer_cb buffer_cb; /* callback context */