lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250919-vdev-state-v2-3-b2c42426965c@ideasonboard.com>
Date: Fri, 19 Sep 2025 15:25:55 +0530
From: Jai Luthra <jai.luthra@...asonboard.com>
To: Hans Verkuil <hverkuil@...nel.org>, 
 Mauro Carvalho Chehab <mchehab@...nel.org>, 
 Sakari Ailus <sakari.ailus@...ux.intel.com>, 
 Laurent Pinchart <laurent.pinchart@...asonboard.com>, 
 Tomi Valkeinen <tomi.valkeinen@...asonboard.com>, 
 Jacopo Mondi <jacopo.mondi@...asonboard.com>, linux-media@...r.kernel.org
Cc: Jai Luthra <jai.luthra@...asonboard.com>, 
 Ricardo Ribalda <ribalda@...omium.org>, 
 Laurent Pinchart <laurent.pinchart+renesas@...asonboard.com>, 
 Bartosz Golaszewski <bartosz.golaszewski@...aro.org>, 
 Al Viro <viro@...iv.linux.org.uk>, Ma Ke <make24@...as.ac.cn>, 
 linux-kernel@...r.kernel.org
Subject: [PATCH v2 03/10] media: v4l2-dev: Add callback for initializing
 video device state

Drivers may need to initialize the video device state with default
values, such as setting a default pixelformat and resolution.

Introduce an optional callback that drivers can populate. The framework
calls this callback during state allocation to allow driver-specific
initialization.

Signed-off-by: Jai Luthra <jai.luthra@...asonboard.com>
--
Cc: Mauro Carvalho Chehab <mchehab@...nel.org>
Cc: Hans Verkuil <hverkuil@...nel.org>
Cc: Ricardo Ribalda <ribalda@...omium.org>
Cc: Laurent Pinchart <laurent.pinchart+renesas@...asonboard.com>
Cc: Jai Luthra <jai.luthra@...asonboard.com>
Cc: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Cc: Al Viro <viro@...iv.linux.org.uk>
Cc: Ma Ke <make24@...as.ac.cn>
Cc: linux-media@...r.kernel.org
Cc: linux-kernel@...r.kernel.org
---
 drivers/media/v4l2-core/v4l2-dev.c | 13 +++++++++++++
 include/media/v4l2-dev.h           | 11 +++++++++++
 2 files changed, 24 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 26b6b2f37ca55ce981aa17a28a875dc3cf253d9b..dff23c6a0b56fb3d29e1c04e386bb445fa8773bb 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -169,6 +169,7 @@ __video_device_state_alloc(struct video_device *vdev,
 {
 	struct video_device_state *state =
 		kzalloc(sizeof(struct video_device_state), GFP_KERNEL);
+	int ret;
 
 	if (!state)
 		return ERR_PTR(-ENOMEM);
@@ -176,7 +177,19 @@ __video_device_state_alloc(struct video_device *vdev,
 	state->which = which;
 	state->vdev = vdev;
 
+	if (vdev->vdev_ops && vdev->vdev_ops->init_state) {
+		ret = vdev->vdev_ops->init_state(state);
+
+		if (ret)
+			goto err;
+	}
+
 	return state;
+
+err:
+	kfree(state);
+
+	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(__video_device_state_alloc);
 
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 5ca04a1674e0bf7016537e6fb461d790fc0a958f..d327be16f6def70554a7d92d10436a29384ae32a 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -244,6 +244,15 @@ struct video_device_state {
 	enum video_device_state_whence which;
 };
 
+/**
+ * struct video_device_internal_ops - Callbacks for video device management.
+ *
+ * @init_state: pointer to a function that initializes the video device state.
+ */
+struct video_device_internal_ops {
+	int (*init_state)(struct video_device_state *state);
+};
+
 /*
  * Newer version of video_device, handled by videodev2.c
  *	This version moves redundant code from video device code to
@@ -284,6 +293,7 @@ struct video_device_state {
  *
  * @release: video device release() callback
  * @ioctl_ops: pointer to &struct v4l2_ioctl_ops with ioctl callbacks
+ * @vdev_ops: pointer to &struct video_device_internal_ops
  *
  * @valid_ioctls: bitmap with the valid ioctls for this device
  * @lock: pointer to &struct mutex serialization lock
@@ -336,6 +346,7 @@ struct video_device {
 	/* callbacks */
 	void (*release)(struct video_device *vdev);
 	const struct v4l2_ioctl_ops *ioctl_ops;
+	const struct video_device_internal_ops *vdev_ops;
 	DECLARE_BITMAP(valid_ioctls, BASE_VIDIOC_PRIVATE);
 
 	struct mutex *lock;

-- 
2.51.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ