Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp845444ybi; Fri, 12 Jul 2019 05:36:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPWUWuC5Ks47IhqqPrChWpUoDKLSMh1MOHMnNTc6Bg5z3GVWyucYIadvncCwNQ8OdTCp+b X-Received: by 2002:a17:902:9a95:: with SMTP id w21mr11156188plp.126.1562934989868; Fri, 12 Jul 2019 05:36:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562934989; cv=none; d=google.com; s=arc-20160816; b=xCVfrHgkEND5Lsvo8Ii41X15OhVLUFZncfljOtTGyawfkMV4Jgby6oM+hTceTR+dcR 2guzcyQQvhBXEkDTzZ6pgW6cBShJxhTiMFqAZH/IMkirjERiTkN4hXKQiLDIqMOQJSsY QJw+BVmwhuaoBpvJXrXbeZQuTkmT4MsYqN9aX+WRuG2LmiKJVzKinovXt9lVnWIUR8K0 EKciiDzjgvkWspryU7ZyavCtgQx84Yl6mcyFJyPa8xnuo6EbxUH6UjGzkCbeZoDcaz5a uLjhwO9UvVLfasYobfua8MF5QFBO5CXL+EAUDomkEspNAR4LmXUAkHVaM/cGdwPs9htC YtXQ== 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=p6U6O7gfPCBWOspjCQi8/qRzi81WRslzbWfsjq0zuJY=; b=wrEV2wjrfpA5XPq8XMknghBnLoElhhoyT5+g6nsK+6jzzkHN8VuVekfZr0CwWaimw9 Zh8bVR56JWskBjJ7pezIoYoQR+/IJgRPVAXF4l4UWpuF7nmBhsIlcpeE1oMvpAoeHobo qX+f+/oNjhmbpXCqy47rbjrTeqs78qtxUA0NF1B8WNzfG9i5qLTBR4ApVNdOvznUUIkP pyBmpMILabxPUnP/V6S+6PWtPvhi40BiyffqWhNcbS+DbDUslA4qYy8WU9W00GF5eza6 68fggUlSCqADEAVCkstZG69K0tuiwkP9B18YUCv0LkV7Z1PXPbHIJsQvtO97h7hZuLYz MfMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MxatkRmz; 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 6si7574605plb.345.2019.07.12.05.36.14; Fri, 12 Jul 2019 05:36:29 -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=MxatkRmz; 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 S1729760AbfGLMef (ORCPT + 99 others); Fri, 12 Jul 2019 08:34:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:54408 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729011AbfGLMeb (ORCPT ); Fri, 12 Jul 2019 08:34:31 -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 83BFA216B7; Fri, 12 Jul 2019 12:34:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934870; bh=y8I/VZdab5WdTkRjCn3lOhQks0XTwHHV4UXif+RnngE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MxatkRmze0QOLNDP1l2jWFomTvr/vd0zwDlhtpPoCmEj5HtmUdx90Urifdya7qrm7 GdPsfXLLOxLduEVOnhzB+q6QLHKvyyYXUX7O0Y3ZMFziKvLD1sD+Av9JkLTIheI3+T vhABSjmW3lT1skmF8Hggstdq60/FqeHqEC8LM+9Q= 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 5.2 58/61] staging: bcm2835-camera: Ensure all buffers are returned on disable Date: Fri, 12 Jul 2019 14:20:11 +0200 Message-Id: <20190712121623.922886882@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121620.632595223@linuxfoundation.org> References: <20190712121620.632595223@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 @@ -576,6 +576,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); @@ -599,12 +600,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"); @@ -619,6 +614,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 @@ -240,6 +240,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, @@ -380,6 +382,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 */