[{"id":5044,"web_url":"https://patchwork.libcamera.org/comment/5044/","msgid":"<20200605101851.GI5852@pendragon.ideasonboard.com>","date":"2020-06-05T10:18:51","subject":"Re: [libcamera-devel] [PATCH v2 7/7] v4l2: v4l2_camera_proxy: Fix\n\tsegfault on restarting streams","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Fri, Jun 05, 2020 at 06:01:06PM +0900, Paul Elder wrote:\n> The V4L2 compatibility layer keeps track of the index of the next buffer\n> to be dequeued, to handle VIDIOC_DQBUF. This index is set to 0 on\n> startup and incremented (modulo #frames), and is otherwise never reset.\n> This means that if the last handled frame index is not #frames-1, and\n> the stream is restarted without restarting libcamera and the V4L2\n> compatilibity layer, the buffer index number won't match with the\n> libcamera buffer index number, causing a segfault. Fix this by resetting\n> the current buffer index to zero on VIDIOC_STREAMON.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n> New in v2\n> ---\n>  src/v4l2/v4l2_camera_proxy.cpp | 2 ++\n>  1 file changed, 2 insertions(+)\n> \n> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\n> index 7ee4c0cb..059f3cbe 100644\n> --- a/src/v4l2/v4l2_camera_proxy.cpp\n> +++ b/src/v4l2/v4l2_camera_proxy.cpp\n> @@ -465,6 +465,8 @@ int V4L2CameraProxy::vidioc_streamon(int *arg)\n>  \tif (!validateBufferType(*arg))\n>  \t\treturn -EINVAL;\n>  \n> +\tcurrentBuf_ = 0;\n> +\n>  \treturn vcam_->streamOn();\n>  }\n>","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5BBED603C9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Jun 2020 12:19:09 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C5DDE27C;\n\tFri,  5 Jun 2020 12:19:08 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"juiYjJs9\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1591352349;\n\tbh=4I/V8JM2Mxkhj9ruAThacpV1GKj/oGpeDrohPRDwgGs=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=juiYjJs9uV3apEshcPbDL0SBLrVP+UE+7TwrqcCFTtjmN1GPY6fdiRDkzEvLUxlKk\n\tT7yvoEYr3CetZ4sI8wBgcv4Y+KoV7GDchRUz+ZClDgZF3lzpPiHunEy3/wJhPBIgjP\n\tbF6Y10FrNLR8i2oUJROTuVAajEo4bIvSsYK80q74=","Date":"Fri, 5 Jun 2020 13:18:51 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200605101851.GI5852@pendragon.ideasonboard.com>","References":"<20200605090106.15424-1-paul.elder@ideasonboard.com>\n\t<20200605090106.15424-8-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200605090106.15424-8-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 7/7] v4l2: v4l2_camera_proxy: Fix\n\tsegfault on restarting streams","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Fri, 05 Jun 2020 10:19:09 -0000"}},{"id":5057,"web_url":"https://patchwork.libcamera.org/comment/5057/","msgid":"<20200605182220.GH5864@oden.dyn.berto.se>","date":"2020-06-05T18:22:20","subject":"Re: [libcamera-devel] [PATCH v2 7/7] v4l2: v4l2_camera_proxy: Fix\n\tsegfault on restarting streams","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Paul,\n\nThanks for your work.\n\nOn 2020-06-05 18:01:06 +0900, Paul Elder wrote:\n> The V4L2 compatibility layer keeps track of the index of the next buffer\n> to be dequeued, to handle VIDIOC_DQBUF. This index is set to 0 on\n> startup and incremented (modulo #frames), and is otherwise never reset.\n> This means that if the last handled frame index is not #frames-1, and\n> the stream is restarted without restarting libcamera and the V4L2\n> compatilibity layer, the buffer index number won't match with the\n> libcamera buffer index number, causing a segfault. Fix this by resetting\n> the current buffer index to zero on VIDIOC_STREAMON.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> \n> ---\n> New in v2\n> ---\n>  src/v4l2/v4l2_camera_proxy.cpp | 2 ++\n>  1 file changed, 2 insertions(+)\n> \n> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\n> index 7ee4c0cb..059f3cbe 100644\n> --- a/src/v4l2/v4l2_camera_proxy.cpp\n> +++ b/src/v4l2/v4l2_camera_proxy.cpp\n> @@ -465,6 +465,8 @@ int V4L2CameraProxy::vidioc_streamon(int *arg)\n>  \tif (!validateBufferType(*arg))\n>  \t\treturn -EINVAL;\n>  \n> +\tcurrentBuf_ = 0;\n> +\n>  \treturn vcam_->streamOn();\n>  }\n>  \n> -- \n> 2.20.1\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x142.google.com (mail-lf1-x142.google.com\n\t[IPv6:2a00:1450:4864:20::142])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C4C11603C6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Jun 2020 20:22:21 +0200 (CEST)","by mail-lf1-x142.google.com with SMTP id e125so6381678lfd.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 05 Jun 2020 11:22:21 -0700 (PDT)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\t11sm1076984lju.118.2020.06.05.11.22.20\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 05 Jun 2020 11:22:20 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com header.b=\"iHFietXd\"; \n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=RdpzItQQf2oDgZTY9JnZhPYPhpAfYTTMHup8AdtKsw0=;\n\tb=iHFietXdlQbiykjvQlu4GWPmybEyFvPwsnN+eOd7WrNcYji5rlq0cuCRdHnc+P2/PM\n\t2rz/6edHstIoFlNihNMzF2M0z5gCWHKsneSyZ/Wot5awwR+w3955UmCGRsa08URVHehf\n\tVF8qxUgid6sCarMLV9TzUkNEr0E4Sbb8y1FLOrVby8ij1+cOWIVCi+0gbyA63V/EvA+b\n\tO7d3U0n8H38xl5rjGr2Ycq9oV/4UJWeSWSrCVP83X0pabbRgVVYa1vN7AIaNJ10J5q8g\n\taCve/YynyfxPQflIoBEUUSeFyvczku+Ev5XXjCfkgV0Pp+cBH6Od6PHyiza3TE1E7qIh\n\tTKhg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=RdpzItQQf2oDgZTY9JnZhPYPhpAfYTTMHup8AdtKsw0=;\n\tb=aH3pchmQgLhOtunLhAn8BPELsbDIfP74KW4jCXyA7a/O//ef2BcYlnfcyshGNwN9KJ\n\tJ/BwnQRabp1KcSvW9gb5Xis+snrz1biGp3L0KBX+NwMneRN6roJorZnHH65J4J0S1Usf\n\tPkZqRpLpmyfZK70K6eHaVNRInVPhUp4Hh/uLp2vO+mKMbcpWBiKR7+FMalSX3CtzWNbF\n\tazLcbYO4yAdV1XDzB3sAwZ7QdA+LJ95qprs8AyJez6bxMpG5w4Fex54q371NkQF+7qoV\n\tdEe6BmH2EkS3nJ1+JHlsD+28tjOX6sQdO8Wgxn7Y/dHRCSLr27YswtGB64MnlkKvDpzF\n\t6gWw==","X-Gm-Message-State":"AOAM532vxAVFT34K8LMn3ONLll3fb55DEEkdSTElm9bMPtOFBBqY7xVJ\n\tZ/egQ8pr/4p/+H1m+vO9RGzKki6EHQ9ZQg==","X-Google-Smtp-Source":"ABdhPJz4a52pmprMLdyJGLRjWQv1PcB0GN1bdYfjDVHrCXk8RCdlarD09kWYRz33/6BNGXqmkQmoKw==","X-Received":"by 2002:a19:f119:: with SMTP id p25mr5713059lfh.99.1591381341117;\n\tFri, 05 Jun 2020 11:22:21 -0700 (PDT)","Date":"Fri, 5 Jun 2020 20:22:20 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200605182220.GH5864@oden.dyn.berto.se>","References":"<20200605090106.15424-1-paul.elder@ideasonboard.com>\n\t<20200605090106.15424-8-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200605090106.15424-8-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 7/7] v4l2: v4l2_camera_proxy: Fix\n\tsegfault on restarting streams","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Fri, 05 Jun 2020 18:22:22 -0000"}}]