diff mbox series

[v2,1/4] media: v4l: subdev: Set sub-device active state earlier

Message ID 20231009220906.221303-2-sakari.ailus@linux.intel.com
State New
Headers show
Series V4L2 sub-device active state helper, CCS fixes | expand

Commit Message

Sakari Ailus Oct. 9, 2023, 10:09 p.m. UTC
Set sub-device active state earlier in order to have it available to the
sub-device driver when driver's init_cfg operation is called.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 .../media/platform/renesas/rcar-vin/rcar-v4l2.c    |  3 ++-
 drivers/media/platform/renesas/vsp1/vsp1_entity.c  |  3 ++-
 drivers/media/v4l2-core/v4l2-subdev.c              | 14 +++++++++-----
 drivers/staging/media/tegra-video/vi.c             |  2 +-
 include/media/v4l2-subdev.h                        |  3 ++-
 5 files changed, 16 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/drivers/media/platform/renesas/rcar-vin/rcar-v4l2.c b/drivers/media/platform/renesas/rcar-vin/rcar-v4l2.c
index 073f70c6ac68..26c2470dc289 100644
--- a/drivers/media/platform/renesas/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/renesas/rcar-vin/rcar-v4l2.c
@@ -266,7 +266,8 @@  static int rvin_try_format(struct rvin_dev *vin, u32 which,
 	 * FIXME: Drop this call, drivers are not supposed to use
 	 * __v4l2_subdev_state_alloc().
 	 */
-	sd_state = __v4l2_subdev_state_alloc(sd, "rvin:state->lock", &key);
+	sd_state = __v4l2_subdev_state_alloc(sd, "rvin:state->lock", &key,
+					     false);
 	if (IS_ERR(sd_state))
 		return PTR_ERR(sd_state);
 
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_entity.c b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
index c31f05a80bb5..ab0f47a5fd96 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_entity.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
@@ -680,7 +680,8 @@  int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity,
 	 * __v4l2_subdev_state_alloc().
 	 */
 	entity->config = __v4l2_subdev_state_alloc(&entity->subdev,
-						   "vsp1:config->lock", &key);
+						   "vsp1:config->lock", &key,
+						   false);
 	if (IS_ERR(entity->config)) {
 		media_entity_cleanup(&entity->subdev.entity);
 		return PTR_ERR(entity->config);
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index d295a4e87b66..cd590951c393 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -53,7 +53,7 @@  static int subdev_fh_init(struct v4l2_subdev_fh *fh, struct v4l2_subdev *sd)
 	struct v4l2_subdev_state *state;
 	static struct lock_class_key key;
 
-	state = __v4l2_subdev_state_alloc(sd, "fh->state->lock", &key);
+	state = __v4l2_subdev_state_alloc(sd, "fh->state->lock", &key, false);
 	if (IS_ERR(state))
 		return PTR_ERR(state);
 
@@ -1426,7 +1426,7 @@  EXPORT_SYMBOL_GPL(v4l2_subdev_has_pad_interdep);
 
 struct v4l2_subdev_state *
 __v4l2_subdev_state_alloc(struct v4l2_subdev *sd, const char *lock_name,
-			  struct lock_class_key *lock_key)
+			  struct lock_class_key *lock_key, bool active)
 {
 	struct v4l2_subdev_state *state;
 	int ret;
@@ -1451,6 +1451,9 @@  __v4l2_subdev_state_alloc(struct v4l2_subdev *sd, const char *lock_name,
 		}
 	}
 
+	if (active)
+		sd->active_state = state;
+
 	/*
 	 * There can be no race at this point, but we lock the state anyway to
 	 * satisfy lockdep checks.
@@ -1470,6 +1473,9 @@  __v4l2_subdev_state_alloc(struct v4l2_subdev *sd, const char *lock_name,
 
 	kfree(state);
 
+	if (active)
+		sd->active_state = NULL;
+
 	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(__v4l2_subdev_state_alloc);
@@ -1493,12 +1499,10 @@  int __v4l2_subdev_init_finalize(struct v4l2_subdev *sd, const char *name,
 {
 	struct v4l2_subdev_state *state;
 
-	state = __v4l2_subdev_state_alloc(sd, name, key);
+	state = __v4l2_subdev_state_alloc(sd, name, key, true);
 	if (IS_ERR(state))
 		return PTR_ERR(state);
 
-	sd->active_state = state;
-
 	return 0;
 }
 EXPORT_SYMBOL_GPL(__v4l2_subdev_init_finalize);
diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c
index e98b3010520e..733fccb157fe 100644
--- a/drivers/staging/media/tegra-video/vi.c
+++ b/drivers/staging/media/tegra-video/vi.c
@@ -450,7 +450,7 @@  static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
 	 * __v4l2_subdev_state_alloc().
 	 */
 	sd_state = __v4l2_subdev_state_alloc(subdev, "tegra:state->lock",
-					     &key);
+					     &key, false);
 	if (IS_ERR(sd_state))
 		return PTR_ERR(sd_state);
 	/*
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index c1f90c1223a7..ea05b70389b3 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -1346,7 +1346,8 @@  bool v4l2_subdev_has_pad_interdep(struct media_entity *entity,
  */
 struct v4l2_subdev_state *__v4l2_subdev_state_alloc(struct v4l2_subdev *sd,
 						    const char *lock_name,
-						    struct lock_class_key *key);
+						    struct lock_class_key *key,
+						    bool active);
 
 /**
  * __v4l2_subdev_state_free - free a v4l2_subdev_state