From patchwork Wed Nov 4 07:48:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10331 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 27567BE080 for ; Wed, 4 Nov 2020 07:49:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1BD9C62C74; Wed, 4 Nov 2020 08:49:35 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="vOYY5VUf"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A8E7760344 for ; Wed, 4 Nov 2020 08:49:33 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 498B6BB5 for ; Wed, 4 Nov 2020 08:49:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1604476173; bh=FFO9/3LKr9nbjjQiIH1pYvqISBGmITwX54tqboMw+Sk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=vOYY5VUf/Sq0DgwSU8QYfHQtT67AKoFrpb6UDFFS7R0V6kH0IcuynceldZD+bUCkD fteGQXRpeE4ie8N3xM544CY3EdhAcAOolzno1AHlHLZo8/lNT7NF4B1rW7zBSskdLs y4V1kO/sNLCgKVmHAsEbRnin1U09wsAf0EimO6EI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Nov 2020 09:48:39 +0200 Message-Id: <20201104074841.21676-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201104074841.21676-1-laurent.pinchart@ideasonboard.com> References: <20201104074841.21676-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/3] libcamera: v4l2_videodevice: Zero-initialize planes in V4L2DeviceFormat 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The V4L2DeviceFormat class doesn't have a default constructor, neither does it specifies default member initializers for the plane-related members. This results in the planes array and planesCount members being uninitialized by default, leading to undefined behaviour if the user of the class doesn't initialize it explicitly. Most users initialize V4L2DeviceFormat instances, but some don't. We could fix them, but that would likely turn into a game of whack-a-mole. As there's no use case for instantiating a large number of V4L2DeviceFormat instances in a performance-critical code path, let's instead add default initializers to avoid future issues. While at it, define a type of the structures containing plane information, and use an std::array. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/internal/v4l2_videodevice.h | 13 ++++++++----- src/libcamera/v4l2_videodevice.cpp | 9 +++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 53f6a2d5515b..dcb9654a34b8 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -7,6 +7,7 @@ #ifndef __LIBCAMERA_INTERNAL_V4L2_VIDEODEVICE_H__ #define __LIBCAMERA_INTERNAL_V4L2_VIDEODEVICE_H__ +#include #include #include #include @@ -153,14 +154,16 @@ private: class V4L2DeviceFormat { public: + struct Plane { + uint32_t size = 0; + uint32_t bpl = 0; + }; + V4L2PixelFormat fourcc; Size size; - struct { - uint32_t size; - uint32_t bpl; - } planes[3]; - unsigned int planesCount; + std::array planes; + unsigned int planesCount = 0; const std::string toString() const; }; diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 36d7d9a0f27a..d07c3530eea5 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -351,6 +351,15 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const * V4L2DeviceFormat::planesCount value. */ +/** + * \struct V4L2DeviceFormat::Plane + * \brief Per-plane memory size information + * \var V4L2DeviceFormat::Plane::size + * \brief The plane total memory size (in bytes) + * \var V4L2DeviceFormat::Plane::bpl + * \brief The plane line stride (in bytes) + */ + /** * \var V4L2DeviceFormat::size * \brief The image size in pixels