From patchwork Fri Jun 5 09:01:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 3942 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F01946124F for ; Fri, 5 Jun 2020 11:01:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="QDIG04Jd"; dkim-atps=neutral Received: from emerald.amanokami.net (fs76eef344.knge213.ap.nuro.jp [118.238.243.68]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C7CC227C; Fri, 5 Jun 2020 11:01:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1591347686; bh=5qweElhF0wT6dCUQnqxn3x3FOoB0mlpHWKTIFoMp5eQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QDIG04Jdn5sWHF+rciXkRtWNdVJz+CnRyalRSIPvwuP12n3/ByAxWoqvBNqnOFwHk lyqHzVPxgp3gzozEpbrQXog9m+E3OfE0UVmnpWb/MGh9WuB+/gPl8zftTuISbIDfJh EL6KhVqjYeiZHajzya89H+/FG+oePzNI+zWAabro= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Fri, 5 Jun 2020 18:01:06 +0900 Message-Id: <20200605090106.15424-8-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200605090106.15424-1-paul.elder@ideasonboard.com> References: <20200605090106.15424-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 7/7] v4l2: v4l2_camera_proxy: Fix segfault on restarting streams X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jun 2020 09:01:27 -0000 The V4L2 compatibility layer keeps track of the index of the next buffer to be dequeued, to handle VIDIOC_DQBUF. This index is set to 0 on startup and incremented (modulo #frames), and is otherwise never reset. This means that if the last handled frame index is not #frames-1, and the stream is restarted without restarting libcamera and the V4L2 compatilibity layer, the buffer index number won't match with the libcamera buffer index number, causing a segfault. Fix this by resetting the current buffer index to zero on VIDIOC_STREAMON. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- New in v2 --- src/v4l2/v4l2_camera_proxy.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 7ee4c0cb..059f3cbe 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -465,6 +465,8 @@ int V4L2CameraProxy::vidioc_streamon(int *arg) if (!validateBufferType(*arg)) return -EINVAL; + currentBuf_ = 0; + return vcam_->streamOn(); }