[PATCH 2/7] media: v4l2-isp: Hold v4l2-isp data in central struct

Daniel Scally dan.scally at ideasonboard.com
Wed Nov 4 04:28:17 PST 2026


Hold v4l2-isp related data in a new struct v4l2_isp to facilitate the
easier use of driver-defined data in v4l2-isp itself. Provide a
function to validate the driver's definition of data to make sure that
we have everything that we need.

Signed-off-by: Daniel Scally <dan.scally at ideasonboard.com>
---
 drivers/media/v4l2-core/v4l2-isp.c | 41 ++++++++++++++++++++
 include/media/v4l2-isp.h           | 79 ++++++++++++++++++++++++++++----------
 2 files changed, 99 insertions(+), 21 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-isp.c b/drivers/media/v4l2-core/v4l2-isp.c
index 8e6c2ef326aaa63e00332bcdac8ebdf6da059f44..a979c0690d19d9956a45657561b510546b3aa8c2 100644
--- a/drivers/media/v4l2-core/v4l2-isp.c
+++ b/drivers/media/v4l2-core/v4l2-isp.c
@@ -13,6 +13,47 @@
 
 #include <media/videobuf2-core.h>
 
+int v4l2_isp_validate(struct v4l2_isp *isp)
+{
+	/* We require a device pointer for debugging purposes */
+	if (!isp->dev)
+		return -EINVAL;
+
+	/*
+	 * We need to know how big the data member of the params buffer can get
+	 */
+	if (!isp->params.max_size) {
+		dev_err(isp->dev, "Missing parameters buffer size data\n");
+		return -EINVAL;
+	}
+
+	/* We need to know how many block types there are */
+	if (!isp->params.num_block_types) {
+		dev_err(isp->dev, "Missing number of block types\n");
+		return -EINVAL;
+	}
+
+	/* We need a pointer to some &struct v4l2_isp_params_block_type_info */
+	if (!isp->params.types_info) {
+		dev_err(isp->dev, "Missing block types info pointer\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * A block type with a size of zero is inherently invalid, so let's
+	 * catch that early.
+	 */
+	for (unsigned int i = 0; i < isp->params.num_block_types; i++) {
+		if (!isp->params.types_info[i].size) {
+			dev_err(isp->dev, "Found block type info with 0 size\n");
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_isp_validate);
+
 int v4l2_isp_params_validate_buffer_size(struct device *dev,
 					 struct vb2_buffer *vb,
 					 size_t max_size)
diff --git a/include/media/v4l2-isp.h b/include/media/v4l2-isp.h
index 7a54cf98c79af7a621fdc1f7098690ec7ccaa267..dc3e612ef79ea510ec1535f483fc16c6ec3d4569 100644
--- a/include/media/v4l2-isp.h
+++ b/include/media/v4l2-isp.h
@@ -31,27 +31,6 @@ struct vb2_buffer;
 #define v4l2_isp_buffer_size(max_size)			\
 	(offsetof(struct v4l2_isp_buffer, data) + (max_size))
 
-/**
- * v4l2_isp_params_validate_buffer_size - Validate a V4L2 ISP buffer sizes
- * @dev: the driver's device pointer
- * @vb: the videobuf2 buffer
- * @max_size: the maximum allowed buffer size
- *
- * This function performs validation of the size of a V4L2 ISP parameters buffer
- * before the driver can access the actual data buffer content.
- *
- * After the sizes validation, drivers should copy the buffer content to a
- * kernel-only memory area to prevent userspace from modifying it,
- * before completing validation using v4l2_isp_params_validate_buffer().
- *
- * The @vb buffer as received from the vb2 .buf_prepare() operation is checked
- * against @max_size and it's validated to be large enough to accommodate at
- * least one ISP configuration block.
- */
-int v4l2_isp_params_validate_buffer_size(struct device *dev,
-					 struct vb2_buffer *vb,
-					 size_t max_size);
-
 /**
  * struct v4l2_isp_params_block_type_info - V4L2 ISP params per-block-type info
  * @size: the block type expected size
@@ -73,6 +52,64 @@ struct v4l2_isp_params_block_type_info {
 			      const struct v4l2_isp_block_header *block);
 };
 
+/**
+ * struct v4l2_isp - V4L2 ISP processing structure
+ * @dev: pointer to the &struct device associated with the ISP
+ * @params: sub-struct holding data related to the V4L2 ISP parameters
+ * @params.types_info: pointer to array of params block information structs
+ * @params.num_block_types: number of possible params block types
+ * @params.max_size: maximum size in bytes of the data member of
+ *		     &struct v4l2_isp_params_buffer
+ *
+ * The V4L2 ISP framework is designed to ease validation of parameter and
+ * statistic buffers queued to ISP device drivers. This struct holds references
+ * to driver-defined information designed to facilitate easy validation in a
+ * central source file. The intention is for an instance of the struct to be
+ * embedded within a driver specific struct and populated before validation and
+ * use through the v4l2-isp framework.
+ */
+struct v4l2_isp {
+	struct device *dev;
+
+	struct {
+		const struct v4l2_isp_params_block_type_info *types_info;
+		size_t num_block_types;
+		size_t max_size;
+	} params;
+};
+
+/**
+ * v4l2_isp_validate - Set up a &struct v4l2_isp properly
+ * @isp: pointer to the &struct v4l2_isp to initialise
+ *
+ * This function validates that the members of @isp have been populated with
+ * information sufficient to allow it to be used with the v4l2-isp framework.
+ *
+ * @return int
+ */
+int v4l2_isp_validate(struct v4l2_isp *isp);
+
+/**
+ * v4l2_isp_params_validate_buffer_size - Validate a V4L2 ISP buffer sizes
+ * @dev: the driver's device pointer
+ * @vb: the videobuf2 buffer
+ * @max_size: the maximum allowed buffer size
+ *
+ * This function performs validation of the size of a V4L2 ISP parameters buffer
+ * before the driver can access the actual data buffer content.
+ *
+ * After the sizes validation, drivers should copy the buffer content to a
+ * kernel-only memory area to prevent userspace from modifying it,
+ * before completing validation using v4l2_isp_params_validate_buffer().
+ *
+ * The @vb buffer as received from the vb2 .buf_prepare() operation is checked
+ * against @max_size and it's validated to be large enough to accommodate at
+ * least one ISP configuration block.
+ */
+int v4l2_isp_params_validate_buffer_size(struct device *dev,
+					 struct vb2_buffer *vb,
+					 size_t max_size);
+
 /**
  * v4l2_isp_params_validate_buffer - Validate a V4L2 ISP parameters buffer
  * @dev: the driver's device pointer

-- 
2.43.0




More information about the Linux-rockchip mailing list