From patchwork Thu Jun 16 18:23:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16252 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 0010AC3275 for ; Thu, 16 Jun 2022 18:24:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 77F936563F; Thu, 16 Jun 2022 20:24:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655403854; bh=4oraDFQGac7iP6sqkblu/Ky4ylMjLz5Y9aGH+ReEdXc=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=fJjmpLRcLoLwissGvhP62SEaFNYRiJguTGEPwemruEfq6Dr8yvctbdR1Qs7uRZ6h2 H0M45VW2/OeKJh6xKoiWinGDOuIr2rlHjiFl9gkYbU012Pf2ocIxmykkkoh1pjAG5N GEoXHw0wGe+ytNlKoRMk90qerQGNUP/YbKs42t2JNXtwd++HteubD1U23bMf2FgIkQ cFkptBc7MyNaBaV2rE5PoMnRPIUjSV9CCbUcku9KV6VlSn4CDTLBM8w/UwnjzR+T6x djg2NQicEJ/oHY9MpDLoO5WrAXc7LFM/KQHnx4O+NIl7GHZO6p7nGsORnf1Jko8+tN 0x5b5N6fleV8Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2FAF065634 for ; Thu, 16 Jun 2022 20:24:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Tv8WrHly"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7683E8AF; Thu, 16 Jun 2022 20:24:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655403849; bh=4oraDFQGac7iP6sqkblu/Ky4ylMjLz5Y9aGH+ReEdXc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tv8WrHlySezVN6fDhTI1NYNOTwfDe8bmAg8OzSLwB/5wd6owwcUG6rL4uAo5+ukmz L1Aq07ueaGPPScgZN50j9X3BMiLj8m+6sccGbq5URgoUL4qNHYZ3X2Glyk44BWmm90 Wu88U4ZbfluP5fALCbNBBkV9wgM8ZArTIGZTbgXI= To: libcamera-devel@lists.libcamera.org Date: Thu, 16 Jun 2022 21:23:47 +0300 Message-Id: <20220616182350.17352-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220616182350.17352-1-laurent.pinchart@ideasonboard.com> References: <20220616182350.17352-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/7] media: v4l2: Make colorspace validity checks more future-proof 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-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Sakari Ailus , linux-imx@nxp.com, kernel@pengutronix.de, Hans Verkuil Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The helper functions that test validity of colorspace-related fields use the last value of the corresponding enums. This isn't very future-proof, as there's a high chance someone adding a new value may forget to update the helpers. Add new "LAST" entries to the enumerations to improve this, and keep them private to the kernel. Signed-off-by: Laurent Pinchart Acked-by: Sakari Ailus --- Changes since v1: - Let the compiler assign a value to the *_LAST enum entries --- include/media/v4l2-common.h | 10 +++++----- include/uapi/linux/videodev2.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h index 3eb202259e8c..ccc138a9104d 100644 --- a/include/media/v4l2-common.h +++ b/include/media/v4l2-common.h @@ -563,19 +563,19 @@ static inline void v4l2_buffer_set_timestamp(struct v4l2_buffer *buf, static inline bool v4l2_is_colorspace_valid(__u32 colorspace) { return colorspace > V4L2_COLORSPACE_DEFAULT && - colorspace <= V4L2_COLORSPACE_DCI_P3; + colorspace < V4L2_COLORSPACE_LAST; } static inline bool v4l2_is_xfer_func_valid(__u32 xfer_func) { return xfer_func > V4L2_XFER_FUNC_DEFAULT && - xfer_func <= V4L2_XFER_FUNC_SMPTE2084; + xfer_func < V4L2_XFER_FUNC_LAST; } static inline bool v4l2_is_ycbcr_enc_valid(__u8 ycbcr_enc) { return ycbcr_enc > V4L2_YCBCR_ENC_DEFAULT && - ycbcr_enc <= V4L2_YCBCR_ENC_SMPTE240M; + ycbcr_enc < V4L2_YCBCR_ENC_LAST; } static inline bool v4l2_is_hsv_enc_valid(__u8 hsv_enc) @@ -585,8 +585,8 @@ static inline bool v4l2_is_hsv_enc_valid(__u8 hsv_enc) static inline bool v4l2_is_quant_valid(__u8 quantization) { - return quantization == V4L2_QUANTIZATION_FULL_RANGE || - quantization == V4L2_QUANTIZATION_LIM_RANGE; + return quantization > V4L2_QUANTIZATION_DEFAULT && + quantization < V4L2_QUANTIZATION_LAST; } #endif /* V4L2_COMMON_H_ */ diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index f6f9a690971e..7b7d852dc74b 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -245,6 +245,14 @@ enum v4l2_colorspace { /* DCI-P3 colorspace, used by cinema projectors */ V4L2_COLORSPACE_DCI_P3 = 12, + +#ifdef __KERNEL__ + /* + * Largest supported colorspace value, assigned by the compiler, used + * by the framework to check for invalid values. + */ + V4L2_COLORSPACE_LAST, +#endif }; /* @@ -283,6 +291,13 @@ enum v4l2_xfer_func { V4L2_XFER_FUNC_NONE = 5, V4L2_XFER_FUNC_DCI_P3 = 6, V4L2_XFER_FUNC_SMPTE2084 = 7, +#ifdef __KERNEL__ + /* + * Largest supported transfer function value, assigned by the compiler, + * used by the framework to check for invalid values. + */ + V4L2_XFER_FUNC_LAST, +#endif }; /* @@ -343,6 +358,13 @@ enum v4l2_ycbcr_encoding { /* SMPTE 240M -- Obsolete HDTV */ V4L2_YCBCR_ENC_SMPTE240M = 8, +#ifdef __KERNEL__ + /* + * Largest supported encoding value, assigned by the compiler, used by + * the framework to check for invalid values. + */ + V4L2_YCBCR_ENC_LAST, +#endif }; /* @@ -378,6 +400,13 @@ enum v4l2_quantization { V4L2_QUANTIZATION_DEFAULT = 0, V4L2_QUANTIZATION_FULL_RANGE = 1, V4L2_QUANTIZATION_LIM_RANGE = 2, +#ifdef __KERNEL__ + /* + * Largest supported quantization value, assigned by the compiler, used + * by the framework to check for invalid values. + */ + V4L2_QUANTIZATION_LAST, +#endif }; /*