Linux Media Controller development
 help / color / mirror / Atom feed
* [PATCH 00/11] media: renesas: vsp1: Modernize the driver
@ 2026-05-11 23:56 Laurent Pinchart
  2026-05-11 23:56 ` [PATCH 01/11] media: renesas: vsp1: Avoid forward function declaration Laurent Pinchart
                   ` (10 more replies)
  0 siblings, 11 replies; 24+ messages in thread
From: Laurent Pinchart @ 2026-05-11 23:56 UTC (permalink / raw)
  To: linux-media, dri-devel
  Cc: linux-renesas-soc, Tomi Valkeinen, Kieran Bingham, Biju Das,
	David Airlie, Simona Vetter

Hello,

This patch series modernizes the VSP1 driver by using scoped guards and
moving loop index variable declarations to the loop statements.

Patches 01/11 and 02/11 prepare for the introduction of scoped guards by
splitting a large function to lower the indentation level. As the
function is called by DRM clients (R-Car DU and RZ DU drivers), an
inline compatibility wrapper is introduced. The clients are then updated
in patches 03/11 and 04/11, and the compatibility wrapper removed in
11/11.

Patches 05/11 to 08/11 then introduce guards and scoped guards for
mutexes and spin locks. There isn't much to say about this, the changes
are pretty boring, but generate a nice reduction of 148 lines. I advise
reviewers to apply the changes and use 'git show -b', as a large part of
the modified lines in 06/11 and 08/11 are just indentation changes due
to scoped guards.

Patch 09/11 continues with the introduction of a helper macro to
simplifying iteration over format arrays, which occurs 6 times in the
driver. Patch 10/11 ends the modernization effort with declaring index
variables in for loop statements to avoid using index variables outside
of the loop unintentionally.

Patch 03/11 and 04/11 touch the DRM subsystem and depend on 02/11. They
could be delayed by one kernel release (in which case 11/11 would need
to be delayed by two releases), but I would prefer merging them through
the media tree if possible if there's no objection from the DRM
maintainers. I don't expect conflicting changes in the R-Car DU driver
for v7.2. Dave, Sima, could you give your ack for this ?

Laurent Pinchart (11):
  media: renesas: vsp1: Avoid forward function declaration
  media: renesas: vsp1: Split vsp1_du_setup_lif()
  drm: renesas: rcar-du: Switch to new VSP API
  drm: renesas: rz-du: Switch to new VSP API
  media: renesas: vsp1: Use mutex guards
  media: renesas: vsp1: Use mutex scoped guards
  media: renesas: vsp1: Use spinlock guards
  media: renesas: vsp1: Use spinlock scoped guards
  media: renesas: vsp1: Simplify iteration over format arrays
  media: renesas: vsp1: Declare index variables in for loop statement
  media: renesas: vsp1: Drop deprecated vsp1_du_setup_lif() function

 drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c |   4 +-
 drivers/gpu/drm/renesas/rz-du/rzg2l_du_vsp.c  |   4 +-
 .../media/platform/renesas/vsp1/vsp1_brx.c    |  40 +--
 .../media/platform/renesas/vsp1/vsp1_clu.c    |  18 +-
 drivers/media/platform/renesas/vsp1/vsp1_dl.c |  75 ++---
 .../media/platform/renesas/vsp1/vsp1_drm.c    | 269 +++++++++---------
 .../media/platform/renesas/vsp1/vsp1_drv.c    |  42 ++-
 .../media/platform/renesas/vsp1/vsp1_entity.c |  31 +-
 .../media/platform/renesas/vsp1/vsp1_hgo.c    |  17 +-
 .../media/platform/renesas/vsp1/vsp1_hgt.c    |  27 +-
 .../media/platform/renesas/vsp1/vsp1_histo.c  |  55 ++--
 .../media/platform/renesas/vsp1/vsp1_hsit.c   |  15 +-
 .../media/platform/renesas/vsp1/vsp1_lut.c    |  18 +-
 .../media/platform/renesas/vsp1/vsp1_pipe.c   |  65 ++---
 .../media/platform/renesas/vsp1/vsp1_rwpf.c   |  44 +--
 .../media/platform/renesas/vsp1/vsp1_sru.c    |  13 +-
 .../media/platform/renesas/vsp1/vsp1_uds.c    |  13 +-
 .../media/platform/renesas/vsp1/vsp1_uif.c    |  29 +-
 .../media/platform/renesas/vsp1/vsp1_video.c  | 191 +++++--------
 .../media/platform/renesas/vsp1/vsp1_wpf.c    |  38 +--
 include/media/vsp1.h                          |   5 +-
 21 files changed, 413 insertions(+), 600 deletions(-)


base-commit: bc1ba628e37c93cf2abeb2c79716f49087f8a024
prerequisite-patch-id: 5aca4e543fab1580689807ae68bea97cf436124b
prerequisite-patch-id: 1f31895481c2e7c8ba2adac3b2067236c8fec8b6
prerequisite-patch-id: c83c8d5e318389b8cab7761c5012ce9fad95337c
-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 01/11] media: renesas: vsp1: Avoid forward function declaration
  2026-05-11 23:56 [PATCH 00/11] media: renesas: vsp1: Modernize the driver Laurent Pinchart
@ 2026-05-11 23:56 ` Laurent Pinchart
  2026-05-13 19:09   ` Niklas Söderlund
  2026-05-11 23:56 ` [PATCH 02/11] media: renesas: vsp1: Split vsp1_du_setup_lif() Laurent Pinchart
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Laurent Pinchart @ 2026-05-11 23:56 UTC (permalink / raw)
  To: linux-media, dri-devel
  Cc: linux-renesas-soc, Tomi Valkeinen, Kieran Bingham, Biju Das,
	David Airlie, Simona Vetter

Reorder functions to avoid the forward declaration of the
vsp1_du_pipeline_configure(). No functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 .../media/platform/renesas/vsp1/vsp1_drm.c    | 90 +++++++++----------
 1 file changed, 44 insertions(+), 46 deletions(-)

diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drm.c b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
index 15d266439564..79b85968b061 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_drm.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
@@ -57,6 +57,50 @@ static void vsp1_du_pipeline_frame_end(struct vsp1_pipeline *pipe,
  * Pipeline Configuration
  */
 
+/* Configure all entities in the pipeline. */
+static void vsp1_du_pipeline_configure(struct vsp1_pipeline *pipe)
+{
+	struct vsp1_drm_pipeline *drm_pipe = to_vsp1_drm_pipeline(pipe);
+	struct vsp1_entity *entity;
+	struct vsp1_entity *next;
+	struct vsp1_dl_list *dl;
+	struct vsp1_dl_body *dlb;
+	unsigned int dl_flags = 0;
+
+	vsp1_pipeline_calculate_partition(pipe, &pipe->part_table[0],
+					  drm_pipe->width, 0);
+
+	if (drm_pipe->force_brx_release)
+		dl_flags |= VSP1_DL_FRAME_END_INTERNAL;
+	if (pipe->output->writeback)
+		dl_flags |= VSP1_DL_FRAME_END_WRITEBACK;
+
+	dl = vsp1_dl_list_get(pipe->output->dlm);
+	dlb = vsp1_dl_list_get_body0(dl);
+
+	list_for_each_entry_safe(entity, next, &pipe->entities, list_pipe) {
+		/* Disconnect unused entities from the pipeline. */
+		if (!entity->pipe) {
+			vsp1_dl_body_write(dlb, entity->route->reg,
+					   VI6_DPR_NODE_UNUSED);
+
+			entity->sink = NULL;
+			list_del(&entity->list_pipe);
+
+			continue;
+		}
+
+		vsp1_entity_route_setup(entity, pipe, dlb);
+		vsp1_entity_configure_stream(entity, entity->state, pipe,
+					     dl, dlb);
+		vsp1_entity_configure_frame(entity, pipe, dl, dlb);
+		vsp1_entity_configure_partition(entity, pipe,
+						&pipe->part_table[0], dl, dlb);
+	}
+
+	vsp1_dl_list_commit(dl, dl_flags);
+}
+
 /*
  * Insert the UIF in the pipeline between the prev and next entities. If no UIF
  * is available connect the two entities directly.
@@ -224,8 +268,6 @@ static int vsp1_du_pipeline_setup_rpf(struct vsp1_device *vsp1,
 /* Setup the BRx source pad. */
 static int vsp1_du_pipeline_setup_inputs(struct vsp1_device *vsp1,
 					 struct vsp1_pipeline *pipe);
-static void vsp1_du_pipeline_configure(struct vsp1_pipeline *pipe);
-
 static int vsp1_du_pipeline_setup_brx(struct vsp1_device *vsp1,
 				      struct vsp1_pipeline *pipe)
 {
@@ -541,50 +583,6 @@ static int vsp1_du_pipeline_setup_output(struct vsp1_device *vsp1,
 	return 0;
 }
 
-/* Configure all entities in the pipeline. */
-static void vsp1_du_pipeline_configure(struct vsp1_pipeline *pipe)
-{
-	struct vsp1_drm_pipeline *drm_pipe = to_vsp1_drm_pipeline(pipe);
-	struct vsp1_entity *entity;
-	struct vsp1_entity *next;
-	struct vsp1_dl_list *dl;
-	struct vsp1_dl_body *dlb;
-	unsigned int dl_flags = 0;
-
-	vsp1_pipeline_calculate_partition(pipe, &pipe->part_table[0],
-					  drm_pipe->width, 0);
-
-	if (drm_pipe->force_brx_release)
-		dl_flags |= VSP1_DL_FRAME_END_INTERNAL;
-	if (pipe->output->writeback)
-		dl_flags |= VSP1_DL_FRAME_END_WRITEBACK;
-
-	dl = vsp1_dl_list_get(pipe->output->dlm);
-	dlb = vsp1_dl_list_get_body0(dl);
-
-	list_for_each_entry_safe(entity, next, &pipe->entities, list_pipe) {
-		/* Disconnect unused entities from the pipeline. */
-		if (!entity->pipe) {
-			vsp1_dl_body_write(dlb, entity->route->reg,
-					   VI6_DPR_NODE_UNUSED);
-
-			entity->sink = NULL;
-			list_del(&entity->list_pipe);
-
-			continue;
-		}
-
-		vsp1_entity_route_setup(entity, pipe, dlb);
-		vsp1_entity_configure_stream(entity, entity->state, pipe,
-					     dl, dlb);
-		vsp1_entity_configure_frame(entity, pipe, dl, dlb);
-		vsp1_entity_configure_partition(entity, pipe,
-						&pipe->part_table[0], dl, dlb);
-	}
-
-	vsp1_dl_list_commit(dl, dl_flags);
-}
-
 static int vsp1_du_pipeline_set_rwpf_format(struct vsp1_device *vsp1,
 					    struct vsp1_rwpf *rwpf,
 					    u32 pixelformat, unsigned int pitch)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 02/11] media: renesas: vsp1: Split vsp1_du_setup_lif()
  2026-05-11 23:56 [PATCH 00/11] media: renesas: vsp1: Modernize the driver Laurent Pinchart
  2026-05-11 23:56 ` [PATCH 01/11] media: renesas: vsp1: Avoid forward function declaration Laurent Pinchart
@ 2026-05-11 23:56 ` Laurent Pinchart
  2026-05-13 19:11   ` Niklas Söderlund
  2026-05-11 23:56 ` [PATCH 03/11] drm: renesas: rcar-du: Switch to new VSP API Laurent Pinchart
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Laurent Pinchart @ 2026-05-11 23:56 UTC (permalink / raw)
  To: linux-media, dri-devel
  Cc: linux-renesas-soc, Tomi Valkeinen, Kieran Bingham, Biju Das,
	David Airlie, Simona Vetter

The vsp1_du_setup_lif() function is used to configure and enable a
pipeline, as well as disable it, depending on the cfg argument being a
valid pointer or NULL. This creates a confusing API. Improve it by
splitting the function in two, a vsp1_du_enable() function to configure
a pipeline, and a vsp1_du_disable() function to disaple it.

Keep vsp1_du_setup_lif() as an inline wrapper for existing callers in
the DRM subsystem, to simplify merging. The callers will be updated
separately and the old API will then be removed.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 .../media/platform/renesas/vsp1/vsp1_drm.c    | 140 ++++++++++--------
 include/media/vsp1.h                          |  14 +-
 2 files changed, 91 insertions(+), 63 deletions(-)

diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drm.c b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
index 79b85968b061..1f431874064d 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_drm.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
@@ -629,14 +629,14 @@ int vsp1_du_init(struct device *dev)
 EXPORT_SYMBOL_GPL(vsp1_du_init);
 
 /**
- * vsp1_du_setup_lif - Setup the output part of the VSP pipeline
+ * vsp1_du_enable - Setup and enable a DU pipeline
  * @dev: the VSP device
  * @pipe_index: the DRM pipeline index
  * @cfg: the LIF configuration
  *
  * Configure the output part of VSP DRM pipeline for the given frame @cfg.width
  * and @cfg.height. This sets up formats on the BRx source pad, the WPF sink and
- * source pads, and the LIF sink pad.
+ * source pads, and the LIF sink pad, and then starts the pipeline.
  *
  * The @pipe_index argument selects which DRM pipeline to setup. The number of
  * available pipelines depend on the VSP instance.
@@ -649,14 +649,13 @@ EXPORT_SYMBOL_GPL(vsp1_du_init);
  *
  * Return 0 on success or a negative error code on failure.
  */
-int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
-		      const struct vsp1_du_lif_config *cfg)
+int vsp1_du_enable(struct device *dev, unsigned int pipe_index,
+		   const struct vsp1_du_lif_config *cfg)
 {
 	struct vsp1_device *vsp1 = dev_get_drvdata(dev);
 	struct vsp1_drm_pipeline *drm_pipe;
 	struct vsp1_pipeline *pipe;
 	unsigned long flags;
-	unsigned int i;
 	int ret;
 
 	if (pipe_index >= vsp1->info->lif_count)
@@ -665,60 +664,6 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
 	drm_pipe = &vsp1->drm->pipe[pipe_index];
 	pipe = &drm_pipe->pipe;
 
-	if (!cfg) {
-		struct vsp1_brx *brx;
-
-		mutex_lock(&vsp1->drm->lock);
-
-		brx = to_brx(&pipe->brx->subdev);
-
-		/*
-		 * NULL configuration means the CRTC is being disabled, stop
-		 * the pipeline and turn the light off.
-		 */
-		ret = vsp1_pipeline_stop(pipe);
-		if (ret == -ETIMEDOUT)
-			dev_err(vsp1->dev, "DRM pipeline stop timeout\n");
-
-		for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) {
-			struct vsp1_rwpf *rpf = pipe->inputs[i];
-
-			if (!rpf)
-				continue;
-
-			/*
-			 * Remove the RPF from the pipe and the list of BRx
-			 * inputs.
-			 */
-			WARN_ON(!rpf->entity.pipe);
-			rpf->entity.pipe = NULL;
-			list_del(&rpf->entity.list_pipe);
-			pipe->inputs[i] = NULL;
-
-			brx->inputs[rpf->brx_input].rpf = NULL;
-		}
-
-		drm_pipe->du_complete = NULL;
-		pipe->num_inputs = 0;
-
-		dev_dbg(vsp1->dev, "%s: pipe %u: releasing %s\n",
-			__func__, pipe->lif->index,
-			BRX_NAME(pipe->brx));
-
-		list_del(&pipe->brx->list_pipe);
-		pipe->brx->pipe = NULL;
-		pipe->brx = NULL;
-
-		mutex_unlock(&vsp1->drm->lock);
-
-		vsp1_dlm_reset(pipe->output->dlm);
-		vsp1_device_put(vsp1);
-
-		dev_dbg(vsp1->dev, "%s: pipeline disabled\n", __func__);
-
-		return 0;
-	}
-
 	/* Reset the underrun counter */
 	pipe->underrun_count = 0;
 
@@ -741,7 +686,7 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
 	if (ret < 0)
 		goto unlock;
 
-	vsp1_pipeline_dump(pipe, "LIF setup");
+	vsp1_pipeline_dump(pipe, "DU enable");
 
 	/* Enable the VSP1. */
 	ret = vsp1_device_get(vsp1);
@@ -777,7 +722,80 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(vsp1_du_setup_lif);
+EXPORT_SYMBOL_GPL(vsp1_du_enable);
+
+/**
+ * vsp1_du_disable - Disable and stop a DU pipeline
+ * @dev: the VSP device
+ * @pipe_index: the DRM pipeline index
+ *
+ * The @pipe_index argument selects which DRM pipeline to disable. The number
+ * of available pipelines depend on the VSP instance.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int vsp1_du_disable(struct device *dev, unsigned int pipe_index)
+{
+	struct vsp1_device *vsp1 = dev_get_drvdata(dev);
+	struct vsp1_drm_pipeline *drm_pipe;
+	struct vsp1_pipeline *pipe;
+	struct vsp1_brx *brx;
+	unsigned int i;
+	int ret;
+
+	if (pipe_index >= vsp1->info->lif_count)
+		return -EINVAL;
+
+	drm_pipe = &vsp1->drm->pipe[pipe_index];
+	pipe = &drm_pipe->pipe;
+
+	mutex_lock(&vsp1->drm->lock);
+
+	brx = to_brx(&pipe->brx->subdev);
+
+	ret = vsp1_pipeline_stop(pipe);
+	if (ret == -ETIMEDOUT)
+		dev_err(vsp1->dev, "DRM pipeline stop timeout\n");
+
+	for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) {
+		struct vsp1_rwpf *rpf = pipe->inputs[i];
+
+		if (!rpf)
+			continue;
+
+		/*
+		 * Remove the RPF from the pipe and the list of BRx
+		 * inputs.
+		 */
+		WARN_ON(!rpf->entity.pipe);
+		rpf->entity.pipe = NULL;
+		list_del(&rpf->entity.list_pipe);
+		pipe->inputs[i] = NULL;
+
+		brx->inputs[rpf->brx_input].rpf = NULL;
+	}
+
+	drm_pipe->du_complete = NULL;
+	pipe->num_inputs = 0;
+
+	dev_dbg(vsp1->dev, "%s: pipe %u: releasing %s\n",
+		__func__, pipe->lif->index,
+		BRX_NAME(pipe->brx));
+
+	list_del(&pipe->brx->list_pipe);
+	pipe->brx->pipe = NULL;
+	pipe->brx = NULL;
+
+	mutex_unlock(&vsp1->drm->lock);
+
+	vsp1_dlm_reset(pipe->output->dlm);
+	vsp1_device_put(vsp1);
+
+	dev_dbg(vsp1->dev, "%s: pipeline disabled\n", __func__);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(vsp1_du_disable);
 
 /**
  * vsp1_du_atomic_begin - Prepare for an atomic update
diff --git a/include/media/vsp1.h b/include/media/vsp1.h
index d9b91ff02761..d2085cdb7fcb 100644
--- a/include/media/vsp1.h
+++ b/include/media/vsp1.h
@@ -44,8 +44,18 @@ struct vsp1_du_lif_config {
 	void *callback_data;
 };
 
-int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
-		      const struct vsp1_du_lif_config *cfg);
+int vsp1_du_enable(struct device *dev, unsigned int pipe_index,
+		   const struct vsp1_du_lif_config *cfg);
+int vsp1_du_disable(struct device *dev, unsigned int pipe_index);
+
+static inline int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
+				    const struct vsp1_du_lif_config *cfg)
+{
+	if (cfg)
+		return vsp1_du_enable(dev, pipe_index, cfg);
+	else
+		return vsp1_du_disable(dev, pipe_index);
+}
 
 /**
  * struct vsp1_du_atomic_config - VSP atomic configuration parameters
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 03/11] drm: renesas: rcar-du: Switch to new VSP API
  2026-05-11 23:56 [PATCH 00/11] media: renesas: vsp1: Modernize the driver Laurent Pinchart
  2026-05-11 23:56 ` [PATCH 01/11] media: renesas: vsp1: Avoid forward function declaration Laurent Pinchart
  2026-05-11 23:56 ` [PATCH 02/11] media: renesas: vsp1: Split vsp1_du_setup_lif() Laurent Pinchart
@ 2026-05-11 23:56 ` Laurent Pinchart
  2026-05-13 19:12   ` Niklas Söderlund
  2026-05-11 23:56 ` [PATCH 04/11] drm: renesas: rz-du: " Laurent Pinchart
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Laurent Pinchart @ 2026-05-11 23:56 UTC (permalink / raw)
  To: linux-media, dri-devel
  Cc: linux-renesas-soc, Tomi Valkeinen, Kieran Bingham, Biju Das,
	David Airlie, Simona Vetter

The vsp1_du_setup_lif() function is deprecated. Use the new
vsp1_du_enable() and vsp1_du_disable() functions instead.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c b/drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c
index a4a49dcd8233..5cfb4d50bc67 100644
--- a/drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c
+++ b/drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c
@@ -87,12 +87,12 @@ void rcar_du_vsp_enable(struct rcar_du_crtc *crtc)
 
 	__rcar_du_plane_setup(crtc->group, &state);
 
-	vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, &cfg);
+	vsp1_du_enable(crtc->vsp->vsp, crtc->vsp_pipe, &cfg);
 }
 
 void rcar_du_vsp_disable(struct rcar_du_crtc *crtc)
 {
-	vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, NULL);
+	vsp1_du_disable(crtc->vsp->vsp, crtc->vsp_pipe);
 }
 
 void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 04/11] drm: renesas: rz-du: Switch to new VSP API
  2026-05-11 23:56 [PATCH 00/11] media: renesas: vsp1: Modernize the driver Laurent Pinchart
                   ` (2 preceding siblings ...)
  2026-05-11 23:56 ` [PATCH 03/11] drm: renesas: rcar-du: Switch to new VSP API Laurent Pinchart
@ 2026-05-11 23:56 ` Laurent Pinchart
  2026-05-13 19:13   ` Niklas Söderlund
  2026-05-11 23:56 ` [PATCH 05/11] media: renesas: vsp1: Use mutex guards Laurent Pinchart
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Laurent Pinchart @ 2026-05-11 23:56 UTC (permalink / raw)
  To: linux-media, dri-devel
  Cc: linux-renesas-soc, Tomi Valkeinen, Kieran Bingham, Biju Das,
	David Airlie, Simona Vetter

The vsp1_du_setup_lif() function is deprecated. Use the new
vsp1_du_enable() and vsp1_du_disable() functions instead.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
Biju, I would like to merge this for v7.2 through the media tree instead
of the DRM tree. Would that be OK with you, or do you expect conflicting
changes to the rz-du driver for v7.2 ?
---
 drivers/gpu/drm/renesas/rz-du/rzg2l_du_vsp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_vsp.c b/drivers/gpu/drm/renesas/rz-du/rzg2l_du_vsp.c
index bd486377f037..d5a1d36db2c1 100644
--- a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_vsp.c
+++ b/drivers/gpu/drm/renesas/rz-du/rzg2l_du_vsp.c
@@ -55,12 +55,12 @@ void rzg2l_du_vsp_enable(struct rzg2l_du_crtc *crtc)
 		.callback_data = crtc,
 	};
 
-	vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, &cfg);
+	vsp1_du_enable(crtc->vsp->vsp, crtc->vsp_pipe, &cfg);
 }
 
 void rzg2l_du_vsp_disable(struct rzg2l_du_crtc *crtc)
 {
-	vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, NULL);
+	vsp1_du_disable(crtc->vsp->vsp, crtc->vsp_pipe);
 }
 
 void rzg2l_du_vsp_atomic_flush(struct rzg2l_du_crtc *crtc)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 05/11] media: renesas: vsp1: Use mutex guards
  2026-05-11 23:56 [PATCH 00/11] media: renesas: vsp1: Modernize the driver Laurent Pinchart
                   ` (3 preceding siblings ...)
  2026-05-11 23:56 ` [PATCH 04/11] drm: renesas: rz-du: " Laurent Pinchart
@ 2026-05-11 23:56 ` Laurent Pinchart
  2026-05-13 19:20   ` Niklas Söderlund
  2026-05-11 23:56 ` [PATCH 06/11] media: renesas: vsp1: Use mutex scoped guards Laurent Pinchart
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Laurent Pinchart @ 2026-05-11 23:56 UTC (permalink / raw)
  To: linux-media, dri-devel
  Cc: linux-renesas-soc, Tomi Valkeinen, Kieran Bingham, Biju Das,
	David Airlie, Simona Vetter

Replace manual mutex locking and unlocking with guards. This simplifies
error paths and reduces the amount of code. Limit the changes to
locations where the guard covers until the end of the function to ease
review. Scoped guards will be introduced separately.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 .../media/platform/renesas/vsp1/vsp1_brx.c    | 26 ++++-------
 .../media/platform/renesas/vsp1/vsp1_drm.c    |  7 +--
 .../media/platform/renesas/vsp1/vsp1_entity.c | 19 +++-----
 .../media/platform/renesas/vsp1/vsp1_histo.c  | 35 +++++----------
 .../media/platform/renesas/vsp1/vsp1_hsit.c   | 15 +++----
 .../media/platform/renesas/vsp1/vsp1_rwpf.c   | 44 ++++++-------------
 .../media/platform/renesas/vsp1/vsp1_sru.c    | 13 ++----
 .../media/platform/renesas/vsp1/vsp1_uds.c    | 13 ++----
 .../media/platform/renesas/vsp1/vsp1_uif.c    | 29 ++++--------
 .../media/platform/renesas/vsp1/vsp1_video.c  | 20 ++++-----
 .../media/platform/renesas/vsp1/vsp1_wpf.c    | 17 +++----
 11 files changed, 77 insertions(+), 161 deletions(-)

diff --git a/drivers/media/platform/renesas/vsp1/vsp1_brx.c b/drivers/media/platform/renesas/vsp1/vsp1_brx.c
index 9d93cb8b8e82..bd2672341386 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_brx.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_brx.c
@@ -130,15 +130,12 @@ static int brx_set_format(struct v4l2_subdev *subdev,
 	struct vsp1_brx *brx = to_brx(subdev);
 	struct v4l2_subdev_state *state;
 	struct v4l2_mbus_framefmt *format;
-	int ret = 0;
 
-	mutex_lock(&brx->entity.lock);
+	guard(mutex)(&brx->entity.lock);
 
 	state = vsp1_entity_get_state(&brx->entity, sd_state, fmt->which);
-	if (!state) {
-		ret = -EINVAL;
-		goto done;
-	}
+	if (!state)
+		return -EINVAL;
 
 	brx_try_format(brx, state, fmt->pad, &fmt->format);
 
@@ -166,9 +163,7 @@ static int brx_set_format(struct v4l2_subdev *subdev,
 		}
 	}
 
-done:
-	mutex_unlock(&brx->entity.lock);
-	return ret;
+	return 0;
 }
 
 static int brx_get_selection(struct v4l2_subdev *subdev,
@@ -213,7 +208,6 @@ static int brx_set_selection(struct v4l2_subdev *subdev,
 	struct v4l2_subdev_state *state;
 	struct v4l2_mbus_framefmt *format;
 	struct v4l2_rect *compose;
-	int ret = 0;
 
 	if (sel->pad == brx->entity.source_pad)
 		return -EINVAL;
@@ -221,13 +215,11 @@ static int brx_set_selection(struct v4l2_subdev *subdev,
 	if (sel->target != V4L2_SEL_TGT_COMPOSE)
 		return -EINVAL;
 
-	mutex_lock(&brx->entity.lock);
+	guard(mutex)(&brx->entity.lock);
 
 	state = vsp1_entity_get_state(&brx->entity, sd_state, sel->which);
-	if (!state) {
-		ret = -EINVAL;
-		goto done;
-	}
+	if (!state)
+		return -EINVAL;
 
 	/*
 	 * The compose rectangle top left corner must be inside the output
@@ -248,9 +240,7 @@ static int brx_set_selection(struct v4l2_subdev *subdev,
 	compose = v4l2_subdev_state_get_compose(state, sel->pad);
 	*compose = sel->r;
 
-done:
-	mutex_unlock(&brx->entity.lock);
-	return ret;
+	return 0;
 }
 
 static const struct v4l2_subdev_pad_ops brx_pad_ops = {
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drm.c b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
index 1f431874064d..1439cf7bfb59 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_drm.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
@@ -920,7 +920,7 @@ void vsp1_du_atomic_flush(struct device *dev, unsigned int pipe_index,
 
 	drm_pipe->crc = cfg->crc;
 
-	mutex_lock(&vsp1->drm->lock);
+	guard(mutex)(&vsp1->drm->lock);
 
 	if (cfg->writeback.pixelformat) {
 		const struct vsp1_du_writeback_config *wb_cfg = &cfg->writeback;
@@ -929,7 +929,7 @@ void vsp1_du_atomic_flush(struct device *dev, unsigned int pipe_index,
 						       wb_cfg->pixelformat,
 						       wb_cfg->pitch);
 		if (WARN_ON(ret < 0))
-			goto done;
+			return;
 
 		pipe->output->mem.addr[0] = wb_cfg->mem[0];
 		pipe->output->mem.addr[1] = wb_cfg->mem[1];
@@ -942,9 +942,6 @@ void vsp1_du_atomic_flush(struct device *dev, unsigned int pipe_index,
 	vsp1_pipeline_dump(pipe, "atomic update");
 
 	vsp1_du_pipeline_configure(pipe);
-
-done:
-	mutex_unlock(&vsp1->drm->lock);
 }
 EXPORT_SYMBOL_GPL(vsp1_du_atomic_flush);
 
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_entity.c b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
index 839b75b62ceb..3820ba53b45f 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_entity.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
@@ -172,9 +172,9 @@ int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev,
 	if (!state)
 		return -EINVAL;
 
-	mutex_lock(&entity->lock);
+	guard(mutex)(&entity->lock);
+
 	fmt->format = *v4l2_subdev_state_get_format(state, fmt->pad);
-	mutex_unlock(&entity->lock);
 
 	return 0;
 }
@@ -308,22 +308,19 @@ int vsp1_subdev_set_pad_format(struct v4l2_subdev *subdev,
 	struct v4l2_mbus_framefmt *format;
 	struct v4l2_rect *selection;
 	unsigned int i;
-	int ret = 0;
 
-	mutex_lock(&entity->lock);
+	guard(mutex)(&entity->lock);
 
 	state = vsp1_entity_get_state(entity, sd_state, fmt->which);
-	if (!state) {
-		ret = -EINVAL;
-		goto done;
-	}
+	if (!state)
+		return -EINVAL;
 
 	format = v4l2_subdev_state_get_format(state, fmt->pad);
 
 	if (fmt->pad == entity->source_pad) {
 		/* The output format can't be modified. */
 		fmt->format = *format;
-		goto done;
+		return 0;
 	}
 
 	/*
@@ -369,9 +366,7 @@ int vsp1_subdev_set_pad_format(struct v4l2_subdev *subdev,
 	selection->width = format->width;
 	selection->height = format->height;
 
-done:
-	mutex_unlock(&entity->lock);
-	return ret;
+	return 0;
 }
 
 static int vsp1_entity_init_state(struct v4l2_subdev *subdev,
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_histo.c b/drivers/media/platform/renesas/vsp1/vsp1_histo.c
index 3f87a2c9df0e..72f6ef2fdc4f 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_histo.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_histo.c
@@ -196,18 +196,15 @@ static int histo_get_selection(struct v4l2_subdev *subdev,
 	struct v4l2_subdev_state *state;
 	struct v4l2_mbus_framefmt *format;
 	struct v4l2_rect *crop;
-	int ret = 0;
 
 	if (sel->pad != HISTO_PAD_SINK)
 		return -EINVAL;
 
-	mutex_lock(&histo->entity.lock);
+	guard(mutex)(&histo->entity.lock);
 
 	state = vsp1_entity_get_state(&histo->entity, sd_state, sel->which);
-	if (!state) {
-		ret = -EINVAL;
-		goto done;
-	}
+	if (!state)
+		return -EINVAL;
 
 	switch (sel->target) {
 	case V4L2_SEL_TGT_COMPOSE_BOUNDS:
@@ -237,13 +234,10 @@ static int histo_get_selection(struct v4l2_subdev *subdev,
 		break;
 
 	default:
-		ret = -EINVAL;
-		break;
+		return -EINVAL;
 	}
 
-done:
-	mutex_unlock(&histo->entity.lock);
-	return ret;
+	return 0;
 }
 
 static int histo_set_crop(struct v4l2_subdev *subdev,
@@ -321,29 +315,22 @@ static int histo_set_selection(struct v4l2_subdev *subdev,
 {
 	struct vsp1_histogram *histo = subdev_to_histo(subdev);
 	struct v4l2_subdev_state *state;
-	int ret;
 
 	if (sel->pad != HISTO_PAD_SINK)
 		return -EINVAL;
 
-	mutex_lock(&histo->entity.lock);
+	guard(mutex)(&histo->entity.lock);
 
 	state = vsp1_entity_get_state(&histo->entity, sd_state, sel->which);
-	if (!state) {
-		ret = -EINVAL;
-		goto done;
-	}
+	if (!state)
+		return -EINVAL;
 
 	if (sel->target == V4L2_SEL_TGT_CROP)
-		ret = histo_set_crop(subdev, state, sel);
+		return histo_set_crop(subdev, state, sel);
 	else if (sel->target == V4L2_SEL_TGT_COMPOSE)
-		ret = histo_set_compose(subdev, state, sel);
+		return histo_set_compose(subdev, state, sel);
 	else
-		ret = -EINVAL;
-
-done:
-	mutex_unlock(&histo->entity.lock);
-	return ret;
+		return -EINVAL;
 }
 
 static int histo_set_format(struct v4l2_subdev *subdev,
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_hsit.c b/drivers/media/platform/renesas/vsp1/vsp1_hsit.c
index 830e124beb7b..df069c228243 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_hsit.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_hsit.c
@@ -115,15 +115,12 @@ static int hsit_set_format(struct v4l2_subdev *subdev,
 	struct vsp1_hsit *hsit = to_hsit(subdev);
 	struct v4l2_subdev_state *state;
 	struct v4l2_mbus_framefmt *format;
-	int ret = 0;
 
-	mutex_lock(&hsit->entity.lock);
+	guard(mutex)(&hsit->entity.lock);
 
 	state = vsp1_entity_get_state(&hsit->entity, sd_state, fmt->which);
-	if (!state) {
-		ret = -EINVAL;
-		goto done;
-	}
+	if (!state)
+		return -EINVAL;
 
 	format = v4l2_subdev_state_get_format(state, fmt->pad);
 
@@ -133,7 +130,7 @@ static int hsit_set_format(struct v4l2_subdev *subdev,
 		 * modified.
 		 */
 		fmt->format = *format;
-		goto done;
+		return 0;
 	}
 
 	format->code = hsit->inverse ? MEDIA_BUS_FMT_AHSV8888_1X32
@@ -161,9 +158,7 @@ static int hsit_set_format(struct v4l2_subdev *subdev,
 
 	vsp1_entity_adjust_color_space(format);
 
-done:
-	mutex_unlock(&hsit->entity.lock);
-	return ret;
+	return 0;
 }
 
 static const struct v4l2_subdev_pad_ops hsit_pad_ops = {
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_rwpf.c b/drivers/media/platform/renesas/vsp1/vsp1_rwpf.c
index c72518b29f84..ced01870acd6 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_rwpf.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_rwpf.c
@@ -116,15 +116,12 @@ static int vsp1_rwpf_set_format(struct v4l2_subdev *subdev,
 	struct vsp1_rwpf *rwpf = to_rwpf(subdev);
 	struct v4l2_subdev_state *state;
 	struct v4l2_mbus_framefmt *format;
-	int ret = 0;
 
-	mutex_lock(&rwpf->entity.lock);
+	guard(mutex)(&rwpf->entity.lock);
 
 	state = vsp1_entity_get_state(&rwpf->entity, sd_state, fmt->which);
-	if (!state) {
-		ret = -EINVAL;
-		goto done;
-	}
+	if (!state)
+		return -EINVAL;
 
 	/* Default to YUV if the requested format is not supported. */
 	if (fmt->format.code != MEDIA_BUS_FMT_ARGB8888_1X32 &&
@@ -174,7 +171,7 @@ static int vsp1_rwpf_set_format(struct v4l2_subdev *subdev,
 		fmt->format = *format;
 		fmt->format.flags = flags;
 
-		goto done;
+		return 0;
 	}
 
 	format->code = fmt->format.code;
@@ -213,9 +210,7 @@ static int vsp1_rwpf_set_format(struct v4l2_subdev *subdev,
 		format->height = fmt->format.width;
 	}
 
-done:
-	mutex_unlock(&rwpf->entity.lock);
-	return ret;
+	return 0;
 }
 
 static int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev,
@@ -225,7 +220,6 @@ static int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev,
 	struct vsp1_rwpf *rwpf = to_rwpf(subdev);
 	struct v4l2_subdev_state *state;
 	struct v4l2_mbus_framefmt *format;
-	int ret = 0;
 
 	/*
 	 * Cropping is only supported on the RPF and is implemented on the sink
@@ -234,13 +228,11 @@ static int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev,
 	if (rwpf->entity.type == VSP1_ENTITY_WPF || sel->pad != RWPF_PAD_SINK)
 		return -EINVAL;
 
-	mutex_lock(&rwpf->entity.lock);
+	guard(mutex)(&rwpf->entity.lock);
 
 	state = vsp1_entity_get_state(&rwpf->entity, sd_state, sel->which);
-	if (!state) {
-		ret = -EINVAL;
-		goto done;
-	}
+	if (!state)
+		return -EINVAL;
 
 	switch (sel->target) {
 	case V4L2_SEL_TGT_CROP:
@@ -256,13 +248,10 @@ static int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev,
 		break;
 
 	default:
-		ret = -EINVAL;
-		break;
+		return -EINVAL;
 	}
 
-done:
-	mutex_unlock(&rwpf->entity.lock);
-	return ret;
+	return 0;
 }
 
 static int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev,
@@ -275,7 +264,6 @@ static int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev,
 	struct v4l2_subdev_state *state;
 	struct v4l2_mbus_framefmt *format;
 	struct v4l2_rect *crop;
-	int ret = 0;
 
 	/*
 	 * Cropping is only supported on the RPF and is implemented on the sink
@@ -287,13 +275,11 @@ static int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev,
 	if (sel->target != V4L2_SEL_TGT_CROP)
 		return -EINVAL;
 
-	mutex_lock(&rwpf->entity.lock);
+	guard(mutex)(&rwpf->entity.lock);
 
 	state = vsp1_entity_get_state(&rwpf->entity, sd_state, sel->which);
-	if (!state) {
-		ret = -EINVAL;
-		goto done;
-	}
+	if (!state)
+		return -EINVAL;
 
 	/* Make sure the crop rectangle is entirely contained in the image. */
 	format = v4l2_subdev_state_get_format(state, RWPF_PAD_SINK);
@@ -342,9 +328,7 @@ static int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev,
 	format->width = crop->width;
 	format->height = crop->height;
 
-done:
-	mutex_unlock(&rwpf->entity.lock);
-	return ret;
+	return 0;
 }
 
 static const struct v4l2_subdev_pad_ops vsp1_rwpf_pad_ops = {
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_sru.c b/drivers/media/platform/renesas/vsp1/vsp1_sru.c
index 94149da0c900..3fd9fde5c724 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_sru.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_sru.c
@@ -216,15 +216,12 @@ static int sru_set_format(struct v4l2_subdev *subdev,
 	struct vsp1_sru *sru = to_sru(subdev);
 	struct v4l2_subdev_state *state;
 	struct v4l2_mbus_framefmt *format;
-	int ret = 0;
 
-	mutex_lock(&sru->entity.lock);
+	guard(mutex)(&sru->entity.lock);
 
 	state = vsp1_entity_get_state(&sru->entity, sd_state, fmt->which);
-	if (!state) {
-		ret = -EINVAL;
-		goto done;
-	}
+	if (!state)
+		return -EINVAL;
 
 	sru_try_format(sru, state, fmt->pad, &fmt->format);
 
@@ -239,9 +236,7 @@ static int sru_set_format(struct v4l2_subdev *subdev,
 		sru_try_format(sru, state, SRU_PAD_SOURCE, format);
 	}
 
-done:
-	mutex_unlock(&sru->entity.lock);
-	return ret;
+	return 0;
 }
 
 static const struct v4l2_subdev_pad_ops sru_pad_ops = {
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_uds.c b/drivers/media/platform/renesas/vsp1/vsp1_uds.c
index dd4722315c56..9f7bb112929e 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_uds.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_uds.c
@@ -199,15 +199,12 @@ static int uds_set_format(struct v4l2_subdev *subdev,
 	struct vsp1_uds *uds = to_uds(subdev);
 	struct v4l2_subdev_state *state;
 	struct v4l2_mbus_framefmt *format;
-	int ret = 0;
 
-	mutex_lock(&uds->entity.lock);
+	guard(mutex)(&uds->entity.lock);
 
 	state = vsp1_entity_get_state(&uds->entity, sd_state, fmt->which);
-	if (!state) {
-		ret = -EINVAL;
-		goto done;
-	}
+	if (!state)
+		return -EINVAL;
 
 	uds_try_format(uds, state, fmt->pad, &fmt->format);
 
@@ -222,9 +219,7 @@ static int uds_set_format(struct v4l2_subdev *subdev,
 		uds_try_format(uds, state, UDS_PAD_SOURCE, format);
 	}
 
-done:
-	mutex_unlock(&uds->entity.lock);
-	return ret;
+	return 0;
 }
 
 /* -----------------------------------------------------------------------------
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_uif.c b/drivers/media/platform/renesas/vsp1/vsp1_uif.c
index 3aefe5c9d421..52dbfe58a70d 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_uif.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_uif.c
@@ -60,18 +60,15 @@ static int uif_get_selection(struct v4l2_subdev *subdev,
 	struct vsp1_uif *uif = to_uif(subdev);
 	struct v4l2_subdev_state *state;
 	struct v4l2_mbus_framefmt *format;
-	int ret = 0;
 
 	if (sel->pad != UIF_PAD_SINK)
 		return -EINVAL;
 
-	mutex_lock(&uif->entity.lock);
+	guard(mutex)(&uif->entity.lock);
 
 	state = vsp1_entity_get_state(&uif->entity, sd_state, sel->which);
-	if (!state) {
-		ret = -EINVAL;
-		goto done;
-	}
+	if (!state)
+		return -EINVAL;
 
 	switch (sel->target) {
 	case V4L2_SEL_TGT_CROP_BOUNDS:
@@ -88,13 +85,10 @@ static int uif_get_selection(struct v4l2_subdev *subdev,
 		break;
 
 	default:
-		ret = -EINVAL;
-		break;
+		return -EINVAL;
 	}
 
-done:
-	mutex_unlock(&uif->entity.lock);
-	return ret;
+	return 0;
 }
 
 static int uif_set_selection(struct v4l2_subdev *subdev,
@@ -105,19 +99,16 @@ static int uif_set_selection(struct v4l2_subdev *subdev,
 	struct v4l2_subdev_state *state;
 	struct v4l2_mbus_framefmt *format;
 	struct v4l2_rect *selection;
-	int ret = 0;
 
 	if (sel->pad != UIF_PAD_SINK ||
 	    sel->target != V4L2_SEL_TGT_CROP)
 		return -EINVAL;
 
-	mutex_lock(&uif->entity.lock);
+	guard(mutex)(&uif->entity.lock);
 
 	state = vsp1_entity_get_state(&uif->entity, sd_state, sel->which);
-	if (!state) {
-		ret = -EINVAL;
-		goto done;
-	}
+	if (!state)
+		return -EINVAL;
 
 	/* The crop rectangle must be inside the input frame. */
 	format = v4l2_subdev_state_get_format(state, UIF_PAD_SINK);
@@ -133,9 +124,7 @@ static int uif_set_selection(struct v4l2_subdev *subdev,
 	selection = v4l2_subdev_state_get_crop(state, sel->pad);
 	*selection = sel->r;
 
-done:
-	mutex_unlock(&uif->entity.lock);
-	return ret;
+	return 0;
 }
 
 /* -----------------------------------------------------------------------------
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c
index a8db94bdb670..4cf2cc370416 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_video.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c
@@ -590,9 +590,9 @@ static void vsp1_video_pipeline_put(struct vsp1_pipeline *pipe)
 {
 	struct media_device *mdev = &pipe->output->entity.vsp1->media_dev;
 
-	mutex_lock(&mdev->graph_mutex);
+	guard(mutex)(&mdev->graph_mutex);
+
 	kref_put(&pipe->kref, vsp1_video_pipeline_release);
-	mutex_unlock(&mdev->graph_mutex);
 }
 
 /* -----------------------------------------------------------------------------
@@ -933,9 +933,9 @@ vsp1_video_get_format(struct file *file, void *fh, struct v4l2_format *format)
 	if (format->type != video->queue.type)
 		return -EINVAL;
 
-	mutex_lock(&video->lock);
+	guard(mutex)(&video->lock);
+
 	format->fmt.pix_mp = video->rwpf->format;
-	mutex_unlock(&video->lock);
 
 	return 0;
 }
@@ -967,19 +967,15 @@ vsp1_video_set_format(struct file *file, void *fh, struct v4l2_format *format)
 	if (ret < 0)
 		return ret;
 
-	mutex_lock(&video->lock);
+	guard(mutex)(&video->lock);
 
-	if (vb2_is_busy(&video->queue)) {
-		ret = -EBUSY;
-		goto done;
-	}
+	if (vb2_is_busy(&video->queue))
+		return -EBUSY;
 
 	video->rwpf->format = format->fmt.pix_mp;
 	video->rwpf->fmtinfo = info;
 
-done:
-	mutex_unlock(&video->lock);
-	return ret;
+	return 0;
 }
 
 static int
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
index cd6c5592221b..e7ed3c8e9e90 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
@@ -47,7 +47,6 @@ static int vsp1_wpf_set_rotation(struct vsp1_rwpf *wpf, unsigned int rotation)
 	struct v4l2_mbus_framefmt *sink_format;
 	struct v4l2_mbus_framefmt *source_format;
 	bool rotate;
-	int ret = 0;
 
 	/*
 	 * Only consider the 0°/180° from/to 90°/270° modifications, the rest
@@ -58,19 +57,17 @@ static int vsp1_wpf_set_rotation(struct vsp1_rwpf *wpf, unsigned int rotation)
 		return 0;
 
 	/* Changing rotation isn't allowed when buffers are allocated. */
-	mutex_lock(&video->lock);
+	guard(mutex)(&video->lock);
 
-	if (vb2_is_busy(&video->queue)) {
-		ret = -EBUSY;
-		goto done;
-	}
+	if (vb2_is_busy(&video->queue))
+		return -EBUSY;
 
 	sink_format = v4l2_subdev_state_get_format(wpf->entity.state,
 						   RWPF_PAD_SINK);
 	source_format = v4l2_subdev_state_get_format(wpf->entity.state,
 						     RWPF_PAD_SOURCE);
 
-	mutex_lock(&wpf->entity.lock);
+	guard(mutex)(&wpf->entity.lock);
 
 	if (rotate) {
 		source_format->width = sink_format->height;
@@ -82,11 +79,7 @@ static int vsp1_wpf_set_rotation(struct vsp1_rwpf *wpf, unsigned int rotation)
 
 	wpf->flip.rotate = rotate;
 
-	mutex_unlock(&wpf->entity.lock);
-
-done:
-	mutex_unlock(&video->lock);
-	return ret;
+	return 0;
 }
 
 static int vsp1_wpf_s_ctrl(struct v4l2_ctrl *ctrl)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 06/11] media: renesas: vsp1: Use mutex scoped guards
  2026-05-11 23:56 [PATCH 00/11] media: renesas: vsp1: Modernize the driver Laurent Pinchart
                   ` (4 preceding siblings ...)
  2026-05-11 23:56 ` [PATCH 05/11] media: renesas: vsp1: Use mutex guards Laurent Pinchart
@ 2026-05-11 23:56 ` Laurent Pinchart
  2026-05-13 19:24   ` Niklas Söderlund
  2026-05-11 23:56 ` [PATCH 07/11] media: renesas: vsp1: Use spinlock guards Laurent Pinchart
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Laurent Pinchart @ 2026-05-11 23:56 UTC (permalink / raw)
  To: linux-media, dri-devel
  Cc: linux-renesas-soc, Tomi Valkeinen, Kieran Bingham, Biju Das,
	David Airlie, Simona Vetter

Replace remaining manual mutex locking and unlocking with scoped
guards. This simplifies error paths and reduces the amount of code.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 .../media/platform/renesas/vsp1/vsp1_brx.c    |   7 +-
 .../media/platform/renesas/vsp1/vsp1_drm.c    | 117 ++++++++----------
 .../media/platform/renesas/vsp1/vsp1_entity.c |   8 +-
 .../media/platform/renesas/vsp1/vsp1_hgo.c    |  10 +-
 .../media/platform/renesas/vsp1/vsp1_hgt.c    |  16 +--
 .../media/platform/renesas/vsp1/vsp1_video.c  |  60 ++++-----
 6 files changed, 102 insertions(+), 116 deletions(-)

diff --git a/drivers/media/platform/renesas/vsp1/vsp1_brx.c b/drivers/media/platform/renesas/vsp1/vsp1_brx.c
index bd2672341386..325be30836d7 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_brx.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_brx.c
@@ -190,9 +190,10 @@ static int brx_get_selection(struct v4l2_subdev *subdev,
 		if (!state)
 			return -EINVAL;
 
-		mutex_lock(&brx->entity.lock);
-		sel->r = *v4l2_subdev_state_get_compose(state, sel->pad);
-		mutex_unlock(&brx->entity.lock);
+		scoped_guard(mutex, &brx->entity.lock) {
+			sel->r = *v4l2_subdev_state_get_compose(state, sel->pad);
+		}
+
 		return 0;
 
 	default:
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drm.c b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
index 1439cf7bfb59..2b64d9b5a81c 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_drm.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
@@ -675,43 +675,37 @@ int vsp1_du_enable(struct device *dev, unsigned int pipe_index,
 		__func__, pipe_index, cfg->width, cfg->height,
 		pipe->interlaced ? "i" : "");
 
-	mutex_lock(&vsp1->drm->lock);
+	scoped_guard(mutex, &vsp1->drm->lock) {
+		/* Setup formats through the pipeline. */
+		ret = vsp1_du_pipeline_setup_inputs(vsp1, pipe);
+		if (ret < 0)
+			return ret;
 
-	/* Setup formats through the pipeline. */
-	ret = vsp1_du_pipeline_setup_inputs(vsp1, pipe);
-	if (ret < 0)
-		goto unlock;
+		ret = vsp1_du_pipeline_setup_output(vsp1, pipe);
+		if (ret < 0)
+			return ret;
 
-	ret = vsp1_du_pipeline_setup_output(vsp1, pipe);
-	if (ret < 0)
-		goto unlock;
+		vsp1_pipeline_dump(pipe, "DU enable");
 
-	vsp1_pipeline_dump(pipe, "DU enable");
+		/* Enable the VSP1. */
+		ret = vsp1_device_get(vsp1);
+		if (ret < 0)
+			return ret;
 
-	/* Enable the VSP1. */
-	ret = vsp1_device_get(vsp1);
-	if (ret < 0)
-		goto unlock;
+		/*
+		 * Register a callback to allow us to notify the DRM driver of frame
+		 * completion events.
+		 */
+		drm_pipe->du_complete = cfg->callback;
+		drm_pipe->du_private = cfg->callback_data;
 
-	/*
-	 * Register a callback to allow us to notify the DRM driver of frame
-	 * completion events.
-	 */
-	drm_pipe->du_complete = cfg->callback;
-	drm_pipe->du_private = cfg->callback_data;
+		/* Disable the display interrupts. */
+		vsp1_write(vsp1, VI6_DISP_IRQ_STA(pipe_index), 0);
+		vsp1_write(vsp1, VI6_DISP_IRQ_ENB(pipe_index), 0);
 
-	/* Disable the display interrupts. */
-	vsp1_write(vsp1, VI6_DISP_IRQ_STA(pipe_index), 0);
-	vsp1_write(vsp1, VI6_DISP_IRQ_ENB(pipe_index), 0);
-
-	/* Configure all entities in the pipeline. */
-	vsp1_du_pipeline_configure(pipe);
-
-unlock:
-	mutex_unlock(&vsp1->drm->lock);
-
-	if (ret < 0)
-		return ret;
+		/* Configure all entities in the pipeline. */
+		vsp1_du_pipeline_configure(pipe);
+	}
 
 	/* Start the pipeline. */
 	spin_lock_irqsave(&pipe->irqlock, flags);
@@ -739,7 +733,6 @@ int vsp1_du_disable(struct device *dev, unsigned int pipe_index)
 	struct vsp1_device *vsp1 = dev_get_drvdata(dev);
 	struct vsp1_drm_pipeline *drm_pipe;
 	struct vsp1_pipeline *pipe;
-	struct vsp1_brx *brx;
 	unsigned int i;
 	int ret;
 
@@ -749,45 +742,43 @@ int vsp1_du_disable(struct device *dev, unsigned int pipe_index)
 	drm_pipe = &vsp1->drm->pipe[pipe_index];
 	pipe = &drm_pipe->pipe;
 
-	mutex_lock(&vsp1->drm->lock);
+	scoped_guard(mutex, &vsp1->drm->lock) {
+		struct vsp1_brx *brx = to_brx(&pipe->brx->subdev);
 
-	brx = to_brx(&pipe->brx->subdev);
+		ret = vsp1_pipeline_stop(pipe);
+		if (ret == -ETIMEDOUT)
+			dev_err(vsp1->dev, "DRM pipeline stop timeout\n");
 
-	ret = vsp1_pipeline_stop(pipe);
-	if (ret == -ETIMEDOUT)
-		dev_err(vsp1->dev, "DRM pipeline stop timeout\n");
+		for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) {
+			struct vsp1_rwpf *rpf = pipe->inputs[i];
 
-	for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) {
-		struct vsp1_rwpf *rpf = pipe->inputs[i];
+			if (!rpf)
+				continue;
 
-		if (!rpf)
-			continue;
+			/*
+			 * Remove the RPF from the pipe and the list of BRx
+			 * inputs.
+			 */
+			WARN_ON(!rpf->entity.pipe);
+			rpf->entity.pipe = NULL;
+			list_del(&rpf->entity.list_pipe);
+			pipe->inputs[i] = NULL;
 
-		/*
-		 * Remove the RPF from the pipe and the list of BRx
-		 * inputs.
-		 */
-		WARN_ON(!rpf->entity.pipe);
-		rpf->entity.pipe = NULL;
-		list_del(&rpf->entity.list_pipe);
-		pipe->inputs[i] = NULL;
+			brx->inputs[rpf->brx_input].rpf = NULL;
+		}
 
-		brx->inputs[rpf->brx_input].rpf = NULL;
+		drm_pipe->du_complete = NULL;
+		pipe->num_inputs = 0;
+
+		dev_dbg(vsp1->dev, "%s: pipe %u: releasing %s\n",
+			__func__, pipe->lif->index,
+			BRX_NAME(pipe->brx));
+
+		list_del(&pipe->brx->list_pipe);
+		pipe->brx->pipe = NULL;
+		pipe->brx = NULL;
 	}
 
-	drm_pipe->du_complete = NULL;
-	pipe->num_inputs = 0;
-
-	dev_dbg(vsp1->dev, "%s: pipe %u: releasing %s\n",
-		__func__, pipe->lif->index,
-		BRX_NAME(pipe->brx));
-
-	list_del(&pipe->brx->list_pipe);
-	pipe->brx->pipe = NULL;
-	pipe->brx = NULL;
-
-	mutex_unlock(&vsp1->drm->lock);
-
 	vsp1_dlm_reset(pipe->output->dlm);
 	vsp1_device_put(vsp1);
 
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_entity.c b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
index 3820ba53b45f..2ae2a573f0de 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_entity.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
@@ -216,10 +216,10 @@ int vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev,
 		if (!state)
 			return -EINVAL;
 
-		mutex_lock(&entity->lock);
-		format = v4l2_subdev_state_get_format(state, 0);
-		code->code = format->code;
-		mutex_unlock(&entity->lock);
+		scoped_guard(mutex, &entity->lock) {
+			format = v4l2_subdev_state_get_format(state, 0);
+			code->code = format->code;
+		}
 	}
 
 	return 0;
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_hgo.c b/drivers/media/platform/renesas/vsp1/vsp1_hgo.c
index 2c8ce7175a4e..0ef512e3a94b 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_hgo.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_hgo.c
@@ -153,11 +153,11 @@ static void hgo_configure_stream(struct vsp1_entity *entity,
 		       (crop->width << VI6_HGO_SIZE_HSIZE_SHIFT) |
 		       (crop->height << VI6_HGO_SIZE_VSIZE_SHIFT));
 
-	mutex_lock(hgo->ctrls.handler.lock);
-	hgo->max_rgb = hgo->ctrls.max_rgb->cur.val;
-	if (hgo->ctrls.num_bins)
-		hgo->num_bins = hgo_num_bins[hgo->ctrls.num_bins->cur.val];
-	mutex_unlock(hgo->ctrls.handler.lock);
+	scoped_guard(mutex, hgo->ctrls.handler.lock) {
+		hgo->max_rgb = hgo->ctrls.max_rgb->cur.val;
+		if (hgo->ctrls.num_bins)
+			hgo->num_bins = hgo_num_bins[hgo->ctrls.num_bins->cur.val];
+	}
 
 	hratio = crop->width * 2 / compose->width / 3;
 	vratio = crop->height * 2 / compose->height / 3;
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_hgt.c b/drivers/media/platform/renesas/vsp1/vsp1_hgt.c
index 858f330d44fa..78b5a9201c70 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_hgt.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_hgt.c
@@ -152,15 +152,15 @@ static void hgt_configure_stream(struct vsp1_entity *entity,
 		       (crop->width << VI6_HGT_SIZE_HSIZE_SHIFT) |
 		       (crop->height << VI6_HGT_SIZE_VSIZE_SHIFT));
 
-	mutex_lock(hgt->ctrls.lock);
-	for (i = 0; i < HGT_NUM_HUE_AREAS; ++i) {
-		lower = hgt->hue_areas[i*2 + 0];
-		upper = hgt->hue_areas[i*2 + 1];
-		vsp1_hgt_write(hgt, dlb, VI6_HGT_HUE_AREA(i),
-			       (lower << VI6_HGT_HUE_AREA_LOWER_SHIFT) |
-			       (upper << VI6_HGT_HUE_AREA_UPPER_SHIFT));
+	scoped_guard(mutex, hgt->ctrls.lock) {
+		for (i = 0; i < HGT_NUM_HUE_AREAS; ++i) {
+			lower = hgt->hue_areas[i*2 + 0];
+			upper = hgt->hue_areas[i*2 + 1];
+			vsp1_hgt_write(hgt, dlb, VI6_HGT_HUE_AREA(i),
+				       (lower << VI6_HGT_HUE_AREA_LOWER_SHIFT) |
+				       (upper << VI6_HGT_HUE_AREA_UPPER_SHIFT));
+		}
 	}
-	mutex_unlock(hgt->ctrls.lock);
 
 	hratio = crop->width * 2 / compose->width / 3;
 	vratio = crop->height * 2 / compose->height / 3;
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c
index 4cf2cc370416..138d4e08eee9 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_video.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c
@@ -810,22 +810,21 @@ static int vsp1_video_start_streaming(struct vb2_queue *vq, unsigned int count)
 	unsigned long flags;
 	int ret;
 
-	mutex_lock(&pipe->lock);
-	if (pipe->stream_count == pipe->num_inputs) {
-		ret = vsp1_video_setup_pipeline(pipe);
-		if (ret < 0) {
-			vsp1_video_release_buffers(video);
-			vsp1_video_cleanup_pipeline(pipe);
-			mutex_unlock(&pipe->lock);
-			return ret;
+	scoped_guard(mutex, &pipe->lock) {
+		if (pipe->stream_count == pipe->num_inputs) {
+			ret = vsp1_video_setup_pipeline(pipe);
+			if (ret < 0) {
+				vsp1_video_release_buffers(video);
+				vsp1_video_cleanup_pipeline(pipe);
+				return ret;
+			}
+
+			start_pipeline = true;
 		}
 
-		start_pipeline = true;
+		pipe->stream_count++;
 	}
 
-	pipe->stream_count++;
-	mutex_unlock(&pipe->lock);
-
 	/*
 	 * vsp1_pipeline_ready() is not sufficient to establish that all streams
 	 * are prepared and the pipeline is configured, as multiple streams
@@ -859,16 +858,17 @@ static void vsp1_video_stop_streaming(struct vb2_queue *vq)
 	pipe->buffers_ready &= ~(1 << video->pipe_index);
 	spin_unlock_irqrestore(&video->irqlock, flags);
 
-	mutex_lock(&pipe->lock);
-	if (--pipe->stream_count == pipe->num_inputs) {
-		/* Stop the pipeline. */
-		ret = vsp1_pipeline_stop(pipe);
-		if (ret == -ETIMEDOUT)
-			dev_err(video->vsp1->dev, "pipeline stop timeout\n");
+	scoped_guard(mutex, &pipe->lock) {
+		if (--pipe->stream_count == pipe->num_inputs) {
+			/* Stop the pipeline. */
+			ret = vsp1_pipeline_stop(pipe);
+			if (ret == -ETIMEDOUT)
+				dev_err(video->vsp1->dev,
+					"pipeline stop timeout\n");
 
-		vsp1_video_cleanup_pipeline(pipe);
+			vsp1_video_cleanup_pipeline(pipe);
+		}
 	}
-	mutex_unlock(&pipe->lock);
 
 	video_device_pipeline_stop(&video->video);
 	vsp1_video_release_buffers(video);
@@ -995,22 +995,16 @@ vsp1_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 	 * touching an entity in the pipeline can be activated or deactivated
 	 * once streaming is started.
 	 */
-	mutex_lock(&mdev->graph_mutex);
+	scoped_guard(mutex, &mdev->graph_mutex) {
+		pipe = vsp1_video_pipeline_get(video);
+		if (IS_ERR(pipe))
+			return PTR_ERR(pipe);
 
-	pipe = vsp1_video_pipeline_get(video);
-	if (IS_ERR(pipe)) {
-		mutex_unlock(&mdev->graph_mutex);
-		return PTR_ERR(pipe);
+		ret = __video_device_pipeline_start(&video->video, &pipe->pipe);
+		if (ret < 0)
+			goto err_pipe;
 	}
 
-	ret = __video_device_pipeline_start(&video->video, &pipe->pipe);
-	if (ret < 0) {
-		mutex_unlock(&mdev->graph_mutex);
-		goto err_pipe;
-	}
-
-	mutex_unlock(&mdev->graph_mutex);
-
 	/*
 	 * Verify that the configured format matches the output of the connected
 	 * subdev.
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 07/11] media: renesas: vsp1: Use spinlock guards
  2026-05-11 23:56 [PATCH 00/11] media: renesas: vsp1: Modernize the driver Laurent Pinchart
                   ` (5 preceding siblings ...)
  2026-05-11 23:56 ` [PATCH 06/11] media: renesas: vsp1: Use mutex scoped guards Laurent Pinchart
@ 2026-05-11 23:56 ` Laurent Pinchart
  2026-05-13 19:29   ` Niklas Söderlund
  2026-05-11 23:56 ` [PATCH 08/11] media: renesas: vsp1: Use spinlock scoped guards Laurent Pinchart
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Laurent Pinchart @ 2026-05-11 23:56 UTC (permalink / raw)
  To: linux-media, dri-devel
  Cc: linux-renesas-soc, Tomi Valkeinen, Kieran Bingham, Biju Das,
	David Airlie, Simona Vetter

Replace manual spinlock locking and unlocking with guards. This
simplifies error paths and reduces the amount of code. Limit the changes
to locations where the guard covers until the end of the function to
ease review. Scoped guards will be introduced separately.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/media/platform/renesas/vsp1/vsp1_dl.c | 49 ++++++-------------
 .../media/platform/renesas/vsp1/vsp1_histo.c  | 20 +++-----
 .../media/platform/renesas/vsp1/vsp1_pipe.c   |  9 +---
 .../media/platform/renesas/vsp1/vsp1_video.c  | 14 ++----
 .../media/platform/renesas/vsp1/vsp1_wpf.c    |  4 +-
 5 files changed, 31 insertions(+), 65 deletions(-)

diff --git a/drivers/media/platform/renesas/vsp1/vsp1_dl.c b/drivers/media/platform/renesas/vsp1/vsp1_dl.c
index 6c5578d9d2de..4a19ff1437b0 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_dl.c
@@ -336,9 +336,8 @@ void vsp1_dl_body_pool_destroy(struct vsp1_dl_body_pool *pool)
 struct vsp1_dl_body *vsp1_dl_body_get(struct vsp1_dl_body_pool *pool)
 {
 	struct vsp1_dl_body *dlb = NULL;
-	unsigned long flags;
 
-	spin_lock_irqsave(&pool->lock, flags);
+	guard(spinlock_irqsave)(&pool->lock);
 
 	if (!list_empty(&pool->free)) {
 		dlb = list_first_entry(&pool->free, struct vsp1_dl_body, free);
@@ -346,8 +345,6 @@ struct vsp1_dl_body *vsp1_dl_body_get(struct vsp1_dl_body_pool *pool)
 		refcount_set(&dlb->refcnt, 1);
 	}
 
-	spin_unlock_irqrestore(&pool->lock, flags);
-
 	return dlb;
 }
 
@@ -359,8 +356,6 @@ struct vsp1_dl_body *vsp1_dl_body_get(struct vsp1_dl_body_pool *pool)
  */
 void vsp1_dl_body_put(struct vsp1_dl_body *dlb)
 {
-	unsigned long flags;
-
 	if (!dlb)
 		return;
 
@@ -369,9 +364,9 @@ void vsp1_dl_body_put(struct vsp1_dl_body *dlb)
 
 	dlb->num_entries = 0;
 
-	spin_lock_irqsave(&dlb->pool->lock, flags);
+	guard(spinlock_irqsave)(&dlb->pool->lock);
+
 	list_add_tail(&dlb->free, &dlb->pool->free);
-	spin_unlock_irqrestore(&dlb->pool->lock, flags);
 }
 
 /**
@@ -493,9 +488,8 @@ static
 struct vsp1_dl_ext_cmd *vsp1_dl_ext_cmd_get(struct vsp1_dl_cmd_pool *pool)
 {
 	struct vsp1_dl_ext_cmd *cmd = NULL;
-	unsigned long flags;
 
-	spin_lock_irqsave(&pool->lock, flags);
+	guard(spinlock_irqsave)(&pool->lock);
 
 	if (!list_empty(&pool->free)) {
 		cmd = list_first_entry(&pool->free, struct vsp1_dl_ext_cmd,
@@ -503,24 +497,20 @@ struct vsp1_dl_ext_cmd *vsp1_dl_ext_cmd_get(struct vsp1_dl_cmd_pool *pool)
 		list_del(&cmd->free);
 	}
 
-	spin_unlock_irqrestore(&pool->lock, flags);
-
 	return cmd;
 }
 
 static void vsp1_dl_ext_cmd_put(struct vsp1_dl_ext_cmd *cmd)
 {
-	unsigned long flags;
-
 	if (!cmd)
 		return;
 
 	/* Reset flags, these mark data usage. */
 	cmd->flags = 0;
 
-	spin_lock_irqsave(&cmd->pool->lock, flags);
+	guard(spinlock_irqsave)(&cmd->pool->lock);
+
 	list_add_tail(&cmd->free, &cmd->pool->free);
-	spin_unlock_irqrestore(&cmd->pool->lock, flags);
 }
 
 static void vsp1_dl_ext_cmd_pool_destroy(struct vsp1_dl_cmd_pool *pool)
@@ -611,11 +601,10 @@ static void vsp1_dl_list_free(struct vsp1_dl_list *dl)
 struct vsp1_dl_list *vsp1_dl_list_get(struct vsp1_dl_manager *dlm)
 {
 	struct vsp1_dl_list *dl = NULL;
-	unsigned long flags;
 
 	lockdep_assert_not_held(&dlm->lock);
 
-	spin_lock_irqsave(&dlm->lock, flags);
+	guard(spinlock_irqsave)(&dlm->lock);
 
 	if (!list_empty(&dlm->free)) {
 		dl = list_first_entry(&dlm->free, struct vsp1_dl_list, list);
@@ -629,8 +618,6 @@ struct vsp1_dl_list *vsp1_dl_list_get(struct vsp1_dl_manager *dlm)
 		dl->allocated = true;
 	}
 
-	spin_unlock_irqrestore(&dlm->lock, flags);
-
 	return dl;
 }
 
@@ -690,14 +677,12 @@ static void __vsp1_dl_list_put(struct vsp1_dl_list *dl)
  */
 void vsp1_dl_list_put(struct vsp1_dl_list *dl)
 {
-	unsigned long flags;
-
 	if (!dl)
 		return;
 
-	spin_lock_irqsave(&dl->dlm->lock, flags);
+	guard(spinlock_irqsave)(&dl->dlm->lock);
+
 	__vsp1_dl_list_put(dl);
-	spin_unlock_irqrestore(&dl->dlm->lock, flags);
 }
 
 /**
@@ -937,7 +922,6 @@ void vsp1_dl_list_commit(struct vsp1_dl_list *dl, unsigned int dl_flags)
 {
 	struct vsp1_dl_manager *dlm = dl->dlm;
 	struct vsp1_dl_list *dl_next;
-	unsigned long flags;
 
 	/* Fill the header for the head and chained display lists. */
 	vsp1_dl_list_fill_header(dl, list_empty(&dl->chain));
@@ -950,14 +934,12 @@ void vsp1_dl_list_commit(struct vsp1_dl_list *dl, unsigned int dl_flags)
 
 	dl->flags = dl_flags & ~VSP1_DL_FRAME_END_COMPLETED;
 
-	spin_lock_irqsave(&dlm->lock, flags);
+	guard(spinlock_irqsave)(&dlm->lock);
 
 	if (dlm->singleshot)
 		vsp1_dl_list_commit_singleshot(dl);
 	else
 		vsp1_dl_list_commit_continuous(dl);
-
-	spin_unlock_irqrestore(&dlm->lock, flags);
 }
 
 /* -----------------------------------------------------------------------------
@@ -991,7 +973,7 @@ unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm)
 	u32 status = vsp1_read(vsp1, VI6_STATUS);
 	unsigned int flags = 0;
 
-	spin_lock(&dlm->lock);
+	guard(spinlock)(&dlm->lock);
 
 	/*
 	 * The mem-to-mem pipelines work in single-shot mode. No new display
@@ -1001,7 +983,7 @@ unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm)
 		__vsp1_dl_list_put(dlm->active);
 		dlm->active = NULL;
 		flags |= VSP1_DL_FRAME_END_COMPLETED;
-		goto done;
+		return flags;
 	}
 
 	/*
@@ -1011,7 +993,7 @@ unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm)
 	 * and retry.
 	 */
 	if (vsp1_dl_list_hw_update_pending(dlm))
-		goto done;
+		return flags;
 
 	/*
 	 * Progressive streams report only TOP fields. If we have a BOTTOM
@@ -1019,7 +1001,7 @@ unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm)
 	 * next frame end interrupt.
 	 */
 	if (status & VI6_STATUS_FLD_STD(dlm->index))
-		goto done;
+		return flags;
 
 	/*
 	 * If the active display list has the writeback flag set, the frame
@@ -1058,9 +1040,6 @@ unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm)
 		dlm->pending = NULL;
 	}
 
-done:
-	spin_unlock(&dlm->lock);
-
 	return flags;
 }
 
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_histo.c b/drivers/media/platform/renesas/vsp1/vsp1_histo.c
index 72f6ef2fdc4f..97dbfb93abe9 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_histo.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_histo.c
@@ -35,20 +35,18 @@ to_vsp1_histogram_buffer(struct vb2_v4l2_buffer *vbuf)
 struct vsp1_histogram_buffer *
 vsp1_histogram_buffer_get(struct vsp1_histogram *histo)
 {
-	struct vsp1_histogram_buffer *buf = NULL;
+	struct vsp1_histogram_buffer *buf;
 
-	spin_lock(&histo->irqlock);
+	guard(spinlock)(&histo->irqlock);
 
 	if (list_empty(&histo->irqqueue))
-		goto done;
+		return NULL;
 
 	buf = list_first_entry(&histo->irqqueue, struct vsp1_histogram_buffer,
 			       queue);
 	list_del(&buf->queue);
 	histo->readout = true;
 
-done:
-	spin_unlock(&histo->irqlock);
 	return buf;
 }
 
@@ -68,10 +66,10 @@ void vsp1_histogram_buffer_complete(struct vsp1_histogram *histo,
 	vb2_set_plane_payload(&buf->buf.vb2_buf, 0, size);
 	vb2_buffer_done(&buf->buf.vb2_buf, VB2_BUF_STATE_DONE);
 
-	spin_lock(&histo->irqlock);
+	guard(spinlock)(&histo->irqlock);
+
 	histo->readout = false;
 	wake_up(&histo->wait_queue);
-	spin_unlock(&histo->irqlock);
 }
 
 /* -----------------------------------------------------------------------------
@@ -123,9 +121,9 @@ static void histo_buffer_queue(struct vb2_buffer *vb)
 	struct vsp1_histogram *histo = vb2_get_drv_priv(vb->vb2_queue);
 	struct vsp1_histogram_buffer *buf = to_vsp1_histogram_buffer(vbuf);
 
-	spin_lock_irq(&histo->irqlock);
+	guard(spinlock_irq)(&histo->irqlock);
+
 	list_add_tail(&buf->queue, &histo->irqqueue);
-	spin_unlock_irq(&histo->irqlock);
 }
 
 static int histo_start_streaming(struct vb2_queue *vq, unsigned int count)
@@ -138,7 +136,7 @@ static void histo_stop_streaming(struct vb2_queue *vq)
 	struct vsp1_histogram *histo = vb2_get_drv_priv(vq);
 	struct vsp1_histogram_buffer *buffer;
 
-	spin_lock_irq(&histo->irqlock);
+	guard(spinlock_irq)(&histo->irqlock);
 
 	/* Remove all buffers from the IRQ queue. */
 	list_for_each_entry(buffer, &histo->irqqueue, queue)
@@ -147,8 +145,6 @@ static void histo_stop_streaming(struct vb2_queue *vq)
 
 	/* Wait for the buffer being read out (if any) to complete. */
 	wait_event_lock_irq(histo->wait_queue, !histo->readout, histo->irqlock);
-
-	spin_unlock_irq(&histo->irqlock);
 }
 
 static const struct vb2_ops histo_video_queue_qops = {
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
index aaec1aa15091..924e87f91903 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
@@ -487,14 +487,9 @@ void vsp1_pipeline_run(struct vsp1_pipeline *pipe)
 
 bool vsp1_pipeline_stopped(struct vsp1_pipeline *pipe)
 {
-	unsigned long flags;
-	bool stopped;
+	guard(spinlock_irqsave)(&pipe->irqlock);
 
-	spin_lock_irqsave(&pipe->irqlock, flags);
-	stopped = pipe->state == VSP1_PIPELINE_STOPPED;
-	spin_unlock_irqrestore(&pipe->irqlock, flags);
-
-	return stopped;
+	return pipe->state == VSP1_PIPELINE_STOPPED;
 }
 
 int vsp1_pipeline_stop(struct vsp1_pipeline *pipe)
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c
index 138d4e08eee9..1e5d9e42cea0 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_video.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c
@@ -667,7 +667,7 @@ static void vsp1_video_buffer_queue(struct vb2_buffer *vb)
 	if (!empty)
 		return;
 
-	spin_lock_irqsave(&pipe->irqlock, flags);
+	guard(spinlock_irqsave)(&pipe->irqlock);
 
 	video->rwpf->mem = buf->mem;
 	pipe->buffers_ready |= 1 << video->pipe_index;
@@ -675,8 +675,6 @@ static void vsp1_video_buffer_queue(struct vb2_buffer *vb)
 	if (vb2_start_streaming_called(&video->queue) &&
 	    vsp1_pipeline_ready(pipe))
 		vsp1_video_pipeline_run(pipe);
-
-	spin_unlock_irqrestore(&pipe->irqlock, flags);
 }
 
 static int vsp1_video_pipeline_setup_partitions(struct vsp1_pipeline *pipe)
@@ -778,14 +776,13 @@ static int vsp1_video_setup_pipeline(struct vsp1_pipeline *pipe)
 static void vsp1_video_release_buffers(struct vsp1_video *video)
 {
 	struct vsp1_vb2_buffer *buffer;
-	unsigned long flags;
 
 	/* Remove all buffers from the IRQ queue. */
-	spin_lock_irqsave(&video->irqlock, flags);
+	guard(spinlock_irqsave)(&video->irqlock);
+
 	list_for_each_entry(buffer, &video->irqqueue, queue)
 		vb2_buffer_done(&buffer->buf.vb2_buf, VB2_BUF_STATE_ERROR);
 	INIT_LIST_HEAD(&video->irqqueue);
-	spin_unlock_irqrestore(&video->irqlock, flags);
 }
 
 static void vsp1_video_cleanup_pipeline(struct vsp1_pipeline *pipe)
@@ -807,7 +804,6 @@ static int vsp1_video_start_streaming(struct vb2_queue *vq, unsigned int count)
 	struct vsp1_video *video = vb2_get_drv_priv(vq);
 	struct vsp1_pipeline *pipe = video->rwpf->entity.pipe;
 	bool start_pipeline = false;
-	unsigned long flags;
 	int ret;
 
 	scoped_guard(mutex, &pipe->lock) {
@@ -835,10 +831,10 @@ static int vsp1_video_start_streaming(struct vb2_queue *vq, unsigned int count)
 	if (!start_pipeline)
 		return 0;
 
-	spin_lock_irqsave(&pipe->irqlock, flags);
+	guard(spinlock_irqsave)(&pipe->irqlock);
+
 	if (vsp1_pipeline_ready(pipe))
 		vsp1_video_pipeline_run(pipe);
-	spin_unlock_irqrestore(&pipe->irqlock, flags);
 
 	return 0;
 }
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
index e7ed3c8e9e90..327c7457126f 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
@@ -111,9 +111,9 @@ static int vsp1_wpf_s_ctrl(struct v4l2_ctrl *ctrl)
 	if (rotation == 180 || rotation == 270)
 		flip ^= BIT(WPF_CTRL_VFLIP) | BIT(WPF_CTRL_HFLIP);
 
-	spin_lock_irq(&wpf->flip.lock);
+	guard(spinlock_irq)(&wpf->flip.lock);
+
 	wpf->flip.pending = flip;
-	spin_unlock_irq(&wpf->flip.lock);
 
 	return 0;
 }
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 08/11] media: renesas: vsp1: Use spinlock scoped guards
  2026-05-11 23:56 [PATCH 00/11] media: renesas: vsp1: Modernize the driver Laurent Pinchart
                   ` (6 preceding siblings ...)
  2026-05-11 23:56 ` [PATCH 07/11] media: renesas: vsp1: Use spinlock guards Laurent Pinchart
@ 2026-05-11 23:56 ` Laurent Pinchart
  2026-05-13 19:37   ` Niklas Söderlund
  2026-05-11 23:56 ` [PATCH 09/11] media: renesas: vsp1: Simplify iteration over format arrays Laurent Pinchart
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Laurent Pinchart @ 2026-05-11 23:56 UTC (permalink / raw)
  To: linux-media, dri-devel
  Cc: linux-renesas-soc, Tomi Valkeinen, Kieran Bingham, Biju Das,
	David Airlie, Simona Vetter

Replace remaining manual spinlock locking and unlocking with scoped
guards. This simplifies error paths and reduces the amount of code.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 .../media/platform/renesas/vsp1/vsp1_clu.c    | 15 +++--
 drivers/media/platform/renesas/vsp1/vsp1_dl.c | 14 ++---
 .../media/platform/renesas/vsp1/vsp1_drm.c    |  7 +--
 .../media/platform/renesas/vsp1/vsp1_lut.c    | 15 +++--
 .../media/platform/renesas/vsp1/vsp1_pipe.c   | 15 +++--
 .../media/platform/renesas/vsp1/vsp1_video.c  | 59 ++++++++-----------
 .../media/platform/renesas/vsp1/vsp1_wpf.c    |  9 ++-
 7 files changed, 59 insertions(+), 75 deletions(-)

diff --git a/drivers/media/platform/renesas/vsp1/vsp1_clu.c b/drivers/media/platform/renesas/vsp1/vsp1_clu.c
index 04c466c4da81..a6e4bcab5101 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_clu.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_clu.c
@@ -53,9 +53,9 @@ static int clu_set_table(struct vsp1_clu *clu, struct v4l2_ctrl *ctrl)
 	for (i = 0; i < CLU_SIZE; ++i)
 		vsp1_dl_body_write(dlb, VI6_CLU_DATA, ctrl->p_new.p_u32[i]);
 
-	spin_lock_irq(&clu->lock);
-	swap(clu->clu, dlb);
-	spin_unlock_irq(&clu->lock);
+	scoped_guard(spinlock_irq, &clu->lock) {
+		swap(clu->clu, dlb);
+	}
 
 	vsp1_dl_body_put(dlb);
 	return 0;
@@ -162,7 +162,6 @@ static void clu_configure_frame(struct vsp1_entity *entity,
 {
 	struct vsp1_clu *clu = to_clu(&entity->subdev);
 	struct vsp1_dl_body *clu_dlb;
-	unsigned long flags;
 	u32 ctrl = VI6_CLU_CTRL_AAI | VI6_CLU_CTRL_MVS | VI6_CLU_CTRL_EN;
 
 	/* 2D mode can only be used with the YCbCr pixel encoding. */
@@ -173,10 +172,10 @@ static void clu_configure_frame(struct vsp1_entity *entity,
 
 	vsp1_clu_write(clu, dlb, VI6_CLU_CTRL, ctrl);
 
-	spin_lock_irqsave(&clu->lock, flags);
-	clu_dlb = clu->clu;
-	clu->clu = NULL;
-	spin_unlock_irqrestore(&clu->lock, flags);
+	scoped_guard(spinlock_irqsave, &clu->lock) {
+		clu_dlb = clu->clu;
+		clu->clu = NULL;
+	}
 
 	if (clu_dlb) {
 		vsp1_dl_list_add_body(dl, clu_dlb);
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_dl.c b/drivers/media/platform/renesas/vsp1/vsp1_dl.c
index 4a19ff1437b0..3dc74fed91dc 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_dl.c
@@ -1064,17 +1064,15 @@ void vsp1_dlm_setup(struct vsp1_device *vsp1)
 
 void vsp1_dlm_reset(struct vsp1_dl_manager *dlm)
 {
-	unsigned long flags;
 	size_t list_count;
 
-	spin_lock_irqsave(&dlm->lock, flags);
+	scoped_guard(spinlock_irqsave, &dlm->lock) {
+		__vsp1_dl_list_put(dlm->active);
+		__vsp1_dl_list_put(dlm->queued);
+		__vsp1_dl_list_put(dlm->pending);
 
-	__vsp1_dl_list_put(dlm->active);
-	__vsp1_dl_list_put(dlm->queued);
-	__vsp1_dl_list_put(dlm->pending);
-
-	list_count = list_count_nodes(&dlm->free);
-	spin_unlock_irqrestore(&dlm->lock, flags);
+		list_count = list_count_nodes(&dlm->free);
+	}
 
 	WARN_ON_ONCE(list_count != dlm->list_count);
 
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drm.c b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
index 2b64d9b5a81c..f6fbd3475329 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_drm.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
@@ -655,7 +655,6 @@ int vsp1_du_enable(struct device *dev, unsigned int pipe_index,
 	struct vsp1_device *vsp1 = dev_get_drvdata(dev);
 	struct vsp1_drm_pipeline *drm_pipe;
 	struct vsp1_pipeline *pipe;
-	unsigned long flags;
 	int ret;
 
 	if (pipe_index >= vsp1->info->lif_count)
@@ -708,9 +707,9 @@ int vsp1_du_enable(struct device *dev, unsigned int pipe_index,
 	}
 
 	/* Start the pipeline. */
-	spin_lock_irqsave(&pipe->irqlock, flags);
-	vsp1_pipeline_run(pipe);
-	spin_unlock_irqrestore(&pipe->irqlock, flags);
+	scoped_guard(spinlock_irqsave, &pipe->irqlock) {
+		vsp1_pipeline_run(pipe);
+	}
 
 	dev_dbg(vsp1->dev, "%s: pipeline enabled\n", __func__);
 
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_lut.c b/drivers/media/platform/renesas/vsp1/vsp1_lut.c
index 94bdedcc5c92..a22c31e17cb7 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_lut.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_lut.c
@@ -50,9 +50,9 @@ static int lut_set_table(struct vsp1_lut *lut, struct v4l2_ctrl *ctrl)
 		vsp1_dl_body_write(dlb, VI6_LUT_TABLE + 4 * i,
 				       ctrl->p_new.p_u32[i]);
 
-	spin_lock_irq(&lut->lock);
-	swap(lut->lut, dlb);
-	spin_unlock_irq(&lut->lock);
+	scoped_guard(spinlock_irq, &lut->lock) {
+		swap(lut->lut, dlb);
+	}
 
 	vsp1_dl_body_put(dlb);
 	return 0;
@@ -132,12 +132,11 @@ static void lut_configure_frame(struct vsp1_entity *entity,
 {
 	struct vsp1_lut *lut = to_lut(&entity->subdev);
 	struct vsp1_dl_body *lut_dlb;
-	unsigned long flags;
 
-	spin_lock_irqsave(&lut->lock, flags);
-	lut_dlb = lut->lut;
-	lut->lut = NULL;
-	spin_unlock_irqrestore(&lut->lock, flags);
+	scoped_guard(spinlock_irqsave, &lut->lock) {
+		lut_dlb = lut->lut;
+		lut->lut = NULL;
+	}
 
 	if (lut_dlb) {
 		vsp1_dl_list_add_body(dl, lut_dlb);
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
index 924e87f91903..f9c7c75a7ad0 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
@@ -496,7 +496,6 @@ int vsp1_pipeline_stop(struct vsp1_pipeline *pipe)
 {
 	struct vsp1_device *vsp1 = pipe->output->entity.vsp1;
 	struct vsp1_entity *entity;
-	unsigned long flags;
 	int ret;
 
 	if (pipe->lif) {
@@ -510,16 +509,16 @@ int vsp1_pipeline_stop(struct vsp1_pipeline *pipe)
 
 		ret = vsp1_reset_wpf(vsp1, pipe->output->entity.index);
 		if (ret == 0) {
-			spin_lock_irqsave(&pipe->irqlock, flags);
-			pipe->state = VSP1_PIPELINE_STOPPED;
-			spin_unlock_irqrestore(&pipe->irqlock, flags);
+			scoped_guard(spinlock_irqsave, &pipe->irqlock) {
+				pipe->state = VSP1_PIPELINE_STOPPED;
+			}
 		}
 	} else {
 		/* Otherwise just request a stop and wait. */
-		spin_lock_irqsave(&pipe->irqlock, flags);
-		if (pipe->state == VSP1_PIPELINE_RUNNING)
-			pipe->state = VSP1_PIPELINE_STOPPING;
-		spin_unlock_irqrestore(&pipe->irqlock, flags);
+		scoped_guard(spinlock_irqsave, &pipe->irqlock) {
+			if (pipe->state == VSP1_PIPELINE_RUNNING)
+				pipe->state = VSP1_PIPELINE_STOPPING;
+		}
 
 		ret = wait_event_timeout(pipe->wq, vsp1_pipeline_stopped(pipe),
 					 msecs_to_jiffies(500));
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c
index 1e5d9e42cea0..b0eae54273a0 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_video.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c
@@ -209,26 +209,21 @@ vsp1_video_complete_buffer(struct vsp1_video *video)
 	struct vsp1_pipeline *pipe = video->rwpf->entity.pipe;
 	struct vsp1_vb2_buffer *next = NULL;
 	struct vsp1_vb2_buffer *done;
-	unsigned long flags;
 	unsigned int i;
 
-	spin_lock_irqsave(&video->irqlock, flags);
+	scoped_guard(spinlock_irqsave, &video->irqlock) {
+		if (list_empty(&video->irqqueue))
+			return NULL;
 
-	if (list_empty(&video->irqqueue)) {
-		spin_unlock_irqrestore(&video->irqlock, flags);
-		return NULL;
-	}
-
-	done = list_first_entry(&video->irqqueue,
-				struct vsp1_vb2_buffer, queue);
-
-	list_del(&done->queue);
-
-	if (!list_empty(&video->irqqueue))
-		next = list_first_entry(&video->irqqueue,
+		done = list_first_entry(&video->irqqueue,
 					struct vsp1_vb2_buffer, queue);
 
-	spin_unlock_irqrestore(&video->irqlock, flags);
+		list_del(&done->queue);
+
+		if (!list_empty(&video->irqqueue))
+			next = list_first_entry(&video->irqqueue,
+						struct vsp1_vb2_buffer, queue);
+	}
 
 	done->buf.sequence = pipe->sequence;
 	done->buf.vb2_buf.timestamp = ktime_get_ns();
@@ -656,13 +651,12 @@ static void vsp1_video_buffer_queue(struct vb2_buffer *vb)
 	struct vsp1_video *video = vb2_get_drv_priv(vb->vb2_queue);
 	struct vsp1_pipeline *pipe = video->rwpf->entity.pipe;
 	struct vsp1_vb2_buffer *buf = to_vsp1_vb2_buffer(vbuf);
-	unsigned long flags;
 	bool empty;
 
-	spin_lock_irqsave(&video->irqlock, flags);
-	empty = list_empty(&video->irqqueue);
-	list_add_tail(&buf->queue, &video->irqqueue);
-	spin_unlock_irqrestore(&video->irqlock, flags);
+	scoped_guard(spinlock_irqsave, &video->irqlock) {
+		empty = list_empty(&video->irqqueue);
+		list_add_tail(&buf->queue, &video->irqqueue);
+	}
 
 	if (!empty)
 		return;
@@ -843,16 +837,15 @@ static void vsp1_video_stop_streaming(struct vb2_queue *vq)
 {
 	struct vsp1_video *video = vb2_get_drv_priv(vq);
 	struct vsp1_pipeline *pipe = video->rwpf->entity.pipe;
-	unsigned long flags;
 	int ret;
 
 	/*
 	 * Clear the buffers ready flag to make sure the device won't be started
 	 * by a QBUF on the video node on the other side of the pipeline.
 	 */
-	spin_lock_irqsave(&video->irqlock, flags);
-	pipe->buffers_ready &= ~(1 << video->pipe_index);
-	spin_unlock_irqrestore(&video->irqlock, flags);
+	scoped_guard(spinlock_irqsave, &video->irqlock) {
+		pipe->buffers_ready &= ~(1 << video->pipe_index);
+	}
 
 	scoped_guard(mutex, &pipe->lock) {
 		if (--pipe->stream_count == pipe->num_inputs) {
@@ -1118,7 +1111,6 @@ static const struct media_entity_operations vsp1_video_media_ops = {
 
 void vsp1_video_suspend(struct vsp1_device *vsp1)
 {
-	unsigned long flags;
 	unsigned int i;
 	int ret;
 
@@ -1138,10 +1130,10 @@ void vsp1_video_suspend(struct vsp1_device *vsp1)
 		if (pipe == NULL)
 			continue;
 
-		spin_lock_irqsave(&pipe->irqlock, flags);
-		if (pipe->state == VSP1_PIPELINE_RUNNING)
-			pipe->state = VSP1_PIPELINE_STOPPING;
-		spin_unlock_irqrestore(&pipe->irqlock, flags);
+		scoped_guard(spinlock_irqsave, &pipe->irqlock) {
+			if (pipe->state == VSP1_PIPELINE_RUNNING)
+				pipe->state = VSP1_PIPELINE_STOPPING;
+		}
 	}
 
 	for (i = 0; i < vsp1->info->wpf_count; ++i) {
@@ -1165,7 +1157,6 @@ void vsp1_video_suspend(struct vsp1_device *vsp1)
 
 void vsp1_video_resume(struct vsp1_device *vsp1)
 {
-	unsigned long flags;
 	unsigned int i;
 
 	/* Resume all running pipelines. */
@@ -1186,10 +1177,10 @@ void vsp1_video_resume(struct vsp1_device *vsp1)
 		 */
 		pipe->configured = false;
 
-		spin_lock_irqsave(&pipe->irqlock, flags);
-		if (vsp1_pipeline_ready(pipe))
-			vsp1_video_pipeline_run(pipe);
-		spin_unlock_irqrestore(&pipe->irqlock, flags);
+		scoped_guard(spinlock_irqsave, &pipe->irqlock) {
+			if (vsp1_pipeline_ready(pipe))
+				vsp1_video_pipeline_run(pipe);
+		}
 	}
 }
 
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
index 327c7457126f..0ec707d2913f 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
@@ -366,13 +366,12 @@ static void wpf_configure_frame(struct vsp1_entity *entity,
 	const unsigned int mask = BIT(WPF_CTRL_VFLIP)
 				| BIT(WPF_CTRL_HFLIP);
 	struct vsp1_rwpf *wpf = to_rwpf(&entity->subdev);
-	unsigned long flags;
 	u32 outfmt;
 
-	spin_lock_irqsave(&wpf->flip.lock, flags);
-	wpf->flip.active = (wpf->flip.active & ~mask)
-			 | (wpf->flip.pending & mask);
-	spin_unlock_irqrestore(&wpf->flip.lock, flags);
+	scoped_guard(spinlock_irqsave, &wpf->flip.lock) {
+		wpf->flip.active = (wpf->flip.active & ~mask)
+				 | (wpf->flip.pending & mask);
+	}
 
 	outfmt = (wpf->alpha << VI6_WPF_OUTFMT_PDV_SHIFT) | wpf->outfmt;
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 09/11] media: renesas: vsp1: Simplify iteration over format arrays
  2026-05-11 23:56 [PATCH 00/11] media: renesas: vsp1: Modernize the driver Laurent Pinchart
                   ` (7 preceding siblings ...)
  2026-05-11 23:56 ` [PATCH 08/11] media: renesas: vsp1: Use spinlock scoped guards Laurent Pinchart
@ 2026-05-11 23:56 ` Laurent Pinchart
  2026-05-13 19:44   ` Niklas Söderlund
  2026-05-11 23:56 ` [PATCH 10/11] media: renesas: vsp1: Declare index variables in for loop statement Laurent Pinchart
  2026-05-11 23:56 ` [PATCH 11/11] media: renesas: vsp1: Drop deprecated vsp1_du_setup_lif() function Laurent Pinchart
  10 siblings, 1 reply; 24+ messages in thread
From: Laurent Pinchart @ 2026-05-11 23:56 UTC (permalink / raw)
  To: linux-media, dri-devel
  Cc: linux-renesas-soc, Tomi Valkeinen, Kieran Bingham, Biju Das,
	David Airlie, Simona Vetter

Introduce a vsp1_for_each_format() macro to iterate over format arrays,
to improve readability. No functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 .../media/platform/renesas/vsp1/vsp1_pipe.c   | 36 ++++++-------------
 1 file changed, 10 insertions(+), 26 deletions(-)

diff --git a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
index f9c7c75a7ad0..7197f2917417 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
@@ -229,6 +229,10 @@ static const struct vsp1_format_info vsp1_video_hsit_formats[] = {
 	  1, { 32, 0, 0 }, false, false, 1, 1, false },
 };
 
+#define vsp1_for_each_format(info, formats) \
+	for (const struct vsp1_format_info *info = &formats[0]; \
+	     info < formats + ARRAY_SIZE(formats); ++info)
+
 /**
  * vsp1_get_format_info - Retrieve format information for a 4CC
  * @vsp1: the VSP1 device
@@ -240,30 +244,20 @@ static const struct vsp1_format_info vsp1_video_hsit_formats[] = {
 const struct vsp1_format_info *vsp1_get_format_info(struct vsp1_device *vsp1,
 						    u32 fourcc)
 {
-	unsigned int i;
-
-	for (i = 0; i < ARRAY_SIZE(vsp1_video_formats); ++i) {
-		const struct vsp1_format_info *info = &vsp1_video_formats[i];
-
+	vsp1_for_each_format(info, vsp1_video_formats) {
 		if (info->fourcc == fourcc)
 			return info;
 	}
 
 	if (vsp1->info->gen == 2) {
-		for (i = 0; i < ARRAY_SIZE(vsp1_video_gen2_formats); ++i) {
-			const struct vsp1_format_info *info =
-				&vsp1_video_gen2_formats[i];
-
+		vsp1_for_each_format(info, vsp1_video_gen2_formats) {
 			if (info->fourcc == fourcc)
 				return info;
 		}
 	}
 
 	if (vsp1_feature(vsp1, VSP1_HAS_HSIT)) {
-		for (i = 0; i < ARRAY_SIZE(vsp1_video_hsit_formats); ++i) {
-			const struct vsp1_format_info *info =
-				&vsp1_video_hsit_formats[i];
-
+		vsp1_for_each_format(info, vsp1_video_hsit_formats) {
 			if (info->fourcc == fourcc)
 				return info;
 		}
@@ -287,8 +281,6 @@ const struct vsp1_format_info *
 vsp1_get_format_info_by_index(struct vsp1_device *vsp1, unsigned int index,
 			      u32 code)
 {
-	unsigned int i;
-
 	if (!code) {
 		if (index < ARRAY_SIZE(vsp1_video_formats))
 			return &vsp1_video_formats[index];
@@ -308,9 +300,7 @@ vsp1_get_format_info_by_index(struct vsp1_device *vsp1, unsigned int index,
 		return NULL;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(vsp1_video_formats); ++i) {
-		const struct vsp1_format_info *info = &vsp1_video_formats[i];
-
+	vsp1_for_each_format(info, vsp1_video_formats) {
 		if (info->mbus == code) {
 			if (!index)
 				return info;
@@ -319,10 +309,7 @@ vsp1_get_format_info_by_index(struct vsp1_device *vsp1, unsigned int index,
 	}
 
 	if (vsp1->info->gen == 2) {
-		for (i = 0; i < ARRAY_SIZE(vsp1_video_gen2_formats); ++i) {
-			const struct vsp1_format_info *info =
-				&vsp1_video_gen2_formats[i];
-
+		vsp1_for_each_format(info, vsp1_video_gen2_formats) {
 			if (info->mbus == code) {
 				if (!index)
 					return info;
@@ -332,10 +319,7 @@ vsp1_get_format_info_by_index(struct vsp1_device *vsp1, unsigned int index,
 	}
 
 	if (vsp1_feature(vsp1, VSP1_HAS_HSIT)) {
-		for (i = 0; i < ARRAY_SIZE(vsp1_video_hsit_formats); ++i) {
-			const struct vsp1_format_info *info =
-				&vsp1_video_hsit_formats[i];
-
+		vsp1_for_each_format(info, vsp1_video_hsit_formats) {
 			if (info->mbus == code) {
 				if (!index)
 					return info;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 10/11] media: renesas: vsp1: Declare index variables in for loop statement
  2026-05-11 23:56 [PATCH 00/11] media: renesas: vsp1: Modernize the driver Laurent Pinchart
                   ` (8 preceding siblings ...)
  2026-05-11 23:56 ` [PATCH 09/11] media: renesas: vsp1: Simplify iteration over format arrays Laurent Pinchart
@ 2026-05-11 23:56 ` Laurent Pinchart
  2026-05-13 20:29   ` Niklas Söderlund
  2026-05-11 23:56 ` [PATCH 11/11] media: renesas: vsp1: Drop deprecated vsp1_du_setup_lif() function Laurent Pinchart
  10 siblings, 1 reply; 24+ messages in thread
From: Laurent Pinchart @ 2026-05-11 23:56 UTC (permalink / raw)
  To: linux-media, dri-devel
  Cc: linux-renesas-soc, Tomi Valkeinen, Kieran Bingham, Biju Das,
	David Airlie, Simona Vetter

Using loop indices outside of the loop is a source of out-of-bounds
accesses and other bugs. It is important to carefully review those
usages. To make them stand out, declare all loop index variables that
are not used outside of the loop inside the loop statement.

No functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 .../media/platform/renesas/vsp1/vsp1_brx.c    |  7 +---
 .../media/platform/renesas/vsp1/vsp1_clu.c    |  3 +-
 drivers/media/platform/renesas/vsp1/vsp1_dl.c | 12 ++----
 .../media/platform/renesas/vsp1/vsp1_drm.c    | 14 +++----
 .../media/platform/renesas/vsp1/vsp1_drv.c    | 42 ++++++++-----------
 .../media/platform/renesas/vsp1/vsp1_entity.c |  4 +-
 .../media/platform/renesas/vsp1/vsp1_hgo.c    |  7 ++--
 .../media/platform/renesas/vsp1/vsp1_hgt.c    | 13 +++---
 .../media/platform/renesas/vsp1/vsp1_lut.c    |  3 +-
 .../media/platform/renesas/vsp1/vsp1_pipe.c   |  5 +--
 .../media/platform/renesas/vsp1/vsp1_video.c  | 34 ++++++---------
 .../media/platform/renesas/vsp1/vsp1_wpf.c    |  8 ++--
 12 files changed, 56 insertions(+), 96 deletions(-)

diff --git a/drivers/media/platform/renesas/vsp1/vsp1_brx.c b/drivers/media/platform/renesas/vsp1/vsp1_brx.c
index 325be30836d7..360a42502947 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_brx.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_brx.c
@@ -155,9 +155,7 @@ static int brx_set_format(struct v4l2_subdev *subdev,
 
 	/* Propagate the format code to all pads. */
 	if (fmt->pad == BRX_PAD_SINK(0)) {
-		unsigned int i;
-
-		for (i = 0; i <= brx->entity.source_pad; ++i) {
+		for (unsigned int i = 0; i <= brx->entity.source_pad; ++i) {
 			format = v4l2_subdev_state_get_format(state, i);
 			format->code = fmt->format.code;
 		}
@@ -271,7 +269,6 @@ static void brx_configure_stream(struct vsp1_entity *entity,
 	struct vsp1_brx *brx = to_brx(&entity->subdev);
 	struct v4l2_mbus_framefmt *format;
 	unsigned int flags;
-	unsigned int i;
 
 	format = v4l2_subdev_state_get_format(state, brx->entity.source_pad);
 
@@ -315,7 +312,7 @@ static void brx_configure_stream(struct vsp1_entity *entity,
 			       VI6_BRU_ROP_CROP(VI6_ROP_NOP) |
 			       VI6_BRU_ROP_AROP(VI6_ROP_NOP));
 
-	for (i = 0; i < brx->entity.source_pad; ++i) {
+	for (unsigned int i = 0; i < brx->entity.source_pad; ++i) {
 		bool premultiplied = false;
 		u32 ctrl = 0;
 
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_clu.c b/drivers/media/platform/renesas/vsp1/vsp1_clu.c
index a6e4bcab5101..4b7d07d730da 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_clu.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_clu.c
@@ -43,14 +43,13 @@ static inline void vsp1_clu_write(struct vsp1_clu *clu,
 static int clu_set_table(struct vsp1_clu *clu, struct v4l2_ctrl *ctrl)
 {
 	struct vsp1_dl_body *dlb;
-	unsigned int i;
 
 	dlb = vsp1_dl_body_get(clu->pool);
 	if (!dlb)
 		return -ENOMEM;
 
 	vsp1_dl_body_write(dlb, VI6_CLU_ADDR, 0);
-	for (i = 0; i < CLU_SIZE; ++i)
+	for (unsigned int i = 0; i < CLU_SIZE; ++i)
 		vsp1_dl_body_write(dlb, VI6_CLU_DATA, ctrl->p_new.p_u32[i]);
 
 	scoped_guard(spinlock_irq, &clu->lock) {
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_dl.c b/drivers/media/platform/renesas/vsp1/vsp1_dl.c
index 3dc74fed91dc..6430f2ec8b32 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_dl.c
@@ -257,7 +257,6 @@ vsp1_dl_body_pool_create(struct vsp1_device *vsp1, unsigned int num_bodies,
 {
 	struct vsp1_dl_body_pool *pool;
 	size_t dlb_size;
-	unsigned int i;
 
 	pool = kzalloc_obj(*pool);
 	if (!pool)
@@ -291,7 +290,7 @@ vsp1_dl_body_pool_create(struct vsp1_device *vsp1, unsigned int num_bodies,
 	spin_lock_init(&pool->lock);
 	INIT_LIST_HEAD(&pool->free);
 
-	for (i = 0; i < num_bodies; ++i) {
+	for (unsigned int i = 0; i < num_bodies; ++i) {
 		struct vsp1_dl_body *dlb = &pool->bodies[i];
 
 		dlb->pool = pool;
@@ -426,7 +425,6 @@ vsp1_dl_cmd_pool_create(struct vsp1_device *vsp1, enum vsp1_extcmd_type type,
 			unsigned int num_cmds)
 {
 	struct vsp1_dl_cmd_pool *pool;
-	unsigned int i;
 	size_t cmd_size;
 
 	pool = kzalloc_obj(*pool);
@@ -457,7 +455,7 @@ vsp1_dl_cmd_pool_create(struct vsp1_device *vsp1, enum vsp1_extcmd_type type,
 		return NULL;
 	}
 
-	for (i = 0; i < num_cmds; ++i) {
+	for (unsigned int i = 0; i < num_cmds; ++i) {
 		struct vsp1_dl_ext_cmd *cmd = &pool->cmds[i];
 		size_t cmd_offset = i * cmd_size;
 		/* data_offset must be 16 byte aligned for DMA. */
@@ -1046,7 +1044,6 @@ unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm)
 /* Hardware Setup */
 void vsp1_dlm_setup(struct vsp1_device *vsp1)
 {
-	unsigned int i;
 	u32 ctrl = (256 << VI6_DL_CTRL_AR_WAIT_SHIFT)
 		 | VI6_DL_CTRL_DC2 | VI6_DL_CTRL_DC1 | VI6_DL_CTRL_DC0
 		 | VI6_DL_CTRL_DLE;
@@ -1054,7 +1051,7 @@ void vsp1_dlm_setup(struct vsp1_device *vsp1)
 		   | VI6_DL_EXT_CTRL_DLPRI | VI6_DL_EXT_CTRL_EXT;
 
 	if (vsp1_feature(vsp1, VSP1_HAS_EXT_DL)) {
-		for (i = 0; i < vsp1->info->wpf_count; ++i)
+		for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i)
 			vsp1_write(vsp1, VI6_DL_EXT_CTRL(i), ext_dl);
 	}
 
@@ -1092,7 +1089,6 @@ struct vsp1_dl_manager *vsp1_dlm_create(struct vsp1_device *vsp1,
 {
 	struct vsp1_dl_manager *dlm;
 	size_t header_size;
-	unsigned int i;
 
 	dlm = devm_kzalloc(vsp1->dev, sizeof(*dlm), GFP_KERNEL);
 	if (!dlm)
@@ -1128,7 +1124,7 @@ struct vsp1_dl_manager *vsp1_dlm_create(struct vsp1_device *vsp1,
 	if (!dlm->pool)
 		return NULL;
 
-	for (i = 0; i < prealloc; ++i) {
+	for (unsigned int i = 0; i < prealloc; ++i) {
 		struct vsp1_dl_list *dl;
 
 		dl = vsp1_dl_list_alloc(dlm);
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drm.c b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
index f6fbd3475329..9cd5c025d2be 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_drm.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
@@ -419,13 +419,12 @@ static int vsp1_du_pipeline_setup_inputs(struct vsp1_device *vsp1,
 	struct vsp1_entity *uif;
 	bool use_uif = false;
 	struct vsp1_brx *brx;
-	unsigned int i;
 	int ret;
 
 	/* Count the number of enabled inputs and sort them by Z-order. */
 	pipe->num_inputs = 0;
 
-	for (i = 0; i < vsp1->info->rpf_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->rpf_count; ++i) {
 		struct vsp1_rwpf *rpf = vsp1->rpf[i];
 		unsigned int j;
 
@@ -457,7 +456,7 @@ static int vsp1_du_pipeline_setup_inputs(struct vsp1_device *vsp1,
 	brx = to_brx(&pipe->brx->subdev);
 
 	/* Setup the RPF input pipeline for every enabled input. */
-	for (i = 0; i < pipe->brx->source_pad; ++i) {
+	for (unsigned int i = 0; i < pipe->brx->source_pad; ++i) {
 		struct vsp1_rwpf *rpf = inputs[i];
 
 		if (!rpf) {
@@ -732,7 +731,6 @@ int vsp1_du_disable(struct device *dev, unsigned int pipe_index)
 	struct vsp1_device *vsp1 = dev_get_drvdata(dev);
 	struct vsp1_drm_pipeline *drm_pipe;
 	struct vsp1_pipeline *pipe;
-	unsigned int i;
 	int ret;
 
 	if (pipe_index >= vsp1->info->lif_count)
@@ -748,7 +746,7 @@ int vsp1_du_disable(struct device *dev, unsigned int pipe_index)
 		if (ret == -ETIMEDOUT)
 			dev_err(vsp1->dev, "DRM pipeline stop timeout\n");
 
-		for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) {
+		for (unsigned int i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) {
 			struct vsp1_rwpf *rpf = pipe->inputs[i];
 
 			if (!rpf)
@@ -964,8 +962,6 @@ EXPORT_SYMBOL_GPL(vsp1_du_unmap_sg);
 
 int vsp1_drm_init(struct vsp1_device *vsp1)
 {
-	unsigned int i;
-
 	vsp1->drm = devm_kzalloc(vsp1->dev, sizeof(*vsp1->drm), GFP_KERNEL);
 	if (!vsp1->drm)
 		return -ENOMEM;
@@ -973,7 +969,7 @@ int vsp1_drm_init(struct vsp1_device *vsp1)
 	mutex_init(&vsp1->drm->lock);
 
 	/* Create one DRM pipeline per LIF. */
-	for (i = 0; i < vsp1->info->lif_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->lif_count; ++i) {
 		struct vsp1_drm_pipeline *drm_pipe = &vsp1->drm->pipe[i];
 		struct vsp1_pipeline *pipe = &drm_pipe->pipe;
 
@@ -1010,7 +1006,7 @@ int vsp1_drm_init(struct vsp1_device *vsp1)
 	}
 
 	/* Disable all RPFs initially. */
-	for (i = 0; i < vsp1->info->rpf_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->rpf_count; ++i) {
 		struct vsp1_rwpf *input = vsp1->rpf[i];
 
 		INIT_LIST_HEAD(&input->entity.list_pipe);
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drv.c b/drivers/media/platform/renesas/vsp1/vsp1_drv.c
index 627b5046fa80..3fa5a4415fc6 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_drv.c
@@ -51,10 +51,9 @@ static irqreturn_t vsp1_irq_handler(int irq, void *data)
 		   VI6_WPF_IRQ_STA_UND;
 	struct vsp1_device *vsp1 = data;
 	irqreturn_t ret = IRQ_NONE;
-	unsigned int i;
 	u32 status;
 
-	for (i = 0; i < vsp1->info->wpf_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i) {
 		struct vsp1_rwpf *wpf = vsp1->wpf[i];
 
 		if (wpf == NULL)
@@ -103,7 +102,6 @@ static int vsp1_create_sink_links(struct vsp1_device *vsp1,
 {
 	struct media_entity *entity = &sink->subdev.entity;
 	struct vsp1_entity *source;
-	unsigned int pad;
 	int ret;
 
 	list_for_each_entry(source, &vsp1->entities, list_dev) {
@@ -123,7 +121,7 @@ static int vsp1_create_sink_links(struct vsp1_device *vsp1,
 			source->index == sink->index
 		      ? MEDIA_LNK_FL_ENABLED : 0;
 
-		for (pad = 0; pad < entity->num_pads; ++pad) {
+		for (unsigned int pad = 0; pad < entity->num_pads; ++pad) {
 			if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
 				continue;
 
@@ -144,7 +142,6 @@ static int vsp1_create_sink_links(struct vsp1_device *vsp1,
 static int vsp1_uapi_create_links(struct vsp1_device *vsp1)
 {
 	struct vsp1_entity *entity;
-	unsigned int i;
 	int ret;
 
 	list_for_each_entry(entity, &vsp1->entities, list_dev) {
@@ -177,7 +174,7 @@ static int vsp1_uapi_create_links(struct vsp1_device *vsp1)
 			return ret;
 	}
 
-	for (i = 0; i < vsp1->info->lif_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->lif_count; ++i) {
 		if (!vsp1->lif[i])
 			continue;
 
@@ -189,7 +186,7 @@ static int vsp1_uapi_create_links(struct vsp1_device *vsp1)
 			return ret;
 	}
 
-	for (i = 0; i < vsp1->info->rpf_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->rpf_count; ++i) {
 		struct vsp1_rwpf *rpf = vsp1->rpf[i];
 
 		ret = media_create_pad_link(&rpf->video->video.entity, 0,
@@ -201,7 +198,7 @@ static int vsp1_uapi_create_links(struct vsp1_device *vsp1)
 			return ret;
 	}
 
-	for (i = 0; i < vsp1->info->wpf_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i) {
 		/*
 		 * Connect the video device to the WPF. All connections are
 		 * immutable.
@@ -253,7 +250,6 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 	struct media_device *mdev = &vsp1->media_dev;
 	struct v4l2_device *vdev = &vsp1->v4l2_dev;
 	struct vsp1_entity *entity;
-	unsigned int i;
 	int ret;
 
 	mdev->dev = vsp1->dev;
@@ -365,7 +361,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 	 * enabled skip the LIFs, even when present.
 	 */
 	if (!vsp1->info->uapi) {
-		for (i = 0; i < vsp1->info->lif_count; ++i) {
+		for (unsigned int i = 0; i < vsp1->info->lif_count; ++i) {
 			struct vsp1_lif *lif;
 
 			lif = vsp1_lif_create(vsp1, i);
@@ -389,7 +385,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 		list_add_tail(&vsp1->lut->entity.list_dev, &vsp1->entities);
 	}
 
-	for (i = 0; i < vsp1->info->rpf_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->rpf_count; ++i) {
 		struct vsp1_rwpf *rpf;
 
 		rpf = vsp1_rpf_create(vsp1, i);
@@ -423,7 +419,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 		list_add_tail(&vsp1->sru->entity.list_dev, &vsp1->entities);
 	}
 
-	for (i = 0; i < vsp1->info->uds_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->uds_count; ++i) {
 		struct vsp1_uds *uds;
 
 		uds = vsp1_uds_create(vsp1, i);
@@ -436,7 +432,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 		list_add_tail(&uds->entity.list_dev, &vsp1->entities);
 	}
 
-	for (i = 0; i < vsp1->info->uif_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->uif_count; ++i) {
 		struct vsp1_uif *uif;
 
 		uif = vsp1_uif_create(vsp1, i);
@@ -449,7 +445,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 		list_add_tail(&uif->entity.list_dev, &vsp1->entities);
 	}
 
-	for (i = 0; i < vsp1->info->wpf_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i) {
 		struct vsp1_rwpf *wpf;
 
 		wpf = vsp1_wpf_create(vsp1, i);
@@ -543,11 +539,10 @@ int vsp1_reset_wpf(struct vsp1_device *vsp1, unsigned int index)
 
 static int vsp1_device_init(struct vsp1_device *vsp1)
 {
-	unsigned int i;
 	int ret;
 
 	/* Reset any channel that might be running. */
-	for (i = 0; i < vsp1->info->wpf_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i) {
 		ret = vsp1_reset_wpf(vsp1, i);
 		if (ret < 0)
 			return ret;
@@ -556,13 +551,13 @@ static int vsp1_device_init(struct vsp1_device *vsp1)
 	vsp1_write(vsp1, VI6_CLK_DCSWT, (8 << VI6_CLK_DCSWT_CSTPW_SHIFT) |
 		   (8 << VI6_CLK_DCSWT_CSTRW_SHIFT));
 
-	for (i = 0; i < vsp1->info->rpf_count; ++i)
+	for (unsigned int i = 0; i < vsp1->info->rpf_count; ++i)
 		vsp1_write(vsp1, VI6_DPR_RPF_ROUTE(i), VI6_DPR_NODE_UNUSED);
 
-	for (i = 0; i < vsp1->info->uds_count; ++i)
+	for (unsigned int i = 0; i < vsp1->info->uds_count; ++i)
 		vsp1_write(vsp1, VI6_DPR_UDS_ROUTE(i), VI6_DPR_NODE_UNUSED);
 
-	for (i = 0; i < vsp1->info->uif_count; ++i)
+	for (unsigned int i = 0; i < vsp1->info->uif_count; ++i)
 		vsp1_write(vsp1, VI6_DPR_UIF_ROUTE(i), VI6_DPR_NODE_UNUSED);
 
 	vsp1_write(vsp1, VI6_DPR_SRU_ROUTE, VI6_DPR_NODE_UNUSED);
@@ -587,11 +582,9 @@ static int vsp1_device_init(struct vsp1_device *vsp1)
 
 static void vsp1_mask_all_interrupts(struct vsp1_device *vsp1)
 {
-	unsigned int i;
-
-	for (i = 0; i < vsp1->info->lif_count; ++i)
+	for (unsigned int i = 0; i < vsp1->info->lif_count; ++i)
 		vsp1_write(vsp1, VI6_DISP_IRQ_ENB(i), 0);
-	for (i = 0; i < vsp1->info->wpf_count; ++i)
+	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i)
 		vsp1_write(vsp1, VI6_WPF_IRQ_ENB(i), 0);
 }
 
@@ -891,7 +884,6 @@ static const struct vsp1_device_info rzg2l_vsp2_device_info = {
 static const struct vsp1_device_info *vsp1_lookup_info(struct vsp1_device *vsp1)
 {
 	const struct vsp1_device_info *info;
-	unsigned int i;
 	u32 model;
 	u32 soc;
 
@@ -909,7 +901,7 @@ static const struct vsp1_device_info *vsp1_lookup_info(struct vsp1_device *vsp1)
 	model = vsp1->version & VI6_IP_VERSION_MODEL_MASK;
 	soc = vsp1->version & VI6_IP_VERSION_SOC_MASK;
 
-	for (i = 0; i < ARRAY_SIZE(vsp1_device_infos); ++i) {
+	for (unsigned int i = 0; i < ARRAY_SIZE(vsp1_device_infos); ++i) {
 		info = &vsp1_device_infos[i];
 
 		if (model == info->version && (!info->soc || soc == info->soc))
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_entity.c b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
index 2ae2a573f0de..26b21559878d 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_entity.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
@@ -372,10 +372,8 @@ int vsp1_subdev_set_pad_format(struct v4l2_subdev *subdev,
 static int vsp1_entity_init_state(struct v4l2_subdev *subdev,
 				  struct v4l2_subdev_state *sd_state)
 {
-	unsigned int pad;
-
 	/* Initialize all pad formats with default values. */
-	for (pad = 0; pad < subdev->entity.num_pads - 1; ++pad) {
+	for (unsigned int pad = 0; pad < subdev->entity.num_pads - 1; ++pad) {
 		struct v4l2_subdev_format format = {
 			.pad = pad,
 			.which = sd_state ? V4L2_SUBDEV_FORMAT_TRY
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_hgo.c b/drivers/media/platform/renesas/vsp1/vsp1_hgo.c
index 0ef512e3a94b..d3eaa7c2d595 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_hgo.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_hgo.c
@@ -42,7 +42,6 @@ void vsp1_hgo_frame_end(struct vsp1_entity *entity)
 {
 	struct vsp1_hgo *hgo = to_hgo(&entity->subdev);
 	struct vsp1_histogram_buffer *buf;
-	unsigned int i;
 	size_t size;
 	u32 *data;
 
@@ -56,7 +55,7 @@ void vsp1_hgo_frame_end(struct vsp1_entity *entity)
 		*data++ = vsp1_hgo_read(hgo, VI6_HGO_G_MAXMIN);
 		*data++ = vsp1_hgo_read(hgo, VI6_HGO_G_SUM);
 
-		for (i = 0; i < 256; ++i) {
+		for (unsigned int i = 0; i < 256; ++i) {
 			vsp1_write(hgo->histo.entity.vsp1,
 				   VI6_HGO_EXT_HIST_ADDR, i);
 			*data++ = vsp1_hgo_read(hgo, VI6_HGO_EXT_HIST_DATA);
@@ -67,7 +66,7 @@ void vsp1_hgo_frame_end(struct vsp1_entity *entity)
 		*data++ = vsp1_hgo_read(hgo, VI6_HGO_G_MAXMIN);
 		*data++ = vsp1_hgo_read(hgo, VI6_HGO_G_SUM);
 
-		for (i = 0; i < 64; ++i)
+		for (unsigned int i = 0; i < 64; ++i)
 			*data++ = vsp1_hgo_read(hgo, VI6_HGO_G_HISTO(i));
 
 		size = (2 + 64) * sizeof(u32);
@@ -80,7 +79,7 @@ void vsp1_hgo_frame_end(struct vsp1_entity *entity)
 		*data++ = vsp1_hgo_read(hgo, VI6_HGO_G_SUM);
 		*data++ = vsp1_hgo_read(hgo, VI6_HGO_B_SUM);
 
-		for (i = 0; i < 64; ++i) {
+		for (unsigned int i = 0; i < 64; ++i) {
 			data[i] = vsp1_hgo_read(hgo, VI6_HGO_R_HISTO(i));
 			data[i+64] = vsp1_hgo_read(hgo, VI6_HGO_G_HISTO(i));
 			data[i+128] = vsp1_hgo_read(hgo, VI6_HGO_B_HISTO(i));
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_hgt.c b/drivers/media/platform/renesas/vsp1/vsp1_hgt.c
index 78b5a9201c70..8c04bdec8510 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_hgt.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_hgt.c
@@ -42,8 +42,6 @@ void vsp1_hgt_frame_end(struct vsp1_entity *entity)
 {
 	struct vsp1_hgt *hgt = to_hgt(&entity->subdev);
 	struct vsp1_histogram_buffer *buf;
-	unsigned int m;
-	unsigned int n;
 	u32 *data;
 
 	buf = vsp1_histogram_buffer_get(&hgt->histo);
@@ -55,9 +53,10 @@ void vsp1_hgt_frame_end(struct vsp1_entity *entity)
 	*data++ = vsp1_hgt_read(hgt, VI6_HGT_MAXMIN);
 	*data++ = vsp1_hgt_read(hgt, VI6_HGT_SUM);
 
-	for (m = 0; m < 6; ++m)
-		for (n = 0; n < 32; ++n)
+	for (unsigned int m = 0; m < 6; ++m) {
+		for (unsigned int n = 0; n < 32; ++n)
 			*data++ = vsp1_hgt_read(hgt, VI6_HGT_HISTO(m, n));
+	}
 
 	vsp1_histogram_buffer_complete(&hgt->histo, buf, HGT_DATA_SIZE);
 }
@@ -71,7 +70,6 @@ void vsp1_hgt_frame_end(struct vsp1_entity *entity)
 static int hgt_hue_areas_try_ctrl(struct v4l2_ctrl *ctrl)
 {
 	const u8 *values = ctrl->p_new.p_u8;
-	unsigned int i;
 
 	/*
 	 * The hardware has constraints on the hue area boundaries beyond the
@@ -83,7 +81,7 @@ static int hgt_hue_areas_try_ctrl(struct v4l2_ctrl *ctrl)
 	 *
 	 * Start by verifying the common part...
 	 */
-	for (i = 1; i < (HGT_NUM_HUE_AREAS * 2) - 1; ++i) {
+	for (unsigned int i = 1; i < (HGT_NUM_HUE_AREAS * 2) - 1; ++i) {
 		if (values[i] > values[i+1])
 			return -EINVAL;
 	}
@@ -138,7 +136,6 @@ static void hgt_configure_stream(struct vsp1_entity *entity,
 	unsigned int vratio;
 	u8 lower;
 	u8 upper;
-	unsigned int i;
 
 	crop = v4l2_subdev_state_get_crop(state, HISTO_PAD_SINK);
 	compose = v4l2_subdev_state_get_compose(state, HISTO_PAD_SINK);
@@ -153,7 +150,7 @@ static void hgt_configure_stream(struct vsp1_entity *entity,
 		       (crop->height << VI6_HGT_SIZE_VSIZE_SHIFT));
 
 	scoped_guard(mutex, hgt->ctrls.lock) {
-		for (i = 0; i < HGT_NUM_HUE_AREAS; ++i) {
+		for (unsigned int i = 0; i < HGT_NUM_HUE_AREAS; ++i) {
 			lower = hgt->hue_areas[i*2 + 0];
 			upper = hgt->hue_areas[i*2 + 1];
 			vsp1_hgt_write(hgt, dlb, VI6_HGT_HUE_AREA(i),
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_lut.c b/drivers/media/platform/renesas/vsp1/vsp1_lut.c
index a22c31e17cb7..6433b5515ef9 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_lut.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_lut.c
@@ -40,13 +40,12 @@ static inline void vsp1_lut_write(struct vsp1_lut *lut,
 static int lut_set_table(struct vsp1_lut *lut, struct v4l2_ctrl *ctrl)
 {
 	struct vsp1_dl_body *dlb;
-	unsigned int i;
 
 	dlb = vsp1_dl_body_get(lut->pool);
 	if (!dlb)
 		return -ENOMEM;
 
-	for (i = 0; i < LUT_SIZE; ++i)
+	for (unsigned int i = 0; i < LUT_SIZE; ++i)
 		vsp1_dl_body_write(dlb, VI6_LUT_TABLE + 4 * i,
 				       ctrl->p_new.p_u32[i]);
 
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
index 7197f2917417..ca0ec00b9deb 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
@@ -391,16 +391,15 @@ void vsp1_adjust_color_space(u32 code, u32 *colorspace, u8 *xfer_func,
 void vsp1_pipeline_reset(struct vsp1_pipeline *pipe)
 {
 	struct vsp1_entity *entity;
-	unsigned int i;
 
 	if (pipe->brx) {
 		struct vsp1_brx *brx = to_brx(&pipe->brx->subdev);
 
-		for (i = 0; i < ARRAY_SIZE(brx->inputs); ++i)
+		for (unsigned int i = 0; i < ARRAY_SIZE(brx->inputs); ++i)
 			brx->inputs[i].rpf = NULL;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i)
+	for (unsigned int i = 0; i < ARRAY_SIZE(pipe->inputs); ++i)
 		pipe->inputs[i] = NULL;
 
 	pipe->output = NULL;
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c
index b0eae54273a0..fa57e241f827 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_video.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c
@@ -104,14 +104,13 @@ static int __vsp1_video_try_format(struct vsp1_video *video,
 	const struct vsp1_format_info *info;
 	unsigned int width = pix->width;
 	unsigned int height = pix->height;
-	unsigned int i;
 
 	/*
 	 * Backward compatibility: replace deprecated RGB formats by their XRGB
 	 * equivalent. This selects the format older userspace applications want
 	 * while still exposing the new format.
 	 */
-	for (i = 0; i < ARRAY_SIZE(xrgb_formats); ++i) {
+	for (unsigned int i = 0; i < ARRAY_SIZE(xrgb_formats); ++i) {
 		if (xrgb_formats[i][0] == pix->pixelformat) {
 			pix->pixelformat = xrgb_formats[i][1];
 			break;
@@ -161,7 +160,7 @@ static int __vsp1_video_try_format(struct vsp1_video *video,
 	 * the datasheet, strides not aligned to a multiple of 128 bytes result
 	 * in image corruption.
 	 */
-	for (i = 0; i < min(info->planes, 2U); ++i) {
+	for (unsigned int i = 0; i < min(info->planes, 2U); ++i) {
 		unsigned int hsub = i > 0 ? info->hsub : 1;
 		unsigned int vsub = i > 0 ? info->vsub : 1;
 		unsigned int align = 128;
@@ -209,7 +208,6 @@ vsp1_video_complete_buffer(struct vsp1_video *video)
 	struct vsp1_pipeline *pipe = video->rwpf->entity.pipe;
 	struct vsp1_vb2_buffer *next = NULL;
 	struct vsp1_vb2_buffer *done;
-	unsigned int i;
 
 	scoped_guard(spinlock_irqsave, &video->irqlock) {
 		if (list_empty(&video->irqqueue))
@@ -227,7 +225,7 @@ vsp1_video_complete_buffer(struct vsp1_video *video)
 
 	done->buf.sequence = pipe->sequence;
 	done->buf.vb2_buf.timestamp = ktime_get_ns();
-	for (i = 0; i < done->buf.vb2_buf.num_planes; ++i)
+	for (unsigned int i = 0; i < done->buf.vb2_buf.num_planes; ++i)
 		vb2_set_plane_payload(&done->buf.vb2_buf, i,
 				      vb2_plane_size(&done->buf.vb2_buf, i));
 	vb2_buffer_done(&done->buf.vb2_buf, VB2_BUF_STATE_DONE);
@@ -267,7 +265,6 @@ static void vsp1_video_pipeline_run(struct vsp1_pipeline *pipe)
 	struct vsp1_entity *entity;
 	struct vsp1_dl_body *dlb;
 	struct vsp1_dl_list *dl;
-	unsigned int partition;
 
 	dl = vsp1_dl_list_get(pipe->output->dlm);
 
@@ -289,7 +286,7 @@ static void vsp1_video_pipeline_run(struct vsp1_pipeline *pipe)
 	vsp1_video_pipeline_run_partition(pipe, dl, 0);
 
 	/* Process consecutive partitions as necessary. */
-	for (partition = 1; partition < pipe->partitions; ++partition) {
+	for (unsigned int partition = 1; partition < pipe->partitions; ++partition) {
 		struct vsp1_dl_list *dl_next;
 
 		dl_next = vsp1_dl_list_get(pipe->output->dlm);
@@ -320,13 +317,12 @@ static void vsp1_video_pipeline_frame_end(struct vsp1_pipeline *pipe,
 {
 	struct vsp1_device *vsp1 = pipe->output->entity.vsp1;
 	enum vsp1_pipeline_state state;
-	unsigned int i;
 
 	/* M2M Pipelines should never call here with an incomplete frame. */
 	WARN_ON_ONCE(!(completion & VSP1_DL_FRAME_END_COMPLETED));
 
 	/* Complete buffers on all video nodes. */
-	for (i = 0; i < vsp1->info->rpf_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->rpf_count; ++i) {
 		if (!pipe->inputs[i])
 			continue;
 
@@ -444,7 +440,6 @@ static int vsp1_video_pipeline_build(struct vsp1_pipeline *pipe,
 	struct media_graph graph;
 	struct media_entity *entity = &video->video.entity;
 	struct media_device *mdev = entity->graph_obj.mdev;
-	unsigned int i;
 	int ret;
 
 	/* Walk the graph to locate the entities and video nodes. */
@@ -512,7 +507,7 @@ static int vsp1_video_pipeline_build(struct vsp1_pipeline *pipe,
 	 * Follow links downstream for each input and make sure the graph
 	 * contains no loop and that all branches end at the output WPF.
 	 */
-	for (i = 0; i < video->vsp1->info->rpf_count; ++i) {
+	for (unsigned int i = 0; i < video->vsp1->info->rpf_count; ++i) {
 		if (!pipe->inputs[i])
 			continue;
 
@@ -601,13 +596,12 @@ vsp1_video_queue_setup(struct vb2_queue *vq,
 {
 	struct vsp1_video *video = vb2_get_drv_priv(vq);
 	const struct v4l2_pix_format_mplane *format = &video->rwpf->format;
-	unsigned int i;
 
 	if (*nplanes) {
 		if (*nplanes != format->num_planes)
 			return -EINVAL;
 
-		for (i = 0; i < *nplanes; i++)
+		for (unsigned int i = 0; i < *nplanes; i++)
 			if (sizes[i] < format->plane_fmt[i].sizeimage)
 				return -EINVAL;
 		return 0;
@@ -615,7 +609,7 @@ vsp1_video_queue_setup(struct vb2_queue *vq,
 
 	*nplanes = format->num_planes;
 
-	for (i = 0; i < format->num_planes; ++i)
+	for (unsigned int i = 0; i < format->num_planes; ++i)
 		sizes[i] = format->plane_fmt[i].sizeimage;
 
 	return 0;
@@ -677,7 +671,6 @@ static int vsp1_video_pipeline_setup_partitions(struct vsp1_pipeline *pipe)
 	const struct v4l2_mbus_framefmt *format;
 	struct vsp1_entity *entity;
 	unsigned int div_size;
-	unsigned int i;
 
 	/*
 	 * Partitions are computed on the size before rotation, use the format
@@ -711,7 +704,7 @@ static int vsp1_video_pipeline_setup_partitions(struct vsp1_pipeline *pipe)
 	if (!pipe->part_table)
 		return -ENOMEM;
 
-	for (i = 0; i < pipe->partitions; ++i)
+	for (unsigned int i = 0; i < pipe->partitions; ++i)
 		vsp1_pipeline_calculate_partition(pipe, &pipe->part_table[i],
 						  div_size, i);
 
@@ -1111,7 +1104,6 @@ static const struct media_entity_operations vsp1_video_media_ops = {
 
 void vsp1_video_suspend(struct vsp1_device *vsp1)
 {
-	unsigned int i;
 	int ret;
 
 	/*
@@ -1119,7 +1111,7 @@ void vsp1_video_suspend(struct vsp1_device *vsp1)
 	 * pipelines twice, first to set them all to the stopping state, and
 	 * then to wait for the stop to complete.
 	 */
-	for (i = 0; i < vsp1->info->wpf_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i) {
 		struct vsp1_rwpf *wpf = vsp1->wpf[i];
 		struct vsp1_pipeline *pipe;
 
@@ -1136,7 +1128,7 @@ void vsp1_video_suspend(struct vsp1_device *vsp1)
 		}
 	}
 
-	for (i = 0; i < vsp1->info->wpf_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i) {
 		struct vsp1_rwpf *wpf = vsp1->wpf[i];
 		struct vsp1_pipeline *pipe;
 
@@ -1157,10 +1149,8 @@ void vsp1_video_suspend(struct vsp1_device *vsp1)
 
 void vsp1_video_resume(struct vsp1_device *vsp1)
 {
-	unsigned int i;
-
 	/* Resume all running pipelines. */
-	for (i = 0; i < vsp1->info->wpf_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i) {
 		struct vsp1_rwpf *wpf = vsp1->wpf[i];
 		struct vsp1_pipeline *pipe;
 
diff --git a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
index 0ec707d2913f..821887815eb2 100644
--- a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
@@ -232,7 +232,6 @@ static void wpf_configure_stream(struct vsp1_entity *entity,
 	const struct v4l2_mbus_framefmt *source_format;
 	const struct v4l2_mbus_framefmt *sink_format;
 	unsigned int index = wpf->entity.index;
-	unsigned int i;
 	u32 outfmt = 0;
 	u32 srcrpf = 0;
 	int ret;
@@ -314,7 +313,7 @@ static void wpf_configure_stream(struct vsp1_entity *entity,
 	 * inputs as sub-layers and select the virtual RPF as the master
 	 * layer. For VSPX configure the enabled sources as masters.
 	 */
-	for (i = 0; i < vsp1->info->rpf_count; ++i) {
+	for (unsigned int i = 0; i < vsp1->info->rpf_count; ++i) {
 		struct vsp1_rwpf *input = pipe->inputs[i];
 
 		if (!input)
@@ -399,7 +398,6 @@ static void wpf_configure_partition(struct vsp1_entity *entity,
 	unsigned int left;
 	unsigned int offset;
 	unsigned int flip;
-	unsigned int i;
 
 	/*
 	 * Cropping. The partition algorithm can split the image into multiple
@@ -448,7 +446,7 @@ static void wpf_configure_partition(struct vsp1_entity *entity,
 	else
 		offset = left;
 
-	for (i = 0; i < format->num_planes; ++i) {
+	for (unsigned int i = 0; i < format->num_planes; ++i) {
 		unsigned int hsub = i > 0 ? fmtinfo->hsub : 1;
 		unsigned int vsub = i > 0 ? fmtinfo->vsub : 1;
 
@@ -490,7 +488,7 @@ static void wpf_configure_partition(struct vsp1_entity *entity,
 		 * Compute the output coordinate. The partition
 		 * horizontal (left) offset becomes a vertical offset.
 		 */
-		for (i = 0; i < format->num_planes; ++i) {
+		for (unsigned int i = 0; i < format->num_planes; ++i) {
 			unsigned int hsub = i > 0 ? fmtinfo->hsub : 1;
 
 			mem.addr[i] += hoffset / hsub
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 11/11] media: renesas: vsp1: Drop deprecated vsp1_du_setup_lif() function
  2026-05-11 23:56 [PATCH 00/11] media: renesas: vsp1: Modernize the driver Laurent Pinchart
                   ` (9 preceding siblings ...)
  2026-05-11 23:56 ` [PATCH 10/11] media: renesas: vsp1: Declare index variables in for loop statement Laurent Pinchart
@ 2026-05-11 23:56 ` Laurent Pinchart
  2026-05-13 20:31   ` Niklas Söderlund
  10 siblings, 1 reply; 24+ messages in thread
From: Laurent Pinchart @ 2026-05-11 23:56 UTC (permalink / raw)
  To: linux-media, dri-devel
  Cc: linux-renesas-soc, Tomi Valkeinen, Kieran Bingham, Biju Das,
	David Airlie, Simona Vetter

The vsp1_du_setup_lif() is deprecated and its last users are gone. Drop
it.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 include/media/vsp1.h | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/include/media/vsp1.h b/include/media/vsp1.h
index d2085cdb7fcb..98089e0a4385 100644
--- a/include/media/vsp1.h
+++ b/include/media/vsp1.h
@@ -48,15 +48,6 @@ int vsp1_du_enable(struct device *dev, unsigned int pipe_index,
 		   const struct vsp1_du_lif_config *cfg);
 int vsp1_du_disable(struct device *dev, unsigned int pipe_index);
 
-static inline int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
-				    const struct vsp1_du_lif_config *cfg)
-{
-	if (cfg)
-		return vsp1_du_enable(dev, pipe_index, cfg);
-	else
-		return vsp1_du_disable(dev, pipe_index);
-}
-
 /**
  * struct vsp1_du_atomic_config - VSP atomic configuration parameters
  * @pixelformat: plane pixel format (V4L2 4CC)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH 01/11] media: renesas: vsp1: Avoid forward function declaration
  2026-05-11 23:56 ` [PATCH 01/11] media: renesas: vsp1: Avoid forward function declaration Laurent Pinchart
@ 2026-05-13 19:09   ` Niklas Söderlund
  0 siblings, 0 replies; 24+ messages in thread
From: Niklas Söderlund @ 2026-05-13 19:09 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, dri-devel, linux-renesas-soc, Tomi Valkeinen,
	Kieran Bingham, Biju Das, David Airlie, Simona Vetter

Hi Laurent,

Thanks for your patch.

On 2026-05-12 02:56:25 +0300, Laurent Pinchart wrote:
> Reorder functions to avoid the forward declaration of the
> vsp1_du_pipeline_configure(). No functional change intended.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> ---
>  .../media/platform/renesas/vsp1/vsp1_drm.c    | 90 +++++++++----------
>  1 file changed, 44 insertions(+), 46 deletions(-)
> 
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drm.c b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> index 15d266439564..79b85968b061 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> @@ -57,6 +57,50 @@ static void vsp1_du_pipeline_frame_end(struct vsp1_pipeline *pipe,
>   * Pipeline Configuration
>   */
>  
> +/* Configure all entities in the pipeline. */
> +static void vsp1_du_pipeline_configure(struct vsp1_pipeline *pipe)
> +{
> +	struct vsp1_drm_pipeline *drm_pipe = to_vsp1_drm_pipeline(pipe);
> +	struct vsp1_entity *entity;
> +	struct vsp1_entity *next;
> +	struct vsp1_dl_list *dl;
> +	struct vsp1_dl_body *dlb;
> +	unsigned int dl_flags = 0;
> +
> +	vsp1_pipeline_calculate_partition(pipe, &pipe->part_table[0],
> +					  drm_pipe->width, 0);
> +
> +	if (drm_pipe->force_brx_release)
> +		dl_flags |= VSP1_DL_FRAME_END_INTERNAL;
> +	if (pipe->output->writeback)
> +		dl_flags |= VSP1_DL_FRAME_END_WRITEBACK;
> +
> +	dl = vsp1_dl_list_get(pipe->output->dlm);
> +	dlb = vsp1_dl_list_get_body0(dl);
> +
> +	list_for_each_entry_safe(entity, next, &pipe->entities, list_pipe) {
> +		/* Disconnect unused entities from the pipeline. */
> +		if (!entity->pipe) {
> +			vsp1_dl_body_write(dlb, entity->route->reg,
> +					   VI6_DPR_NODE_UNUSED);
> +
> +			entity->sink = NULL;
> +			list_del(&entity->list_pipe);
> +
> +			continue;
> +		}
> +
> +		vsp1_entity_route_setup(entity, pipe, dlb);
> +		vsp1_entity_configure_stream(entity, entity->state, pipe,
> +					     dl, dlb);
> +		vsp1_entity_configure_frame(entity, pipe, dl, dlb);
> +		vsp1_entity_configure_partition(entity, pipe,
> +						&pipe->part_table[0], dl, dlb);
> +	}
> +
> +	vsp1_dl_list_commit(dl, dl_flags);
> +}
> +
>  /*
>   * Insert the UIF in the pipeline between the prev and next entities. If no UIF
>   * is available connect the two entities directly.
> @@ -224,8 +268,6 @@ static int vsp1_du_pipeline_setup_rpf(struct vsp1_device *vsp1,
>  /* Setup the BRx source pad. */
>  static int vsp1_du_pipeline_setup_inputs(struct vsp1_device *vsp1,
>  					 struct vsp1_pipeline *pipe);
> -static void vsp1_du_pipeline_configure(struct vsp1_pipeline *pipe);
> -
>  static int vsp1_du_pipeline_setup_brx(struct vsp1_device *vsp1,
>  				      struct vsp1_pipeline *pipe)
>  {
> @@ -541,50 +583,6 @@ static int vsp1_du_pipeline_setup_output(struct vsp1_device *vsp1,
>  	return 0;
>  }
>  
> -/* Configure all entities in the pipeline. */
> -static void vsp1_du_pipeline_configure(struct vsp1_pipeline *pipe)
> -{
> -	struct vsp1_drm_pipeline *drm_pipe = to_vsp1_drm_pipeline(pipe);
> -	struct vsp1_entity *entity;
> -	struct vsp1_entity *next;
> -	struct vsp1_dl_list *dl;
> -	struct vsp1_dl_body *dlb;
> -	unsigned int dl_flags = 0;
> -
> -	vsp1_pipeline_calculate_partition(pipe, &pipe->part_table[0],
> -					  drm_pipe->width, 0);
> -
> -	if (drm_pipe->force_brx_release)
> -		dl_flags |= VSP1_DL_FRAME_END_INTERNAL;
> -	if (pipe->output->writeback)
> -		dl_flags |= VSP1_DL_FRAME_END_WRITEBACK;
> -
> -	dl = vsp1_dl_list_get(pipe->output->dlm);
> -	dlb = vsp1_dl_list_get_body0(dl);
> -
> -	list_for_each_entry_safe(entity, next, &pipe->entities, list_pipe) {
> -		/* Disconnect unused entities from the pipeline. */
> -		if (!entity->pipe) {
> -			vsp1_dl_body_write(dlb, entity->route->reg,
> -					   VI6_DPR_NODE_UNUSED);
> -
> -			entity->sink = NULL;
> -			list_del(&entity->list_pipe);
> -
> -			continue;
> -		}
> -
> -		vsp1_entity_route_setup(entity, pipe, dlb);
> -		vsp1_entity_configure_stream(entity, entity->state, pipe,
> -					     dl, dlb);
> -		vsp1_entity_configure_frame(entity, pipe, dl, dlb);
> -		vsp1_entity_configure_partition(entity, pipe,
> -						&pipe->part_table[0], dl, dlb);
> -	}
> -
> -	vsp1_dl_list_commit(dl, dl_flags);
> -}
> -
>  static int vsp1_du_pipeline_set_rwpf_format(struct vsp1_device *vsp1,
>  					    struct vsp1_rwpf *rwpf,
>  					    u32 pixelformat, unsigned int pitch)
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> 

-- 
Kind Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 02/11] media: renesas: vsp1: Split vsp1_du_setup_lif()
  2026-05-11 23:56 ` [PATCH 02/11] media: renesas: vsp1: Split vsp1_du_setup_lif() Laurent Pinchart
@ 2026-05-13 19:11   ` Niklas Söderlund
  0 siblings, 0 replies; 24+ messages in thread
From: Niklas Söderlund @ 2026-05-13 19:11 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, dri-devel, linux-renesas-soc, Tomi Valkeinen,
	Kieran Bingham, Biju Das, David Airlie, Simona Vetter

Hi Laurent,

Thanks for your cleanup!

On 2026-05-12 02:56:26 +0300, Laurent Pinchart wrote:
> The vsp1_du_setup_lif() function is used to configure and enable a
> pipeline, as well as disable it, depending on the cfg argument being a
> valid pointer or NULL. This creates a confusing API. Improve it by
> splitting the function in two, a vsp1_du_enable() function to configure
> a pipeline, and a vsp1_du_disable() function to disaple it.
> 
> Keep vsp1_du_setup_lif() as an inline wrapper for existing callers in
> the DRM subsystem, to simplify merging. The callers will be updated
> separately and the old API will then be removed.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> ---
>  .../media/platform/renesas/vsp1/vsp1_drm.c    | 140 ++++++++++--------
>  include/media/vsp1.h                          |  14 +-
>  2 files changed, 91 insertions(+), 63 deletions(-)
> 
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drm.c b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> index 79b85968b061..1f431874064d 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> @@ -629,14 +629,14 @@ int vsp1_du_init(struct device *dev)
>  EXPORT_SYMBOL_GPL(vsp1_du_init);
>  
>  /**
> - * vsp1_du_setup_lif - Setup the output part of the VSP pipeline
> + * vsp1_du_enable - Setup and enable a DU pipeline
>   * @dev: the VSP device
>   * @pipe_index: the DRM pipeline index
>   * @cfg: the LIF configuration
>   *
>   * Configure the output part of VSP DRM pipeline for the given frame @cfg.width
>   * and @cfg.height. This sets up formats on the BRx source pad, the WPF sink and
> - * source pads, and the LIF sink pad.
> + * source pads, and the LIF sink pad, and then starts the pipeline.
>   *
>   * The @pipe_index argument selects which DRM pipeline to setup. The number of
>   * available pipelines depend on the VSP instance.
> @@ -649,14 +649,13 @@ EXPORT_SYMBOL_GPL(vsp1_du_init);
>   *
>   * Return 0 on success or a negative error code on failure.
>   */
> -int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
> -		      const struct vsp1_du_lif_config *cfg)
> +int vsp1_du_enable(struct device *dev, unsigned int pipe_index,
> +		   const struct vsp1_du_lif_config *cfg)
>  {
>  	struct vsp1_device *vsp1 = dev_get_drvdata(dev);
>  	struct vsp1_drm_pipeline *drm_pipe;
>  	struct vsp1_pipeline *pipe;
>  	unsigned long flags;
> -	unsigned int i;
>  	int ret;
>  
>  	if (pipe_index >= vsp1->info->lif_count)
> @@ -665,60 +664,6 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
>  	drm_pipe = &vsp1->drm->pipe[pipe_index];
>  	pipe = &drm_pipe->pipe;
>  
> -	if (!cfg) {
> -		struct vsp1_brx *brx;
> -
> -		mutex_lock(&vsp1->drm->lock);
> -
> -		brx = to_brx(&pipe->brx->subdev);
> -
> -		/*
> -		 * NULL configuration means the CRTC is being disabled, stop
> -		 * the pipeline and turn the light off.
> -		 */
> -		ret = vsp1_pipeline_stop(pipe);
> -		if (ret == -ETIMEDOUT)
> -			dev_err(vsp1->dev, "DRM pipeline stop timeout\n");
> -
> -		for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) {
> -			struct vsp1_rwpf *rpf = pipe->inputs[i];
> -
> -			if (!rpf)
> -				continue;
> -
> -			/*
> -			 * Remove the RPF from the pipe and the list of BRx
> -			 * inputs.
> -			 */
> -			WARN_ON(!rpf->entity.pipe);
> -			rpf->entity.pipe = NULL;
> -			list_del(&rpf->entity.list_pipe);
> -			pipe->inputs[i] = NULL;
> -
> -			brx->inputs[rpf->brx_input].rpf = NULL;
> -		}
> -
> -		drm_pipe->du_complete = NULL;
> -		pipe->num_inputs = 0;
> -
> -		dev_dbg(vsp1->dev, "%s: pipe %u: releasing %s\n",
> -			__func__, pipe->lif->index,
> -			BRX_NAME(pipe->brx));
> -
> -		list_del(&pipe->brx->list_pipe);
> -		pipe->brx->pipe = NULL;
> -		pipe->brx = NULL;
> -
> -		mutex_unlock(&vsp1->drm->lock);
> -
> -		vsp1_dlm_reset(pipe->output->dlm);
> -		vsp1_device_put(vsp1);
> -
> -		dev_dbg(vsp1->dev, "%s: pipeline disabled\n", __func__);
> -
> -		return 0;
> -	}
> -
>  	/* Reset the underrun counter */
>  	pipe->underrun_count = 0;
>  
> @@ -741,7 +686,7 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
>  	if (ret < 0)
>  		goto unlock;
>  
> -	vsp1_pipeline_dump(pipe, "LIF setup");
> +	vsp1_pipeline_dump(pipe, "DU enable");
>  
>  	/* Enable the VSP1. */
>  	ret = vsp1_device_get(vsp1);
> @@ -777,7 +722,80 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
>  
>  	return 0;
>  }
> -EXPORT_SYMBOL_GPL(vsp1_du_setup_lif);
> +EXPORT_SYMBOL_GPL(vsp1_du_enable);
> +
> +/**
> + * vsp1_du_disable - Disable and stop a DU pipeline
> + * @dev: the VSP device
> + * @pipe_index: the DRM pipeline index
> + *
> + * The @pipe_index argument selects which DRM pipeline to disable. The number
> + * of available pipelines depend on the VSP instance.
> + *
> + * Return 0 on success or a negative error code on failure.
> + */
> +int vsp1_du_disable(struct device *dev, unsigned int pipe_index)
> +{
> +	struct vsp1_device *vsp1 = dev_get_drvdata(dev);
> +	struct vsp1_drm_pipeline *drm_pipe;
> +	struct vsp1_pipeline *pipe;
> +	struct vsp1_brx *brx;
> +	unsigned int i;
> +	int ret;
> +
> +	if (pipe_index >= vsp1->info->lif_count)
> +		return -EINVAL;
> +
> +	drm_pipe = &vsp1->drm->pipe[pipe_index];
> +	pipe = &drm_pipe->pipe;
> +
> +	mutex_lock(&vsp1->drm->lock);
> +
> +	brx = to_brx(&pipe->brx->subdev);
> +
> +	ret = vsp1_pipeline_stop(pipe);
> +	if (ret == -ETIMEDOUT)
> +		dev_err(vsp1->dev, "DRM pipeline stop timeout\n");
> +
> +	for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) {
> +		struct vsp1_rwpf *rpf = pipe->inputs[i];
> +
> +		if (!rpf)
> +			continue;
> +
> +		/*
> +		 * Remove the RPF from the pipe and the list of BRx
> +		 * inputs.
> +		 */
> +		WARN_ON(!rpf->entity.pipe);
> +		rpf->entity.pipe = NULL;
> +		list_del(&rpf->entity.list_pipe);
> +		pipe->inputs[i] = NULL;
> +
> +		brx->inputs[rpf->brx_input].rpf = NULL;
> +	}
> +
> +	drm_pipe->du_complete = NULL;
> +	pipe->num_inputs = 0;
> +
> +	dev_dbg(vsp1->dev, "%s: pipe %u: releasing %s\n",
> +		__func__, pipe->lif->index,
> +		BRX_NAME(pipe->brx));
> +
> +	list_del(&pipe->brx->list_pipe);
> +	pipe->brx->pipe = NULL;
> +	pipe->brx = NULL;
> +
> +	mutex_unlock(&vsp1->drm->lock);
> +
> +	vsp1_dlm_reset(pipe->output->dlm);
> +	vsp1_device_put(vsp1);
> +
> +	dev_dbg(vsp1->dev, "%s: pipeline disabled\n", __func__);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(vsp1_du_disable);
>  
>  /**
>   * vsp1_du_atomic_begin - Prepare for an atomic update
> diff --git a/include/media/vsp1.h b/include/media/vsp1.h
> index d9b91ff02761..d2085cdb7fcb 100644
> --- a/include/media/vsp1.h
> +++ b/include/media/vsp1.h
> @@ -44,8 +44,18 @@ struct vsp1_du_lif_config {
>  	void *callback_data;
>  };
>  
> -int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
> -		      const struct vsp1_du_lif_config *cfg);
> +int vsp1_du_enable(struct device *dev, unsigned int pipe_index,
> +		   const struct vsp1_du_lif_config *cfg);
> +int vsp1_du_disable(struct device *dev, unsigned int pipe_index);
> +
> +static inline int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
> +				    const struct vsp1_du_lif_config *cfg)
> +{
> +	if (cfg)
> +		return vsp1_du_enable(dev, pipe_index, cfg);
> +	else
> +		return vsp1_du_disable(dev, pipe_index);
> +}
>  
>  /**
>   * struct vsp1_du_atomic_config - VSP atomic configuration parameters
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> 

-- 
Kind Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 03/11] drm: renesas: rcar-du: Switch to new VSP API
  2026-05-11 23:56 ` [PATCH 03/11] drm: renesas: rcar-du: Switch to new VSP API Laurent Pinchart
@ 2026-05-13 19:12   ` Niklas Söderlund
  0 siblings, 0 replies; 24+ messages in thread
From: Niklas Söderlund @ 2026-05-13 19:12 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, dri-devel, linux-renesas-soc, Tomi Valkeinen,
	Kieran Bingham, Biju Das, David Airlie, Simona Vetter

Hi Laurent,

Thanks for your work.

On 2026-05-12 02:56:27 +0300, Laurent Pinchart wrote:
> The vsp1_du_setup_lif() function is deprecated. Use the new
> vsp1_du_enable() and vsp1_du_disable() functions instead.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> ---
>  drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c b/drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c
> index a4a49dcd8233..5cfb4d50bc67 100644
> --- a/drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c
> +++ b/drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c
> @@ -87,12 +87,12 @@ void rcar_du_vsp_enable(struct rcar_du_crtc *crtc)
>  
>  	__rcar_du_plane_setup(crtc->group, &state);
>  
> -	vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, &cfg);
> +	vsp1_du_enable(crtc->vsp->vsp, crtc->vsp_pipe, &cfg);
>  }
>  
>  void rcar_du_vsp_disable(struct rcar_du_crtc *crtc)
>  {
> -	vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, NULL);
> +	vsp1_du_disable(crtc->vsp->vsp, crtc->vsp_pipe);
>  }
>  
>  void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc)
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> 

-- 
Kind Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 04/11] drm: renesas: rz-du: Switch to new VSP API
  2026-05-11 23:56 ` [PATCH 04/11] drm: renesas: rz-du: " Laurent Pinchart
@ 2026-05-13 19:13   ` Niklas Söderlund
  0 siblings, 0 replies; 24+ messages in thread
From: Niklas Söderlund @ 2026-05-13 19:13 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, dri-devel, linux-renesas-soc, Tomi Valkeinen,
	Kieran Bingham, Biju Das, David Airlie, Simona Vetter

Hi Laurent,

Thanks for your work.

On 2026-05-12 02:56:28 +0300, Laurent Pinchart wrote:
> The vsp1_du_setup_lif() function is deprecated. Use the new
> vsp1_du_enable() and vsp1_du_disable() functions instead.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> ---
> Biju, I would like to merge this for v7.2 through the media tree instead
> of the DRM tree. Would that be OK with you, or do you expect conflicting
> changes to the rz-du driver for v7.2 ?
> ---
>  drivers/gpu/drm/renesas/rz-du/rzg2l_du_vsp.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_vsp.c b/drivers/gpu/drm/renesas/rz-du/rzg2l_du_vsp.c
> index bd486377f037..d5a1d36db2c1 100644
> --- a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_vsp.c
> +++ b/drivers/gpu/drm/renesas/rz-du/rzg2l_du_vsp.c
> @@ -55,12 +55,12 @@ void rzg2l_du_vsp_enable(struct rzg2l_du_crtc *crtc)
>  		.callback_data = crtc,
>  	};
>  
> -	vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, &cfg);
> +	vsp1_du_enable(crtc->vsp->vsp, crtc->vsp_pipe, &cfg);
>  }
>  
>  void rzg2l_du_vsp_disable(struct rzg2l_du_crtc *crtc)
>  {
> -	vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, NULL);
> +	vsp1_du_disable(crtc->vsp->vsp, crtc->vsp_pipe);
>  }
>  
>  void rzg2l_du_vsp_atomic_flush(struct rzg2l_du_crtc *crtc)
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> 

-- 
Kind Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 05/11] media: renesas: vsp1: Use mutex guards
  2026-05-11 23:56 ` [PATCH 05/11] media: renesas: vsp1: Use mutex guards Laurent Pinchart
@ 2026-05-13 19:20   ` Niklas Söderlund
  2026-05-13 19:40     ` Laurent Pinchart
  0 siblings, 1 reply; 24+ messages in thread
From: Niklas Söderlund @ 2026-05-13 19:20 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, dri-devel, linux-renesas-soc, Tomi Valkeinen,
	Kieran Bingham, Biju Das, David Airlie, Simona Vetter

Hi Laurent,

These new constructs are so useful, nice to take the time to make use of 
them in existing drivers.

On 2026-05-12 02:56:29 +0300, Laurent Pinchart wrote:
> Replace manual mutex locking and unlocking with guards. This simplifies
> error paths and reduces the amount of code. Limit the changes to
> locations where the guard covers until the end of the function to ease
> review. Scoped guards will be introduced separately.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> ---
>  .../media/platform/renesas/vsp1/vsp1_brx.c    | 26 ++++-------
>  .../media/platform/renesas/vsp1/vsp1_drm.c    |  7 +--
>  .../media/platform/renesas/vsp1/vsp1_entity.c | 19 +++-----
>  .../media/platform/renesas/vsp1/vsp1_histo.c  | 35 +++++----------
>  .../media/platform/renesas/vsp1/vsp1_hsit.c   | 15 +++----
>  .../media/platform/renesas/vsp1/vsp1_rwpf.c   | 44 ++++++-------------
>  .../media/platform/renesas/vsp1/vsp1_sru.c    | 13 ++----
>  .../media/platform/renesas/vsp1/vsp1_uds.c    | 13 ++----
>  .../media/platform/renesas/vsp1/vsp1_uif.c    | 29 ++++--------
>  .../media/platform/renesas/vsp1/vsp1_video.c  | 20 ++++-----
>  .../media/platform/renesas/vsp1/vsp1_wpf.c    | 17 +++----
>  11 files changed, 77 insertions(+), 161 deletions(-)
> 
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_brx.c b/drivers/media/platform/renesas/vsp1/vsp1_brx.c
> index 9d93cb8b8e82..bd2672341386 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_brx.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_brx.c
> @@ -130,15 +130,12 @@ static int brx_set_format(struct v4l2_subdev *subdev,
>  	struct vsp1_brx *brx = to_brx(subdev);
>  	struct v4l2_subdev_state *state;
>  	struct v4l2_mbus_framefmt *format;
> -	int ret = 0;
>  
> -	mutex_lock(&brx->entity.lock);
> +	guard(mutex)(&brx->entity.lock);
>  
>  	state = vsp1_entity_get_state(&brx->entity, sd_state, fmt->which);
> -	if (!state) {
> -		ret = -EINVAL;
> -		goto done;
> -	}
> +	if (!state)
> +		return -EINVAL;
>  
>  	brx_try_format(brx, state, fmt->pad, &fmt->format);
>  
> @@ -166,9 +163,7 @@ static int brx_set_format(struct v4l2_subdev *subdev,
>  		}
>  	}
>  
> -done:
> -	mutex_unlock(&brx->entity.lock);
> -	return ret;
> +	return 0;
>  }
>  
>  static int brx_get_selection(struct v4l2_subdev *subdev,
> @@ -213,7 +208,6 @@ static int brx_set_selection(struct v4l2_subdev *subdev,
>  	struct v4l2_subdev_state *state;
>  	struct v4l2_mbus_framefmt *format;
>  	struct v4l2_rect *compose;
> -	int ret = 0;
>  
>  	if (sel->pad == brx->entity.source_pad)
>  		return -EINVAL;
> @@ -221,13 +215,11 @@ static int brx_set_selection(struct v4l2_subdev *subdev,
>  	if (sel->target != V4L2_SEL_TGT_COMPOSE)
>  		return -EINVAL;
>  
> -	mutex_lock(&brx->entity.lock);
> +	guard(mutex)(&brx->entity.lock);
>  
>  	state = vsp1_entity_get_state(&brx->entity, sd_state, sel->which);
> -	if (!state) {
> -		ret = -EINVAL;
> -		goto done;
> -	}
> +	if (!state)
> +		return -EINVAL;
>  
>  	/*
>  	 * The compose rectangle top left corner must be inside the output
> @@ -248,9 +240,7 @@ static int brx_set_selection(struct v4l2_subdev *subdev,
>  	compose = v4l2_subdev_state_get_compose(state, sel->pad);
>  	*compose = sel->r;
>  
> -done:
> -	mutex_unlock(&brx->entity.lock);
> -	return ret;
> +	return 0;
>  }
>  
>  static const struct v4l2_subdev_pad_ops brx_pad_ops = {
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drm.c b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> index 1f431874064d..1439cf7bfb59 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> @@ -920,7 +920,7 @@ void vsp1_du_atomic_flush(struct device *dev, unsigned int pipe_index,
>  
>  	drm_pipe->crc = cfg->crc;
>  
> -	mutex_lock(&vsp1->drm->lock);
> +	guard(mutex)(&vsp1->drm->lock);
>  
>  	if (cfg->writeback.pixelformat) {
>  		const struct vsp1_du_writeback_config *wb_cfg = &cfg->writeback;
> @@ -929,7 +929,7 @@ void vsp1_du_atomic_flush(struct device *dev, unsigned int pipe_index,
>  						       wb_cfg->pixelformat,
>  						       wb_cfg->pitch);
>  		if (WARN_ON(ret < 0))
> -			goto done;
> +			return;
>  
>  		pipe->output->mem.addr[0] = wb_cfg->mem[0];
>  		pipe->output->mem.addr[1] = wb_cfg->mem[1];
> @@ -942,9 +942,6 @@ void vsp1_du_atomic_flush(struct device *dev, unsigned int pipe_index,
>  	vsp1_pipeline_dump(pipe, "atomic update");
>  
>  	vsp1_du_pipeline_configure(pipe);
> -
> -done:
> -	mutex_unlock(&vsp1->drm->lock);
>  }
>  EXPORT_SYMBOL_GPL(vsp1_du_atomic_flush);
>  
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_entity.c b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
> index 839b75b62ceb..3820ba53b45f 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_entity.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
> @@ -172,9 +172,9 @@ int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev,
>  	if (!state)
>  		return -EINVAL;
>  
> -	mutex_lock(&entity->lock);
> +	guard(mutex)(&entity->lock);
> +
>  	fmt->format = *v4l2_subdev_state_get_format(state, fmt->pad);
> -	mutex_unlock(&entity->lock);
>  
>  	return 0;
>  }
> @@ -308,22 +308,19 @@ int vsp1_subdev_set_pad_format(struct v4l2_subdev *subdev,
>  	struct v4l2_mbus_framefmt *format;
>  	struct v4l2_rect *selection;
>  	unsigned int i;
> -	int ret = 0;
>  
> -	mutex_lock(&entity->lock);
> +	guard(mutex)(&entity->lock);
>  
>  	state = vsp1_entity_get_state(entity, sd_state, fmt->which);
> -	if (!state) {
> -		ret = -EINVAL;
> -		goto done;
> -	}
> +	if (!state)
> +		return -EINVAL;
>  
>  	format = v4l2_subdev_state_get_format(state, fmt->pad);
>  
>  	if (fmt->pad == entity->source_pad) {
>  		/* The output format can't be modified. */
>  		fmt->format = *format;
> -		goto done;
> +		return 0;
>  	}
>  
>  	/*
> @@ -369,9 +366,7 @@ int vsp1_subdev_set_pad_format(struct v4l2_subdev *subdev,
>  	selection->width = format->width;
>  	selection->height = format->height;
>  
> -done:
> -	mutex_unlock(&entity->lock);
> -	return ret;
> +	return 0;
>  }
>  
>  static int vsp1_entity_init_state(struct v4l2_subdev *subdev,
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_histo.c b/drivers/media/platform/renesas/vsp1/vsp1_histo.c
> index 3f87a2c9df0e..72f6ef2fdc4f 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_histo.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_histo.c
> @@ -196,18 +196,15 @@ static int histo_get_selection(struct v4l2_subdev *subdev,
>  	struct v4l2_subdev_state *state;
>  	struct v4l2_mbus_framefmt *format;
>  	struct v4l2_rect *crop;
> -	int ret = 0;
>  
>  	if (sel->pad != HISTO_PAD_SINK)
>  		return -EINVAL;
>  
> -	mutex_lock(&histo->entity.lock);
> +	guard(mutex)(&histo->entity.lock);
>  
>  	state = vsp1_entity_get_state(&histo->entity, sd_state, sel->which);
> -	if (!state) {
> -		ret = -EINVAL;
> -		goto done;
> -	}
> +	if (!state)
> +		return -EINVAL;
>  
>  	switch (sel->target) {
>  	case V4L2_SEL_TGT_COMPOSE_BOUNDS:
> @@ -237,13 +234,10 @@ static int histo_get_selection(struct v4l2_subdev *subdev,
>  		break;
>  
>  	default:
> -		ret = -EINVAL;
> -		break;
> +		return -EINVAL;
>  	}
>  
> -done:
> -	mutex_unlock(&histo->entity.lock);
> -	return ret;
> +	return 0;
>  }
>  
>  static int histo_set_crop(struct v4l2_subdev *subdev,
> @@ -321,29 +315,22 @@ static int histo_set_selection(struct v4l2_subdev *subdev,
>  {
>  	struct vsp1_histogram *histo = subdev_to_histo(subdev);
>  	struct v4l2_subdev_state *state;
> -	int ret;
>  
>  	if (sel->pad != HISTO_PAD_SINK)
>  		return -EINVAL;
>  
> -	mutex_lock(&histo->entity.lock);
> +	guard(mutex)(&histo->entity.lock);
>  
>  	state = vsp1_entity_get_state(&histo->entity, sd_state, sel->which);
> -	if (!state) {
> -		ret = -EINVAL;
> -		goto done;
> -	}
> +	if (!state)
> +		return -EINVAL;
>  
>  	if (sel->target == V4L2_SEL_TGT_CROP)
> -		ret = histo_set_crop(subdev, state, sel);
> +		return histo_set_crop(subdev, state, sel);
>  	else if (sel->target == V4L2_SEL_TGT_COMPOSE)
> -		ret = histo_set_compose(subdev, state, sel);
> +		return histo_set_compose(subdev, state, sel);
>  	else
> -		ret = -EINVAL;
> -
> -done:
> -	mutex_unlock(&histo->entity.lock);
> -	return ret;
> +		return -EINVAL;
>  }
>  
>  static int histo_set_format(struct v4l2_subdev *subdev,
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_hsit.c b/drivers/media/platform/renesas/vsp1/vsp1_hsit.c
> index 830e124beb7b..df069c228243 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_hsit.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_hsit.c
> @@ -115,15 +115,12 @@ static int hsit_set_format(struct v4l2_subdev *subdev,
>  	struct vsp1_hsit *hsit = to_hsit(subdev);
>  	struct v4l2_subdev_state *state;
>  	struct v4l2_mbus_framefmt *format;
> -	int ret = 0;
>  
> -	mutex_lock(&hsit->entity.lock);
> +	guard(mutex)(&hsit->entity.lock);
>  
>  	state = vsp1_entity_get_state(&hsit->entity, sd_state, fmt->which);
> -	if (!state) {
> -		ret = -EINVAL;
> -		goto done;
> -	}
> +	if (!state)
> +		return -EINVAL;
>  
>  	format = v4l2_subdev_state_get_format(state, fmt->pad);
>  
> @@ -133,7 +130,7 @@ static int hsit_set_format(struct v4l2_subdev *subdev,
>  		 * modified.
>  		 */
>  		fmt->format = *format;
> -		goto done;
> +		return 0;
>  	}
>  
>  	format->code = hsit->inverse ? MEDIA_BUS_FMT_AHSV8888_1X32
> @@ -161,9 +158,7 @@ static int hsit_set_format(struct v4l2_subdev *subdev,
>  
>  	vsp1_entity_adjust_color_space(format);
>  
> -done:
> -	mutex_unlock(&hsit->entity.lock);
> -	return ret;
> +	return 0;
>  }
>  
>  static const struct v4l2_subdev_pad_ops hsit_pad_ops = {
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_rwpf.c b/drivers/media/platform/renesas/vsp1/vsp1_rwpf.c
> index c72518b29f84..ced01870acd6 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_rwpf.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_rwpf.c
> @@ -116,15 +116,12 @@ static int vsp1_rwpf_set_format(struct v4l2_subdev *subdev,
>  	struct vsp1_rwpf *rwpf = to_rwpf(subdev);
>  	struct v4l2_subdev_state *state;
>  	struct v4l2_mbus_framefmt *format;
> -	int ret = 0;
>  
> -	mutex_lock(&rwpf->entity.lock);
> +	guard(mutex)(&rwpf->entity.lock);
>  
>  	state = vsp1_entity_get_state(&rwpf->entity, sd_state, fmt->which);
> -	if (!state) {
> -		ret = -EINVAL;
> -		goto done;
> -	}
> +	if (!state)
> +		return -EINVAL;
>  
>  	/* Default to YUV if the requested format is not supported. */
>  	if (fmt->format.code != MEDIA_BUS_FMT_ARGB8888_1X32 &&
> @@ -174,7 +171,7 @@ static int vsp1_rwpf_set_format(struct v4l2_subdev *subdev,
>  		fmt->format = *format;
>  		fmt->format.flags = flags;
>  
> -		goto done;
> +		return 0;
>  	}
>  
>  	format->code = fmt->format.code;
> @@ -213,9 +210,7 @@ static int vsp1_rwpf_set_format(struct v4l2_subdev *subdev,
>  		format->height = fmt->format.width;
>  	}
>  
> -done:
> -	mutex_unlock(&rwpf->entity.lock);
> -	return ret;
> +	return 0;
>  }
>  
>  static int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev,
> @@ -225,7 +220,6 @@ static int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev,
>  	struct vsp1_rwpf *rwpf = to_rwpf(subdev);
>  	struct v4l2_subdev_state *state;
>  	struct v4l2_mbus_framefmt *format;
> -	int ret = 0;
>  
>  	/*
>  	 * Cropping is only supported on the RPF and is implemented on the sink
> @@ -234,13 +228,11 @@ static int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev,
>  	if (rwpf->entity.type == VSP1_ENTITY_WPF || sel->pad != RWPF_PAD_SINK)
>  		return -EINVAL;
>  
> -	mutex_lock(&rwpf->entity.lock);
> +	guard(mutex)(&rwpf->entity.lock);
>  
>  	state = vsp1_entity_get_state(&rwpf->entity, sd_state, sel->which);
> -	if (!state) {
> -		ret = -EINVAL;
> -		goto done;
> -	}
> +	if (!state)
> +		return -EINVAL;
>  
>  	switch (sel->target) {
>  	case V4L2_SEL_TGT_CROP:
> @@ -256,13 +248,10 @@ static int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev,
>  		break;
>  
>  	default:
> -		ret = -EINVAL;
> -		break;
> +		return -EINVAL;
>  	}
>  
> -done:
> -	mutex_unlock(&rwpf->entity.lock);
> -	return ret;
> +	return 0;
>  }
>  
>  static int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev,
> @@ -275,7 +264,6 @@ static int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev,
>  	struct v4l2_subdev_state *state;
>  	struct v4l2_mbus_framefmt *format;
>  	struct v4l2_rect *crop;
> -	int ret = 0;
>  
>  	/*
>  	 * Cropping is only supported on the RPF and is implemented on the sink
> @@ -287,13 +275,11 @@ static int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev,
>  	if (sel->target != V4L2_SEL_TGT_CROP)
>  		return -EINVAL;
>  
> -	mutex_lock(&rwpf->entity.lock);
> +	guard(mutex)(&rwpf->entity.lock);
>  
>  	state = vsp1_entity_get_state(&rwpf->entity, sd_state, sel->which);
> -	if (!state) {
> -		ret = -EINVAL;
> -		goto done;
> -	}
> +	if (!state)
> +		return -EINVAL;
>  
>  	/* Make sure the crop rectangle is entirely contained in the image. */
>  	format = v4l2_subdev_state_get_format(state, RWPF_PAD_SINK);
> @@ -342,9 +328,7 @@ static int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev,
>  	format->width = crop->width;
>  	format->height = crop->height;
>  
> -done:
> -	mutex_unlock(&rwpf->entity.lock);
> -	return ret;
> +	return 0;
>  }
>  
>  static const struct v4l2_subdev_pad_ops vsp1_rwpf_pad_ops = {
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_sru.c b/drivers/media/platform/renesas/vsp1/vsp1_sru.c
> index 94149da0c900..3fd9fde5c724 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_sru.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_sru.c
> @@ -216,15 +216,12 @@ static int sru_set_format(struct v4l2_subdev *subdev,
>  	struct vsp1_sru *sru = to_sru(subdev);
>  	struct v4l2_subdev_state *state;
>  	struct v4l2_mbus_framefmt *format;
> -	int ret = 0;
>  
> -	mutex_lock(&sru->entity.lock);
> +	guard(mutex)(&sru->entity.lock);
>  
>  	state = vsp1_entity_get_state(&sru->entity, sd_state, fmt->which);
> -	if (!state) {
> -		ret = -EINVAL;
> -		goto done;
> -	}
> +	if (!state)
> +		return -EINVAL;
>  
>  	sru_try_format(sru, state, fmt->pad, &fmt->format);
>  
> @@ -239,9 +236,7 @@ static int sru_set_format(struct v4l2_subdev *subdev,
>  		sru_try_format(sru, state, SRU_PAD_SOURCE, format);
>  	}
>  
> -done:
> -	mutex_unlock(&sru->entity.lock);
> -	return ret;
> +	return 0;
>  }
>  
>  static const struct v4l2_subdev_pad_ops sru_pad_ops = {
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_uds.c b/drivers/media/platform/renesas/vsp1/vsp1_uds.c
> index dd4722315c56..9f7bb112929e 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_uds.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_uds.c
> @@ -199,15 +199,12 @@ static int uds_set_format(struct v4l2_subdev *subdev,
>  	struct vsp1_uds *uds = to_uds(subdev);
>  	struct v4l2_subdev_state *state;
>  	struct v4l2_mbus_framefmt *format;
> -	int ret = 0;
>  
> -	mutex_lock(&uds->entity.lock);
> +	guard(mutex)(&uds->entity.lock);
>  
>  	state = vsp1_entity_get_state(&uds->entity, sd_state, fmt->which);
> -	if (!state) {
> -		ret = -EINVAL;
> -		goto done;
> -	}
> +	if (!state)
> +		return -EINVAL;
>  
>  	uds_try_format(uds, state, fmt->pad, &fmt->format);
>  
> @@ -222,9 +219,7 @@ static int uds_set_format(struct v4l2_subdev *subdev,
>  		uds_try_format(uds, state, UDS_PAD_SOURCE, format);
>  	}
>  
> -done:
> -	mutex_unlock(&uds->entity.lock);
> -	return ret;
> +	return 0;
>  }
>  
>  /* -----------------------------------------------------------------------------
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_uif.c b/drivers/media/platform/renesas/vsp1/vsp1_uif.c
> index 3aefe5c9d421..52dbfe58a70d 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_uif.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_uif.c
> @@ -60,18 +60,15 @@ static int uif_get_selection(struct v4l2_subdev *subdev,
>  	struct vsp1_uif *uif = to_uif(subdev);
>  	struct v4l2_subdev_state *state;
>  	struct v4l2_mbus_framefmt *format;
> -	int ret = 0;
>  
>  	if (sel->pad != UIF_PAD_SINK)
>  		return -EINVAL;
>  
> -	mutex_lock(&uif->entity.lock);
> +	guard(mutex)(&uif->entity.lock);
>  
>  	state = vsp1_entity_get_state(&uif->entity, sd_state, sel->which);
> -	if (!state) {
> -		ret = -EINVAL;
> -		goto done;
> -	}
> +	if (!state)
> +		return -EINVAL;
>  
>  	switch (sel->target) {
>  	case V4L2_SEL_TGT_CROP_BOUNDS:
> @@ -88,13 +85,10 @@ static int uif_get_selection(struct v4l2_subdev *subdev,
>  		break;
>  
>  	default:
> -		ret = -EINVAL;
> -		break;
> +		return -EINVAL;
>  	}
>  
> -done:
> -	mutex_unlock(&uif->entity.lock);
> -	return ret;
> +	return 0;
>  }
>  
>  static int uif_set_selection(struct v4l2_subdev *subdev,
> @@ -105,19 +99,16 @@ static int uif_set_selection(struct v4l2_subdev *subdev,
>  	struct v4l2_subdev_state *state;
>  	struct v4l2_mbus_framefmt *format;
>  	struct v4l2_rect *selection;
> -	int ret = 0;
>  
>  	if (sel->pad != UIF_PAD_SINK ||
>  	    sel->target != V4L2_SEL_TGT_CROP)
>  		return -EINVAL;
>  
> -	mutex_lock(&uif->entity.lock);
> +	guard(mutex)(&uif->entity.lock);
>  
>  	state = vsp1_entity_get_state(&uif->entity, sd_state, sel->which);
> -	if (!state) {
> -		ret = -EINVAL;
> -		goto done;
> -	}
> +	if (!state)
> +		return -EINVAL;
>  
>  	/* The crop rectangle must be inside the input frame. */
>  	format = v4l2_subdev_state_get_format(state, UIF_PAD_SINK);
> @@ -133,9 +124,7 @@ static int uif_set_selection(struct v4l2_subdev *subdev,
>  	selection = v4l2_subdev_state_get_crop(state, sel->pad);
>  	*selection = sel->r;
>  
> -done:
> -	mutex_unlock(&uif->entity.lock);
> -	return ret;
> +	return 0;
>  }
>  
>  /* -----------------------------------------------------------------------------
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c
> index a8db94bdb670..4cf2cc370416 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c
> @@ -590,9 +590,9 @@ static void vsp1_video_pipeline_put(struct vsp1_pipeline *pipe)
>  {
>  	struct media_device *mdev = &pipe->output->entity.vsp1->media_dev;
>  
> -	mutex_lock(&mdev->graph_mutex);
> +	guard(mutex)(&mdev->graph_mutex);
> +
>  	kref_put(&pipe->kref, vsp1_video_pipeline_release);
> -	mutex_unlock(&mdev->graph_mutex);
>  }
>  
>  /* -----------------------------------------------------------------------------
> @@ -933,9 +933,9 @@ vsp1_video_get_format(struct file *file, void *fh, struct v4l2_format *format)
>  	if (format->type != video->queue.type)
>  		return -EINVAL;
>  
> -	mutex_lock(&video->lock);
> +	guard(mutex)(&video->lock);
> +
>  	format->fmt.pix_mp = video->rwpf->format;
> -	mutex_unlock(&video->lock);
>  
>  	return 0;
>  }
> @@ -967,19 +967,15 @@ vsp1_video_set_format(struct file *file, void *fh, struct v4l2_format *format)
>  	if (ret < 0)
>  		return ret;
>  
> -	mutex_lock(&video->lock);
> +	guard(mutex)(&video->lock);
>  
> -	if (vb2_is_busy(&video->queue)) {
> -		ret = -EBUSY;
> -		goto done;
> -	}
> +	if (vb2_is_busy(&video->queue))
> +		return -EBUSY;
>  
>  	video->rwpf->format = format->fmt.pix_mp;
>  	video->rwpf->fmtinfo = info;
>  
> -done:
> -	mutex_unlock(&video->lock);
> -	return ret;
> +	return 0;
>  }
>  
>  static int
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> index cd6c5592221b..e7ed3c8e9e90 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> @@ -47,7 +47,6 @@ static int vsp1_wpf_set_rotation(struct vsp1_rwpf *wpf, unsigned int rotation)
>  	struct v4l2_mbus_framefmt *sink_format;
>  	struct v4l2_mbus_framefmt *source_format;
>  	bool rotate;
> -	int ret = 0;
>  
>  	/*
>  	 * Only consider the 0°/180° from/to 90°/270° modifications, the rest
> @@ -58,19 +57,17 @@ static int vsp1_wpf_set_rotation(struct vsp1_rwpf *wpf, unsigned int rotation)
>  		return 0;
>  
>  	/* Changing rotation isn't allowed when buffers are allocated. */
> -	mutex_lock(&video->lock);
> +	guard(mutex)(&video->lock);
>  
> -	if (vb2_is_busy(&video->queue)) {
> -		ret = -EBUSY;
> -		goto done;
> -	}
> +	if (vb2_is_busy(&video->queue))
> +		return -EBUSY;
>  
>  	sink_format = v4l2_subdev_state_get_format(wpf->entity.state,
>  						   RWPF_PAD_SINK);
>  	source_format = v4l2_subdev_state_get_format(wpf->entity.state,
>  						     RWPF_PAD_SOURCE);
>  
> -	mutex_lock(&wpf->entity.lock);
> +	guard(mutex)(&wpf->entity.lock);
>  
>  	if (rotate) {
>  		source_format->width = sink_format->height;
> @@ -82,11 +79,7 @@ static int vsp1_wpf_set_rotation(struct vsp1_rwpf *wpf, unsigned int rotation)
>  
>  	wpf->flip.rotate = rotate;
>  
> -	mutex_unlock(&wpf->entity.lock);
> -
> -done:
> -	mutex_unlock(&video->lock);
> -	return ret;
> +	return 0;
>  }
>  
>  static int vsp1_wpf_s_ctrl(struct v4l2_ctrl *ctrl)
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> 

-- 
Kind Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 06/11] media: renesas: vsp1: Use mutex scoped guards
  2026-05-11 23:56 ` [PATCH 06/11] media: renesas: vsp1: Use mutex scoped guards Laurent Pinchart
@ 2026-05-13 19:24   ` Niklas Söderlund
  0 siblings, 0 replies; 24+ messages in thread
From: Niklas Söderlund @ 2026-05-13 19:24 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, dri-devel, linux-renesas-soc, Tomi Valkeinen,
	Kieran Bingham, Biju Das, David Airlie, Simona Vetter

Hi Laurent,

Thanks for your work.

On 2026-05-12 02:56:30 +0300, Laurent Pinchart wrote:
> Replace remaining manual mutex locking and unlocking with scoped
> guards. This simplifies error paths and reduces the amount of code.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> ---
>  .../media/platform/renesas/vsp1/vsp1_brx.c    |   7 +-
>  .../media/platform/renesas/vsp1/vsp1_drm.c    | 117 ++++++++----------
>  .../media/platform/renesas/vsp1/vsp1_entity.c |   8 +-
>  .../media/platform/renesas/vsp1/vsp1_hgo.c    |  10 +-
>  .../media/platform/renesas/vsp1/vsp1_hgt.c    |  16 +--
>  .../media/platform/renesas/vsp1/vsp1_video.c  |  60 ++++-----
>  6 files changed, 102 insertions(+), 116 deletions(-)
> 
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_brx.c b/drivers/media/platform/renesas/vsp1/vsp1_brx.c
> index bd2672341386..325be30836d7 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_brx.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_brx.c
> @@ -190,9 +190,10 @@ static int brx_get_selection(struct v4l2_subdev *subdev,
>  		if (!state)
>  			return -EINVAL;
>  
> -		mutex_lock(&brx->entity.lock);
> -		sel->r = *v4l2_subdev_state_get_compose(state, sel->pad);
> -		mutex_unlock(&brx->entity.lock);
> +		scoped_guard(mutex, &brx->entity.lock) {
> +			sel->r = *v4l2_subdev_state_get_compose(state, sel->pad);
> +		}
> +
>  		return 0;
>  
>  	default:
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drm.c b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> index 1439cf7bfb59..2b64d9b5a81c 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> @@ -675,43 +675,37 @@ int vsp1_du_enable(struct device *dev, unsigned int pipe_index,
>  		__func__, pipe_index, cfg->width, cfg->height,
>  		pipe->interlaced ? "i" : "");
>  
> -	mutex_lock(&vsp1->drm->lock);
> +	scoped_guard(mutex, &vsp1->drm->lock) {
> +		/* Setup formats through the pipeline. */
> +		ret = vsp1_du_pipeline_setup_inputs(vsp1, pipe);
> +		if (ret < 0)
> +			return ret;
>  
> -	/* Setup formats through the pipeline. */
> -	ret = vsp1_du_pipeline_setup_inputs(vsp1, pipe);
> -	if (ret < 0)
> -		goto unlock;
> +		ret = vsp1_du_pipeline_setup_output(vsp1, pipe);
> +		if (ret < 0)
> +			return ret;
>  
> -	ret = vsp1_du_pipeline_setup_output(vsp1, pipe);
> -	if (ret < 0)
> -		goto unlock;
> +		vsp1_pipeline_dump(pipe, "DU enable");
>  
> -	vsp1_pipeline_dump(pipe, "DU enable");
> +		/* Enable the VSP1. */
> +		ret = vsp1_device_get(vsp1);
> +		if (ret < 0)
> +			return ret;
>  
> -	/* Enable the VSP1. */
> -	ret = vsp1_device_get(vsp1);
> -	if (ret < 0)
> -		goto unlock;
> +		/*
> +		 * Register a callback to allow us to notify the DRM driver of frame
> +		 * completion events.
> +		 */
> +		drm_pipe->du_complete = cfg->callback;
> +		drm_pipe->du_private = cfg->callback_data;
>  
> -	/*
> -	 * Register a callback to allow us to notify the DRM driver of frame
> -	 * completion events.
> -	 */
> -	drm_pipe->du_complete = cfg->callback;
> -	drm_pipe->du_private = cfg->callback_data;
> +		/* Disable the display interrupts. */
> +		vsp1_write(vsp1, VI6_DISP_IRQ_STA(pipe_index), 0);
> +		vsp1_write(vsp1, VI6_DISP_IRQ_ENB(pipe_index), 0);
>  
> -	/* Disable the display interrupts. */
> -	vsp1_write(vsp1, VI6_DISP_IRQ_STA(pipe_index), 0);
> -	vsp1_write(vsp1, VI6_DISP_IRQ_ENB(pipe_index), 0);
> -
> -	/* Configure all entities in the pipeline. */
> -	vsp1_du_pipeline_configure(pipe);
> -
> -unlock:
> -	mutex_unlock(&vsp1->drm->lock);
> -
> -	if (ret < 0)
> -		return ret;
> +		/* Configure all entities in the pipeline. */
> +		vsp1_du_pipeline_configure(pipe);
> +	}
>  
>  	/* Start the pipeline. */
>  	spin_lock_irqsave(&pipe->irqlock, flags);
> @@ -739,7 +733,6 @@ int vsp1_du_disable(struct device *dev, unsigned int pipe_index)
>  	struct vsp1_device *vsp1 = dev_get_drvdata(dev);
>  	struct vsp1_drm_pipeline *drm_pipe;
>  	struct vsp1_pipeline *pipe;
> -	struct vsp1_brx *brx;
>  	unsigned int i;
>  	int ret;
>  
> @@ -749,45 +742,43 @@ int vsp1_du_disable(struct device *dev, unsigned int pipe_index)
>  	drm_pipe = &vsp1->drm->pipe[pipe_index];
>  	pipe = &drm_pipe->pipe;
>  
> -	mutex_lock(&vsp1->drm->lock);
> +	scoped_guard(mutex, &vsp1->drm->lock) {
> +		struct vsp1_brx *brx = to_brx(&pipe->brx->subdev);
>  
> -	brx = to_brx(&pipe->brx->subdev);
> +		ret = vsp1_pipeline_stop(pipe);
> +		if (ret == -ETIMEDOUT)
> +			dev_err(vsp1->dev, "DRM pipeline stop timeout\n");
>  
> -	ret = vsp1_pipeline_stop(pipe);
> -	if (ret == -ETIMEDOUT)
> -		dev_err(vsp1->dev, "DRM pipeline stop timeout\n");
> +		for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) {
> +			struct vsp1_rwpf *rpf = pipe->inputs[i];
>  
> -	for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) {
> -		struct vsp1_rwpf *rpf = pipe->inputs[i];
> +			if (!rpf)
> +				continue;
>  
> -		if (!rpf)
> -			continue;
> +			/*
> +			 * Remove the RPF from the pipe and the list of BRx
> +			 * inputs.
> +			 */
> +			WARN_ON(!rpf->entity.pipe);
> +			rpf->entity.pipe = NULL;
> +			list_del(&rpf->entity.list_pipe);
> +			pipe->inputs[i] = NULL;
>  
> -		/*
> -		 * Remove the RPF from the pipe and the list of BRx
> -		 * inputs.
> -		 */
> -		WARN_ON(!rpf->entity.pipe);
> -		rpf->entity.pipe = NULL;
> -		list_del(&rpf->entity.list_pipe);
> -		pipe->inputs[i] = NULL;
> +			brx->inputs[rpf->brx_input].rpf = NULL;
> +		}
>  
> -		brx->inputs[rpf->brx_input].rpf = NULL;
> +		drm_pipe->du_complete = NULL;
> +		pipe->num_inputs = 0;
> +
> +		dev_dbg(vsp1->dev, "%s: pipe %u: releasing %s\n",
> +			__func__, pipe->lif->index,
> +			BRX_NAME(pipe->brx));
> +
> +		list_del(&pipe->brx->list_pipe);
> +		pipe->brx->pipe = NULL;
> +		pipe->brx = NULL;
>  	}
>  
> -	drm_pipe->du_complete = NULL;
> -	pipe->num_inputs = 0;
> -
> -	dev_dbg(vsp1->dev, "%s: pipe %u: releasing %s\n",
> -		__func__, pipe->lif->index,
> -		BRX_NAME(pipe->brx));
> -
> -	list_del(&pipe->brx->list_pipe);
> -	pipe->brx->pipe = NULL;
> -	pipe->brx = NULL;
> -
> -	mutex_unlock(&vsp1->drm->lock);
> -
>  	vsp1_dlm_reset(pipe->output->dlm);
>  	vsp1_device_put(vsp1);
>  
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_entity.c b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
> index 3820ba53b45f..2ae2a573f0de 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_entity.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
> @@ -216,10 +216,10 @@ int vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev,
>  		if (!state)
>  			return -EINVAL;
>  
> -		mutex_lock(&entity->lock);
> -		format = v4l2_subdev_state_get_format(state, 0);
> -		code->code = format->code;
> -		mutex_unlock(&entity->lock);
> +		scoped_guard(mutex, &entity->lock) {
> +			format = v4l2_subdev_state_get_format(state, 0);
> +			code->code = format->code;
> +		}
>  	}
>  
>  	return 0;
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_hgo.c b/drivers/media/platform/renesas/vsp1/vsp1_hgo.c
> index 2c8ce7175a4e..0ef512e3a94b 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_hgo.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_hgo.c
> @@ -153,11 +153,11 @@ static void hgo_configure_stream(struct vsp1_entity *entity,
>  		       (crop->width << VI6_HGO_SIZE_HSIZE_SHIFT) |
>  		       (crop->height << VI6_HGO_SIZE_VSIZE_SHIFT));
>  
> -	mutex_lock(hgo->ctrls.handler.lock);
> -	hgo->max_rgb = hgo->ctrls.max_rgb->cur.val;
> -	if (hgo->ctrls.num_bins)
> -		hgo->num_bins = hgo_num_bins[hgo->ctrls.num_bins->cur.val];
> -	mutex_unlock(hgo->ctrls.handler.lock);
> +	scoped_guard(mutex, hgo->ctrls.handler.lock) {
> +		hgo->max_rgb = hgo->ctrls.max_rgb->cur.val;
> +		if (hgo->ctrls.num_bins)
> +			hgo->num_bins = hgo_num_bins[hgo->ctrls.num_bins->cur.val];
> +	}
>  
>  	hratio = crop->width * 2 / compose->width / 3;
>  	vratio = crop->height * 2 / compose->height / 3;
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_hgt.c b/drivers/media/platform/renesas/vsp1/vsp1_hgt.c
> index 858f330d44fa..78b5a9201c70 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_hgt.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_hgt.c
> @@ -152,15 +152,15 @@ static void hgt_configure_stream(struct vsp1_entity *entity,
>  		       (crop->width << VI6_HGT_SIZE_HSIZE_SHIFT) |
>  		       (crop->height << VI6_HGT_SIZE_VSIZE_SHIFT));
>  
> -	mutex_lock(hgt->ctrls.lock);
> -	for (i = 0; i < HGT_NUM_HUE_AREAS; ++i) {
> -		lower = hgt->hue_areas[i*2 + 0];
> -		upper = hgt->hue_areas[i*2 + 1];
> -		vsp1_hgt_write(hgt, dlb, VI6_HGT_HUE_AREA(i),
> -			       (lower << VI6_HGT_HUE_AREA_LOWER_SHIFT) |
> -			       (upper << VI6_HGT_HUE_AREA_UPPER_SHIFT));
> +	scoped_guard(mutex, hgt->ctrls.lock) {
> +		for (i = 0; i < HGT_NUM_HUE_AREAS; ++i) {
> +			lower = hgt->hue_areas[i*2 + 0];
> +			upper = hgt->hue_areas[i*2 + 1];
> +			vsp1_hgt_write(hgt, dlb, VI6_HGT_HUE_AREA(i),
> +				       (lower << VI6_HGT_HUE_AREA_LOWER_SHIFT) |
> +				       (upper << VI6_HGT_HUE_AREA_UPPER_SHIFT));
> +		}
>  	}
> -	mutex_unlock(hgt->ctrls.lock);
>  
>  	hratio = crop->width * 2 / compose->width / 3;
>  	vratio = crop->height * 2 / compose->height / 3;
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c
> index 4cf2cc370416..138d4e08eee9 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c
> @@ -810,22 +810,21 @@ static int vsp1_video_start_streaming(struct vb2_queue *vq, unsigned int count)
>  	unsigned long flags;
>  	int ret;
>  
> -	mutex_lock(&pipe->lock);
> -	if (pipe->stream_count == pipe->num_inputs) {
> -		ret = vsp1_video_setup_pipeline(pipe);
> -		if (ret < 0) {
> -			vsp1_video_release_buffers(video);
> -			vsp1_video_cleanup_pipeline(pipe);
> -			mutex_unlock(&pipe->lock);
> -			return ret;
> +	scoped_guard(mutex, &pipe->lock) {
> +		if (pipe->stream_count == pipe->num_inputs) {
> +			ret = vsp1_video_setup_pipeline(pipe);
> +			if (ret < 0) {
> +				vsp1_video_release_buffers(video);
> +				vsp1_video_cleanup_pipeline(pipe);
> +				return ret;
> +			}
> +
> +			start_pipeline = true;
>  		}
>  
> -		start_pipeline = true;
> +		pipe->stream_count++;
>  	}
>  
> -	pipe->stream_count++;
> -	mutex_unlock(&pipe->lock);
> -
>  	/*
>  	 * vsp1_pipeline_ready() is not sufficient to establish that all streams
>  	 * are prepared and the pipeline is configured, as multiple streams
> @@ -859,16 +858,17 @@ static void vsp1_video_stop_streaming(struct vb2_queue *vq)
>  	pipe->buffers_ready &= ~(1 << video->pipe_index);
>  	spin_unlock_irqrestore(&video->irqlock, flags);
>  
> -	mutex_lock(&pipe->lock);
> -	if (--pipe->stream_count == pipe->num_inputs) {
> -		/* Stop the pipeline. */
> -		ret = vsp1_pipeline_stop(pipe);
> -		if (ret == -ETIMEDOUT)
> -			dev_err(video->vsp1->dev, "pipeline stop timeout\n");
> +	scoped_guard(mutex, &pipe->lock) {
> +		if (--pipe->stream_count == pipe->num_inputs) {
> +			/* Stop the pipeline. */
> +			ret = vsp1_pipeline_stop(pipe);
> +			if (ret == -ETIMEDOUT)
> +				dev_err(video->vsp1->dev,
> +					"pipeline stop timeout\n");
>  
> -		vsp1_video_cleanup_pipeline(pipe);
> +			vsp1_video_cleanup_pipeline(pipe);
> +		}
>  	}
> -	mutex_unlock(&pipe->lock);
>  
>  	video_device_pipeline_stop(&video->video);
>  	vsp1_video_release_buffers(video);
> @@ -995,22 +995,16 @@ vsp1_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
>  	 * touching an entity in the pipeline can be activated or deactivated
>  	 * once streaming is started.
>  	 */
> -	mutex_lock(&mdev->graph_mutex);
> +	scoped_guard(mutex, &mdev->graph_mutex) {
> +		pipe = vsp1_video_pipeline_get(video);
> +		if (IS_ERR(pipe))
> +			return PTR_ERR(pipe);
>  
> -	pipe = vsp1_video_pipeline_get(video);
> -	if (IS_ERR(pipe)) {
> -		mutex_unlock(&mdev->graph_mutex);
> -		return PTR_ERR(pipe);
> +		ret = __video_device_pipeline_start(&video->video, &pipe->pipe);
> +		if (ret < 0)
> +			goto err_pipe;
>  	}
>  
> -	ret = __video_device_pipeline_start(&video->video, &pipe->pipe);
> -	if (ret < 0) {
> -		mutex_unlock(&mdev->graph_mutex);
> -		goto err_pipe;
> -	}
> -
> -	mutex_unlock(&mdev->graph_mutex);
> -
>  	/*
>  	 * Verify that the configured format matches the output of the connected
>  	 * subdev.
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> 

-- 
Kind Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 07/11] media: renesas: vsp1: Use spinlock guards
  2026-05-11 23:56 ` [PATCH 07/11] media: renesas: vsp1: Use spinlock guards Laurent Pinchart
@ 2026-05-13 19:29   ` Niklas Söderlund
  0 siblings, 0 replies; 24+ messages in thread
From: Niklas Söderlund @ 2026-05-13 19:29 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, dri-devel, linux-renesas-soc, Tomi Valkeinen,
	Kieran Bingham, Biju Das, David Airlie, Simona Vetter

Hi Laurent,

Thanks for your patch.

On 2026-05-12 02:56:31 +0300, Laurent Pinchart wrote:
> Replace manual spinlock locking and unlocking with guards. This
> simplifies error paths and reduces the amount of code. Limit the changes
> to locations where the guard covers until the end of the function to
> ease review. Scoped guards will be introduced separately.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> ---
>  drivers/media/platform/renesas/vsp1/vsp1_dl.c | 49 ++++++-------------
>  .../media/platform/renesas/vsp1/vsp1_histo.c  | 20 +++-----
>  .../media/platform/renesas/vsp1/vsp1_pipe.c   |  9 +---
>  .../media/platform/renesas/vsp1/vsp1_video.c  | 14 ++----
>  .../media/platform/renesas/vsp1/vsp1_wpf.c    |  4 +-
>  5 files changed, 31 insertions(+), 65 deletions(-)
> 
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_dl.c b/drivers/media/platform/renesas/vsp1/vsp1_dl.c
> index 6c5578d9d2de..4a19ff1437b0 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_dl.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_dl.c
> @@ -336,9 +336,8 @@ void vsp1_dl_body_pool_destroy(struct vsp1_dl_body_pool *pool)
>  struct vsp1_dl_body *vsp1_dl_body_get(struct vsp1_dl_body_pool *pool)
>  {
>  	struct vsp1_dl_body *dlb = NULL;
> -	unsigned long flags;
>  
> -	spin_lock_irqsave(&pool->lock, flags);
> +	guard(spinlock_irqsave)(&pool->lock);
>  
>  	if (!list_empty(&pool->free)) {
>  		dlb = list_first_entry(&pool->free, struct vsp1_dl_body, free);
> @@ -346,8 +345,6 @@ struct vsp1_dl_body *vsp1_dl_body_get(struct vsp1_dl_body_pool *pool)
>  		refcount_set(&dlb->refcnt, 1);
>  	}
>  
> -	spin_unlock_irqrestore(&pool->lock, flags);
> -
>  	return dlb;
>  }
>  
> @@ -359,8 +356,6 @@ struct vsp1_dl_body *vsp1_dl_body_get(struct vsp1_dl_body_pool *pool)
>   */
>  void vsp1_dl_body_put(struct vsp1_dl_body *dlb)
>  {
> -	unsigned long flags;
> -
>  	if (!dlb)
>  		return;
>  
> @@ -369,9 +364,9 @@ void vsp1_dl_body_put(struct vsp1_dl_body *dlb)
>  
>  	dlb->num_entries = 0;
>  
> -	spin_lock_irqsave(&dlb->pool->lock, flags);
> +	guard(spinlock_irqsave)(&dlb->pool->lock);
> +
>  	list_add_tail(&dlb->free, &dlb->pool->free);
> -	spin_unlock_irqrestore(&dlb->pool->lock, flags);
>  }
>  
>  /**
> @@ -493,9 +488,8 @@ static
>  struct vsp1_dl_ext_cmd *vsp1_dl_ext_cmd_get(struct vsp1_dl_cmd_pool *pool)
>  {
>  	struct vsp1_dl_ext_cmd *cmd = NULL;
> -	unsigned long flags;
>  
> -	spin_lock_irqsave(&pool->lock, flags);
> +	guard(spinlock_irqsave)(&pool->lock);
>  
>  	if (!list_empty(&pool->free)) {
>  		cmd = list_first_entry(&pool->free, struct vsp1_dl_ext_cmd,
> @@ -503,24 +497,20 @@ struct vsp1_dl_ext_cmd *vsp1_dl_ext_cmd_get(struct vsp1_dl_cmd_pool *pool)
>  		list_del(&cmd->free);
>  	}
>  
> -	spin_unlock_irqrestore(&pool->lock, flags);
> -
>  	return cmd;
>  }
>  
>  static void vsp1_dl_ext_cmd_put(struct vsp1_dl_ext_cmd *cmd)
>  {
> -	unsigned long flags;
> -
>  	if (!cmd)
>  		return;
>  
>  	/* Reset flags, these mark data usage. */
>  	cmd->flags = 0;
>  
> -	spin_lock_irqsave(&cmd->pool->lock, flags);
> +	guard(spinlock_irqsave)(&cmd->pool->lock);
> +
>  	list_add_tail(&cmd->free, &cmd->pool->free);
> -	spin_unlock_irqrestore(&cmd->pool->lock, flags);
>  }
>  
>  static void vsp1_dl_ext_cmd_pool_destroy(struct vsp1_dl_cmd_pool *pool)
> @@ -611,11 +601,10 @@ static void vsp1_dl_list_free(struct vsp1_dl_list *dl)
>  struct vsp1_dl_list *vsp1_dl_list_get(struct vsp1_dl_manager *dlm)
>  {
>  	struct vsp1_dl_list *dl = NULL;
> -	unsigned long flags;
>  
>  	lockdep_assert_not_held(&dlm->lock);
>  
> -	spin_lock_irqsave(&dlm->lock, flags);
> +	guard(spinlock_irqsave)(&dlm->lock);
>  
>  	if (!list_empty(&dlm->free)) {
>  		dl = list_first_entry(&dlm->free, struct vsp1_dl_list, list);
> @@ -629,8 +618,6 @@ struct vsp1_dl_list *vsp1_dl_list_get(struct vsp1_dl_manager *dlm)
>  		dl->allocated = true;
>  	}
>  
> -	spin_unlock_irqrestore(&dlm->lock, flags);
> -
>  	return dl;
>  }
>  
> @@ -690,14 +677,12 @@ static void __vsp1_dl_list_put(struct vsp1_dl_list *dl)
>   */
>  void vsp1_dl_list_put(struct vsp1_dl_list *dl)
>  {
> -	unsigned long flags;
> -
>  	if (!dl)
>  		return;
>  
> -	spin_lock_irqsave(&dl->dlm->lock, flags);
> +	guard(spinlock_irqsave)(&dl->dlm->lock);
> +
>  	__vsp1_dl_list_put(dl);
> -	spin_unlock_irqrestore(&dl->dlm->lock, flags);
>  }
>  
>  /**
> @@ -937,7 +922,6 @@ void vsp1_dl_list_commit(struct vsp1_dl_list *dl, unsigned int dl_flags)
>  {
>  	struct vsp1_dl_manager *dlm = dl->dlm;
>  	struct vsp1_dl_list *dl_next;
> -	unsigned long flags;
>  
>  	/* Fill the header for the head and chained display lists. */
>  	vsp1_dl_list_fill_header(dl, list_empty(&dl->chain));
> @@ -950,14 +934,12 @@ void vsp1_dl_list_commit(struct vsp1_dl_list *dl, unsigned int dl_flags)
>  
>  	dl->flags = dl_flags & ~VSP1_DL_FRAME_END_COMPLETED;
>  
> -	spin_lock_irqsave(&dlm->lock, flags);
> +	guard(spinlock_irqsave)(&dlm->lock);
>  
>  	if (dlm->singleshot)
>  		vsp1_dl_list_commit_singleshot(dl);
>  	else
>  		vsp1_dl_list_commit_continuous(dl);
> -
> -	spin_unlock_irqrestore(&dlm->lock, flags);
>  }
>  
>  /* -----------------------------------------------------------------------------
> @@ -991,7 +973,7 @@ unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm)
>  	u32 status = vsp1_read(vsp1, VI6_STATUS);
>  	unsigned int flags = 0;
>  
> -	spin_lock(&dlm->lock);
> +	guard(spinlock)(&dlm->lock);
>  
>  	/*
>  	 * The mem-to-mem pipelines work in single-shot mode. No new display
> @@ -1001,7 +983,7 @@ unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm)
>  		__vsp1_dl_list_put(dlm->active);
>  		dlm->active = NULL;
>  		flags |= VSP1_DL_FRAME_END_COMPLETED;
> -		goto done;
> +		return flags;
>  	}
>  
>  	/*
> @@ -1011,7 +993,7 @@ unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm)
>  	 * and retry.
>  	 */
>  	if (vsp1_dl_list_hw_update_pending(dlm))
> -		goto done;
> +		return flags;
>  
>  	/*
>  	 * Progressive streams report only TOP fields. If we have a BOTTOM
> @@ -1019,7 +1001,7 @@ unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm)
>  	 * next frame end interrupt.
>  	 */
>  	if (status & VI6_STATUS_FLD_STD(dlm->index))
> -		goto done;
> +		return flags;
>  
>  	/*
>  	 * If the active display list has the writeback flag set, the frame
> @@ -1058,9 +1040,6 @@ unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm)
>  		dlm->pending = NULL;
>  	}
>  
> -done:
> -	spin_unlock(&dlm->lock);
> -
>  	return flags;
>  }
>  
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_histo.c b/drivers/media/platform/renesas/vsp1/vsp1_histo.c
> index 72f6ef2fdc4f..97dbfb93abe9 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_histo.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_histo.c
> @@ -35,20 +35,18 @@ to_vsp1_histogram_buffer(struct vb2_v4l2_buffer *vbuf)
>  struct vsp1_histogram_buffer *
>  vsp1_histogram_buffer_get(struct vsp1_histogram *histo)
>  {
> -	struct vsp1_histogram_buffer *buf = NULL;
> +	struct vsp1_histogram_buffer *buf;
>  
> -	spin_lock(&histo->irqlock);
> +	guard(spinlock)(&histo->irqlock);
>  
>  	if (list_empty(&histo->irqqueue))
> -		goto done;
> +		return NULL;
>  
>  	buf = list_first_entry(&histo->irqqueue, struct vsp1_histogram_buffer,
>  			       queue);
>  	list_del(&buf->queue);
>  	histo->readout = true;
>  
> -done:
> -	spin_unlock(&histo->irqlock);
>  	return buf;
>  }
>  
> @@ -68,10 +66,10 @@ void vsp1_histogram_buffer_complete(struct vsp1_histogram *histo,
>  	vb2_set_plane_payload(&buf->buf.vb2_buf, 0, size);
>  	vb2_buffer_done(&buf->buf.vb2_buf, VB2_BUF_STATE_DONE);
>  
> -	spin_lock(&histo->irqlock);
> +	guard(spinlock)(&histo->irqlock);
> +
>  	histo->readout = false;
>  	wake_up(&histo->wait_queue);
> -	spin_unlock(&histo->irqlock);
>  }
>  
>  /* -----------------------------------------------------------------------------
> @@ -123,9 +121,9 @@ static void histo_buffer_queue(struct vb2_buffer *vb)
>  	struct vsp1_histogram *histo = vb2_get_drv_priv(vb->vb2_queue);
>  	struct vsp1_histogram_buffer *buf = to_vsp1_histogram_buffer(vbuf);
>  
> -	spin_lock_irq(&histo->irqlock);
> +	guard(spinlock_irq)(&histo->irqlock);
> +
>  	list_add_tail(&buf->queue, &histo->irqqueue);
> -	spin_unlock_irq(&histo->irqlock);
>  }
>  
>  static int histo_start_streaming(struct vb2_queue *vq, unsigned int count)
> @@ -138,7 +136,7 @@ static void histo_stop_streaming(struct vb2_queue *vq)
>  	struct vsp1_histogram *histo = vb2_get_drv_priv(vq);
>  	struct vsp1_histogram_buffer *buffer;
>  
> -	spin_lock_irq(&histo->irqlock);
> +	guard(spinlock_irq)(&histo->irqlock);
>  
>  	/* Remove all buffers from the IRQ queue. */
>  	list_for_each_entry(buffer, &histo->irqqueue, queue)
> @@ -147,8 +145,6 @@ static void histo_stop_streaming(struct vb2_queue *vq)
>  
>  	/* Wait for the buffer being read out (if any) to complete. */
>  	wait_event_lock_irq(histo->wait_queue, !histo->readout, histo->irqlock);
> -
> -	spin_unlock_irq(&histo->irqlock);
>  }
>  
>  static const struct vb2_ops histo_video_queue_qops = {
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
> index aaec1aa15091..924e87f91903 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
> @@ -487,14 +487,9 @@ void vsp1_pipeline_run(struct vsp1_pipeline *pipe)
>  
>  bool vsp1_pipeline_stopped(struct vsp1_pipeline *pipe)
>  {
> -	unsigned long flags;
> -	bool stopped;
> +	guard(spinlock_irqsave)(&pipe->irqlock);
>  
> -	spin_lock_irqsave(&pipe->irqlock, flags);
> -	stopped = pipe->state == VSP1_PIPELINE_STOPPED;
> -	spin_unlock_irqrestore(&pipe->irqlock, flags);
> -
> -	return stopped;
> +	return pipe->state == VSP1_PIPELINE_STOPPED;
>  }
>  
>  int vsp1_pipeline_stop(struct vsp1_pipeline *pipe)
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c
> index 138d4e08eee9..1e5d9e42cea0 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c
> @@ -667,7 +667,7 @@ static void vsp1_video_buffer_queue(struct vb2_buffer *vb)
>  	if (!empty)
>  		return;
>  
> -	spin_lock_irqsave(&pipe->irqlock, flags);
> +	guard(spinlock_irqsave)(&pipe->irqlock);
>  
>  	video->rwpf->mem = buf->mem;
>  	pipe->buffers_ready |= 1 << video->pipe_index;
> @@ -675,8 +675,6 @@ static void vsp1_video_buffer_queue(struct vb2_buffer *vb)
>  	if (vb2_start_streaming_called(&video->queue) &&
>  	    vsp1_pipeline_ready(pipe))
>  		vsp1_video_pipeline_run(pipe);
> -
> -	spin_unlock_irqrestore(&pipe->irqlock, flags);
>  }
>  
>  static int vsp1_video_pipeline_setup_partitions(struct vsp1_pipeline *pipe)
> @@ -778,14 +776,13 @@ static int vsp1_video_setup_pipeline(struct vsp1_pipeline *pipe)
>  static void vsp1_video_release_buffers(struct vsp1_video *video)
>  {
>  	struct vsp1_vb2_buffer *buffer;
> -	unsigned long flags;
>  
>  	/* Remove all buffers from the IRQ queue. */
> -	spin_lock_irqsave(&video->irqlock, flags);
> +	guard(spinlock_irqsave)(&video->irqlock);
> +
>  	list_for_each_entry(buffer, &video->irqqueue, queue)
>  		vb2_buffer_done(&buffer->buf.vb2_buf, VB2_BUF_STATE_ERROR);
>  	INIT_LIST_HEAD(&video->irqqueue);
> -	spin_unlock_irqrestore(&video->irqlock, flags);
>  }
>  
>  static void vsp1_video_cleanup_pipeline(struct vsp1_pipeline *pipe)
> @@ -807,7 +804,6 @@ static int vsp1_video_start_streaming(struct vb2_queue *vq, unsigned int count)
>  	struct vsp1_video *video = vb2_get_drv_priv(vq);
>  	struct vsp1_pipeline *pipe = video->rwpf->entity.pipe;
>  	bool start_pipeline = false;
> -	unsigned long flags;
>  	int ret;
>  
>  	scoped_guard(mutex, &pipe->lock) {
> @@ -835,10 +831,10 @@ static int vsp1_video_start_streaming(struct vb2_queue *vq, unsigned int count)
>  	if (!start_pipeline)
>  		return 0;
>  
> -	spin_lock_irqsave(&pipe->irqlock, flags);
> +	guard(spinlock_irqsave)(&pipe->irqlock);
> +
>  	if (vsp1_pipeline_ready(pipe))
>  		vsp1_video_pipeline_run(pipe);
> -	spin_unlock_irqrestore(&pipe->irqlock, flags);
>  
>  	return 0;
>  }
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> index e7ed3c8e9e90..327c7457126f 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> @@ -111,9 +111,9 @@ static int vsp1_wpf_s_ctrl(struct v4l2_ctrl *ctrl)
>  	if (rotation == 180 || rotation == 270)
>  		flip ^= BIT(WPF_CTRL_VFLIP) | BIT(WPF_CTRL_HFLIP);
>  
> -	spin_lock_irq(&wpf->flip.lock);
> +	guard(spinlock_irq)(&wpf->flip.lock);
> +
>  	wpf->flip.pending = flip;
> -	spin_unlock_irq(&wpf->flip.lock);
>  
>  	return 0;
>  }
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> 

-- 
Kind Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 08/11] media: renesas: vsp1: Use spinlock scoped guards
  2026-05-11 23:56 ` [PATCH 08/11] media: renesas: vsp1: Use spinlock scoped guards Laurent Pinchart
@ 2026-05-13 19:37   ` Niklas Söderlund
  0 siblings, 0 replies; 24+ messages in thread
From: Niklas Söderlund @ 2026-05-13 19:37 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, dri-devel, linux-renesas-soc, Tomi Valkeinen,
	Kieran Bingham, Biju Das, David Airlie, Simona Vetter

Hi Laurent,

Thanks for your patch.

On 2026-05-12 02:56:32 +0300, Laurent Pinchart wrote:
> Replace remaining manual spinlock locking and unlocking with scoped
> guards. This simplifies error paths and reduces the amount of code.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>


> ---
>  .../media/platform/renesas/vsp1/vsp1_clu.c    | 15 +++--
>  drivers/media/platform/renesas/vsp1/vsp1_dl.c | 14 ++---
>  .../media/platform/renesas/vsp1/vsp1_drm.c    |  7 +--
>  .../media/platform/renesas/vsp1/vsp1_lut.c    | 15 +++--
>  .../media/platform/renesas/vsp1/vsp1_pipe.c   | 15 +++--
>  .../media/platform/renesas/vsp1/vsp1_video.c  | 59 ++++++++-----------
>  .../media/platform/renesas/vsp1/vsp1_wpf.c    |  9 ++-
>  7 files changed, 59 insertions(+), 75 deletions(-)
> 
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_clu.c b/drivers/media/platform/renesas/vsp1/vsp1_clu.c
> index 04c466c4da81..a6e4bcab5101 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_clu.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_clu.c
> @@ -53,9 +53,9 @@ static int clu_set_table(struct vsp1_clu *clu, struct v4l2_ctrl *ctrl)
>  	for (i = 0; i < CLU_SIZE; ++i)
>  		vsp1_dl_body_write(dlb, VI6_CLU_DATA, ctrl->p_new.p_u32[i]);
>  
> -	spin_lock_irq(&clu->lock);
> -	swap(clu->clu, dlb);
> -	spin_unlock_irq(&clu->lock);
> +	scoped_guard(spinlock_irq, &clu->lock) {
> +		swap(clu->clu, dlb);
> +	}
>  
>  	vsp1_dl_body_put(dlb);
>  	return 0;
> @@ -162,7 +162,6 @@ static void clu_configure_frame(struct vsp1_entity *entity,
>  {
>  	struct vsp1_clu *clu = to_clu(&entity->subdev);
>  	struct vsp1_dl_body *clu_dlb;
> -	unsigned long flags;
>  	u32 ctrl = VI6_CLU_CTRL_AAI | VI6_CLU_CTRL_MVS | VI6_CLU_CTRL_EN;
>  
>  	/* 2D mode can only be used with the YCbCr pixel encoding. */
> @@ -173,10 +172,10 @@ static void clu_configure_frame(struct vsp1_entity *entity,
>  
>  	vsp1_clu_write(clu, dlb, VI6_CLU_CTRL, ctrl);
>  
> -	spin_lock_irqsave(&clu->lock, flags);
> -	clu_dlb = clu->clu;
> -	clu->clu = NULL;
> -	spin_unlock_irqrestore(&clu->lock, flags);
> +	scoped_guard(spinlock_irqsave, &clu->lock) {
> +		clu_dlb = clu->clu;
> +		clu->clu = NULL;
> +	}
>  
>  	if (clu_dlb) {
>  		vsp1_dl_list_add_body(dl, clu_dlb);
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_dl.c b/drivers/media/platform/renesas/vsp1/vsp1_dl.c
> index 4a19ff1437b0..3dc74fed91dc 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_dl.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_dl.c
> @@ -1064,17 +1064,15 @@ void vsp1_dlm_setup(struct vsp1_device *vsp1)
>  
>  void vsp1_dlm_reset(struct vsp1_dl_manager *dlm)
>  {
> -	unsigned long flags;
>  	size_t list_count;
>  
> -	spin_lock_irqsave(&dlm->lock, flags);
> +	scoped_guard(spinlock_irqsave, &dlm->lock) {
> +		__vsp1_dl_list_put(dlm->active);
> +		__vsp1_dl_list_put(dlm->queued);
> +		__vsp1_dl_list_put(dlm->pending);
>  
> -	__vsp1_dl_list_put(dlm->active);
> -	__vsp1_dl_list_put(dlm->queued);
> -	__vsp1_dl_list_put(dlm->pending);
> -
> -	list_count = list_count_nodes(&dlm->free);
> -	spin_unlock_irqrestore(&dlm->lock, flags);
> +		list_count = list_count_nodes(&dlm->free);
> +	}
>  
>  	WARN_ON_ONCE(list_count != dlm->list_count);
>  
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drm.c b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> index 2b64d9b5a81c..f6fbd3475329 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> @@ -655,7 +655,6 @@ int vsp1_du_enable(struct device *dev, unsigned int pipe_index,
>  	struct vsp1_device *vsp1 = dev_get_drvdata(dev);
>  	struct vsp1_drm_pipeline *drm_pipe;
>  	struct vsp1_pipeline *pipe;
> -	unsigned long flags;
>  	int ret;
>  
>  	if (pipe_index >= vsp1->info->lif_count)
> @@ -708,9 +707,9 @@ int vsp1_du_enable(struct device *dev, unsigned int pipe_index,
>  	}
>  
>  	/* Start the pipeline. */
> -	spin_lock_irqsave(&pipe->irqlock, flags);
> -	vsp1_pipeline_run(pipe);
> -	spin_unlock_irqrestore(&pipe->irqlock, flags);
> +	scoped_guard(spinlock_irqsave, &pipe->irqlock) {
> +		vsp1_pipeline_run(pipe);
> +	}
>  
>  	dev_dbg(vsp1->dev, "%s: pipeline enabled\n", __func__);
>  
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_lut.c b/drivers/media/platform/renesas/vsp1/vsp1_lut.c
> index 94bdedcc5c92..a22c31e17cb7 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_lut.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_lut.c
> @@ -50,9 +50,9 @@ static int lut_set_table(struct vsp1_lut *lut, struct v4l2_ctrl *ctrl)
>  		vsp1_dl_body_write(dlb, VI6_LUT_TABLE + 4 * i,
>  				       ctrl->p_new.p_u32[i]);
>  
> -	spin_lock_irq(&lut->lock);
> -	swap(lut->lut, dlb);
> -	spin_unlock_irq(&lut->lock);
> +	scoped_guard(spinlock_irq, &lut->lock) {
> +		swap(lut->lut, dlb);
> +	}
>  
>  	vsp1_dl_body_put(dlb);
>  	return 0;
> @@ -132,12 +132,11 @@ static void lut_configure_frame(struct vsp1_entity *entity,
>  {
>  	struct vsp1_lut *lut = to_lut(&entity->subdev);
>  	struct vsp1_dl_body *lut_dlb;
> -	unsigned long flags;
>  
> -	spin_lock_irqsave(&lut->lock, flags);
> -	lut_dlb = lut->lut;
> -	lut->lut = NULL;
> -	spin_unlock_irqrestore(&lut->lock, flags);
> +	scoped_guard(spinlock_irqsave, &lut->lock) {
> +		lut_dlb = lut->lut;
> +		lut->lut = NULL;
> +	}
>  
>  	if (lut_dlb) {
>  		vsp1_dl_list_add_body(dl, lut_dlb);
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
> index 924e87f91903..f9c7c75a7ad0 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
> @@ -496,7 +496,6 @@ int vsp1_pipeline_stop(struct vsp1_pipeline *pipe)
>  {
>  	struct vsp1_device *vsp1 = pipe->output->entity.vsp1;
>  	struct vsp1_entity *entity;
> -	unsigned long flags;
>  	int ret;
>  
>  	if (pipe->lif) {
> @@ -510,16 +509,16 @@ int vsp1_pipeline_stop(struct vsp1_pipeline *pipe)
>  
>  		ret = vsp1_reset_wpf(vsp1, pipe->output->entity.index);
>  		if (ret == 0) {
> -			spin_lock_irqsave(&pipe->irqlock, flags);
> -			pipe->state = VSP1_PIPELINE_STOPPED;
> -			spin_unlock_irqrestore(&pipe->irqlock, flags);
> +			scoped_guard(spinlock_irqsave, &pipe->irqlock) {
> +				pipe->state = VSP1_PIPELINE_STOPPED;
> +			}
>  		}
>  	} else {
>  		/* Otherwise just request a stop and wait. */
> -		spin_lock_irqsave(&pipe->irqlock, flags);
> -		if (pipe->state == VSP1_PIPELINE_RUNNING)
> -			pipe->state = VSP1_PIPELINE_STOPPING;
> -		spin_unlock_irqrestore(&pipe->irqlock, flags);
> +		scoped_guard(spinlock_irqsave, &pipe->irqlock) {
> +			if (pipe->state == VSP1_PIPELINE_RUNNING)
> +				pipe->state = VSP1_PIPELINE_STOPPING;
> +		}
>  
>  		ret = wait_event_timeout(pipe->wq, vsp1_pipeline_stopped(pipe),
>  					 msecs_to_jiffies(500));
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c
> index 1e5d9e42cea0..b0eae54273a0 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c
> @@ -209,26 +209,21 @@ vsp1_video_complete_buffer(struct vsp1_video *video)
>  	struct vsp1_pipeline *pipe = video->rwpf->entity.pipe;
>  	struct vsp1_vb2_buffer *next = NULL;
>  	struct vsp1_vb2_buffer *done;
> -	unsigned long flags;
>  	unsigned int i;
>  
> -	spin_lock_irqsave(&video->irqlock, flags);
> +	scoped_guard(spinlock_irqsave, &video->irqlock) {
> +		if (list_empty(&video->irqqueue))
> +			return NULL;
>  
> -	if (list_empty(&video->irqqueue)) {
> -		spin_unlock_irqrestore(&video->irqlock, flags);
> -		return NULL;
> -	}
> -
> -	done = list_first_entry(&video->irqqueue,
> -				struct vsp1_vb2_buffer, queue);
> -
> -	list_del(&done->queue);
> -
> -	if (!list_empty(&video->irqqueue))
> -		next = list_first_entry(&video->irqqueue,
> +		done = list_first_entry(&video->irqqueue,
>  					struct vsp1_vb2_buffer, queue);
>  
> -	spin_unlock_irqrestore(&video->irqlock, flags);
> +		list_del(&done->queue);
> +
> +		if (!list_empty(&video->irqqueue))
> +			next = list_first_entry(&video->irqqueue,
> +						struct vsp1_vb2_buffer, queue);
> +	}
>  
>  	done->buf.sequence = pipe->sequence;
>  	done->buf.vb2_buf.timestamp = ktime_get_ns();
> @@ -656,13 +651,12 @@ static void vsp1_video_buffer_queue(struct vb2_buffer *vb)
>  	struct vsp1_video *video = vb2_get_drv_priv(vb->vb2_queue);
>  	struct vsp1_pipeline *pipe = video->rwpf->entity.pipe;
>  	struct vsp1_vb2_buffer *buf = to_vsp1_vb2_buffer(vbuf);
> -	unsigned long flags;
>  	bool empty;
>  
> -	spin_lock_irqsave(&video->irqlock, flags);
> -	empty = list_empty(&video->irqqueue);
> -	list_add_tail(&buf->queue, &video->irqqueue);
> -	spin_unlock_irqrestore(&video->irqlock, flags);
> +	scoped_guard(spinlock_irqsave, &video->irqlock) {
> +		empty = list_empty(&video->irqqueue);
> +		list_add_tail(&buf->queue, &video->irqqueue);
> +	}
>  
>  	if (!empty)
>  		return;
> @@ -843,16 +837,15 @@ static void vsp1_video_stop_streaming(struct vb2_queue *vq)
>  {
>  	struct vsp1_video *video = vb2_get_drv_priv(vq);
>  	struct vsp1_pipeline *pipe = video->rwpf->entity.pipe;
> -	unsigned long flags;
>  	int ret;
>  
>  	/*
>  	 * Clear the buffers ready flag to make sure the device won't be started
>  	 * by a QBUF on the video node on the other side of the pipeline.
>  	 */
> -	spin_lock_irqsave(&video->irqlock, flags);
> -	pipe->buffers_ready &= ~(1 << video->pipe_index);
> -	spin_unlock_irqrestore(&video->irqlock, flags);
> +	scoped_guard(spinlock_irqsave, &video->irqlock) {
> +		pipe->buffers_ready &= ~(1 << video->pipe_index);
> +	}
>  
>  	scoped_guard(mutex, &pipe->lock) {
>  		if (--pipe->stream_count == pipe->num_inputs) {
> @@ -1118,7 +1111,6 @@ static const struct media_entity_operations vsp1_video_media_ops = {
>  
>  void vsp1_video_suspend(struct vsp1_device *vsp1)
>  {
> -	unsigned long flags;
>  	unsigned int i;
>  	int ret;
>  
> @@ -1138,10 +1130,10 @@ void vsp1_video_suspend(struct vsp1_device *vsp1)
>  		if (pipe == NULL)
>  			continue;
>  
> -		spin_lock_irqsave(&pipe->irqlock, flags);
> -		if (pipe->state == VSP1_PIPELINE_RUNNING)
> -			pipe->state = VSP1_PIPELINE_STOPPING;
> -		spin_unlock_irqrestore(&pipe->irqlock, flags);
> +		scoped_guard(spinlock_irqsave, &pipe->irqlock) {
> +			if (pipe->state == VSP1_PIPELINE_RUNNING)
> +				pipe->state = VSP1_PIPELINE_STOPPING;
> +		}
>  	}
>  
>  	for (i = 0; i < vsp1->info->wpf_count; ++i) {
> @@ -1165,7 +1157,6 @@ void vsp1_video_suspend(struct vsp1_device *vsp1)
>  
>  void vsp1_video_resume(struct vsp1_device *vsp1)
>  {
> -	unsigned long flags;
>  	unsigned int i;
>  
>  	/* Resume all running pipelines. */
> @@ -1186,10 +1177,10 @@ void vsp1_video_resume(struct vsp1_device *vsp1)
>  		 */
>  		pipe->configured = false;
>  
> -		spin_lock_irqsave(&pipe->irqlock, flags);
> -		if (vsp1_pipeline_ready(pipe))
> -			vsp1_video_pipeline_run(pipe);
> -		spin_unlock_irqrestore(&pipe->irqlock, flags);
> +		scoped_guard(spinlock_irqsave, &pipe->irqlock) {
> +			if (vsp1_pipeline_ready(pipe))
> +				vsp1_video_pipeline_run(pipe);
> +		}
>  	}
>  }
>  
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> index 327c7457126f..0ec707d2913f 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> @@ -366,13 +366,12 @@ static void wpf_configure_frame(struct vsp1_entity *entity,
>  	const unsigned int mask = BIT(WPF_CTRL_VFLIP)
>  				| BIT(WPF_CTRL_HFLIP);
>  	struct vsp1_rwpf *wpf = to_rwpf(&entity->subdev);
> -	unsigned long flags;
>  	u32 outfmt;
>  
> -	spin_lock_irqsave(&wpf->flip.lock, flags);
> -	wpf->flip.active = (wpf->flip.active & ~mask)
> -			 | (wpf->flip.pending & mask);
> -	spin_unlock_irqrestore(&wpf->flip.lock, flags);
> +	scoped_guard(spinlock_irqsave, &wpf->flip.lock) {
> +		wpf->flip.active = (wpf->flip.active & ~mask)
> +				 | (wpf->flip.pending & mask);
> +	}
>  
>  	outfmt = (wpf->alpha << VI6_WPF_OUTFMT_PDV_SHIFT) | wpf->outfmt;
>  
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> 

-- 
Kind Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 05/11] media: renesas: vsp1: Use mutex guards
  2026-05-13 19:20   ` Niklas Söderlund
@ 2026-05-13 19:40     ` Laurent Pinchart
  0 siblings, 0 replies; 24+ messages in thread
From: Laurent Pinchart @ 2026-05-13 19:40 UTC (permalink / raw)
  To: Niklas Söderlund
  Cc: linux-media, dri-devel, linux-renesas-soc, Tomi Valkeinen,
	Kieran Bingham, Biju Das, David Airlie, Simona Vetter

On Wed, May 13, 2026 at 09:20:54PM +0200, Niklas Söderlund wrote:
> Hi Laurent,
> 
> These new constructs are so useful, nice to take the time to make use of 
> them in existing drivers.

Yes, I like them too. The scoped guards are sometimes more annoying as
they add one indentation level.

> On 2026-05-12 02:56:29 +0300, Laurent Pinchart wrote:
> > Replace manual mutex locking and unlocking with guards. This simplifies
> > error paths and reduces the amount of code. Limit the changes to
> > locations where the guard covers until the end of the function to ease
> > review. Scoped guards will be introduced separately.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> 
> Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> 
> > ---
> >  .../media/platform/renesas/vsp1/vsp1_brx.c    | 26 ++++-------
> >  .../media/platform/renesas/vsp1/vsp1_drm.c    |  7 +--
> >  .../media/platform/renesas/vsp1/vsp1_entity.c | 19 +++-----
> >  .../media/platform/renesas/vsp1/vsp1_histo.c  | 35 +++++----------
> >  .../media/platform/renesas/vsp1/vsp1_hsit.c   | 15 +++----
> >  .../media/platform/renesas/vsp1/vsp1_rwpf.c   | 44 ++++++-------------
> >  .../media/platform/renesas/vsp1/vsp1_sru.c    | 13 ++----
> >  .../media/platform/renesas/vsp1/vsp1_uds.c    | 13 ++----
> >  .../media/platform/renesas/vsp1/vsp1_uif.c    | 29 ++++--------
> >  .../media/platform/renesas/vsp1/vsp1_video.c  | 20 ++++-----
> >  .../media/platform/renesas/vsp1/vsp1_wpf.c    | 17 +++----
> >  11 files changed, 77 insertions(+), 161 deletions(-)
> > 
> > diff --git a/drivers/media/platform/renesas/vsp1/vsp1_brx.c b/drivers/media/platform/renesas/vsp1/vsp1_brx.c
> > index 9d93cb8b8e82..bd2672341386 100644
> > --- a/drivers/media/platform/renesas/vsp1/vsp1_brx.c
> > +++ b/drivers/media/platform/renesas/vsp1/vsp1_brx.c
> > @@ -130,15 +130,12 @@ static int brx_set_format(struct v4l2_subdev *subdev,
> >  	struct vsp1_brx *brx = to_brx(subdev);
> >  	struct v4l2_subdev_state *state;
> >  	struct v4l2_mbus_framefmt *format;
> > -	int ret = 0;
> >  
> > -	mutex_lock(&brx->entity.lock);
> > +	guard(mutex)(&brx->entity.lock);
> >  
> >  	state = vsp1_entity_get_state(&brx->entity, sd_state, fmt->which);
> > -	if (!state) {
> > -		ret = -EINVAL;
> > -		goto done;
> > -	}
> > +	if (!state)
> > +		return -EINVAL;
> >  
> >  	brx_try_format(brx, state, fmt->pad, &fmt->format);
> >  
> > @@ -166,9 +163,7 @@ static int brx_set_format(struct v4l2_subdev *subdev,
> >  		}
> >  	}
> >  
> > -done:
> > -	mutex_unlock(&brx->entity.lock);
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  static int brx_get_selection(struct v4l2_subdev *subdev,
> > @@ -213,7 +208,6 @@ static int brx_set_selection(struct v4l2_subdev *subdev,
> >  	struct v4l2_subdev_state *state;
> >  	struct v4l2_mbus_framefmt *format;
> >  	struct v4l2_rect *compose;
> > -	int ret = 0;
> >  
> >  	if (sel->pad == brx->entity.source_pad)
> >  		return -EINVAL;
> > @@ -221,13 +215,11 @@ static int brx_set_selection(struct v4l2_subdev *subdev,
> >  	if (sel->target != V4L2_SEL_TGT_COMPOSE)
> >  		return -EINVAL;
> >  
> > -	mutex_lock(&brx->entity.lock);
> > +	guard(mutex)(&brx->entity.lock);
> >  
> >  	state = vsp1_entity_get_state(&brx->entity, sd_state, sel->which);
> > -	if (!state) {
> > -		ret = -EINVAL;
> > -		goto done;
> > -	}
> > +	if (!state)
> > +		return -EINVAL;
> >  
> >  	/*
> >  	 * The compose rectangle top left corner must be inside the output
> > @@ -248,9 +240,7 @@ static int brx_set_selection(struct v4l2_subdev *subdev,
> >  	compose = v4l2_subdev_state_get_compose(state, sel->pad);
> >  	*compose = sel->r;
> >  
> > -done:
> > -	mutex_unlock(&brx->entity.lock);
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  static const struct v4l2_subdev_pad_ops brx_pad_ops = {
> > diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drm.c b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> > index 1f431874064d..1439cf7bfb59 100644
> > --- a/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> > +++ b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> > @@ -920,7 +920,7 @@ void vsp1_du_atomic_flush(struct device *dev, unsigned int pipe_index,
> >  
> >  	drm_pipe->crc = cfg->crc;
> >  
> > -	mutex_lock(&vsp1->drm->lock);
> > +	guard(mutex)(&vsp1->drm->lock);
> >  
> >  	if (cfg->writeback.pixelformat) {
> >  		const struct vsp1_du_writeback_config *wb_cfg = &cfg->writeback;
> > @@ -929,7 +929,7 @@ void vsp1_du_atomic_flush(struct device *dev, unsigned int pipe_index,
> >  						       wb_cfg->pixelformat,
> >  						       wb_cfg->pitch);
> >  		if (WARN_ON(ret < 0))
> > -			goto done;
> > +			return;
> >  
> >  		pipe->output->mem.addr[0] = wb_cfg->mem[0];
> >  		pipe->output->mem.addr[1] = wb_cfg->mem[1];
> > @@ -942,9 +942,6 @@ void vsp1_du_atomic_flush(struct device *dev, unsigned int pipe_index,
> >  	vsp1_pipeline_dump(pipe, "atomic update");
> >  
> >  	vsp1_du_pipeline_configure(pipe);
> > -
> > -done:
> > -	mutex_unlock(&vsp1->drm->lock);
> >  }
> >  EXPORT_SYMBOL_GPL(vsp1_du_atomic_flush);
> >  
> > diff --git a/drivers/media/platform/renesas/vsp1/vsp1_entity.c b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
> > index 839b75b62ceb..3820ba53b45f 100644
> > --- a/drivers/media/platform/renesas/vsp1/vsp1_entity.c
> > +++ b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
> > @@ -172,9 +172,9 @@ int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev,
> >  	if (!state)
> >  		return -EINVAL;
> >  
> > -	mutex_lock(&entity->lock);
> > +	guard(mutex)(&entity->lock);
> > +
> >  	fmt->format = *v4l2_subdev_state_get_format(state, fmt->pad);
> > -	mutex_unlock(&entity->lock);
> >  
> >  	return 0;
> >  }
> > @@ -308,22 +308,19 @@ int vsp1_subdev_set_pad_format(struct v4l2_subdev *subdev,
> >  	struct v4l2_mbus_framefmt *format;
> >  	struct v4l2_rect *selection;
> >  	unsigned int i;
> > -	int ret = 0;
> >  
> > -	mutex_lock(&entity->lock);
> > +	guard(mutex)(&entity->lock);
> >  
> >  	state = vsp1_entity_get_state(entity, sd_state, fmt->which);
> > -	if (!state) {
> > -		ret = -EINVAL;
> > -		goto done;
> > -	}
> > +	if (!state)
> > +		return -EINVAL;
> >  
> >  	format = v4l2_subdev_state_get_format(state, fmt->pad);
> >  
> >  	if (fmt->pad == entity->source_pad) {
> >  		/* The output format can't be modified. */
> >  		fmt->format = *format;
> > -		goto done;
> > +		return 0;
> >  	}
> >  
> >  	/*
> > @@ -369,9 +366,7 @@ int vsp1_subdev_set_pad_format(struct v4l2_subdev *subdev,
> >  	selection->width = format->width;
> >  	selection->height = format->height;
> >  
> > -done:
> > -	mutex_unlock(&entity->lock);
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  static int vsp1_entity_init_state(struct v4l2_subdev *subdev,
> > diff --git a/drivers/media/platform/renesas/vsp1/vsp1_histo.c b/drivers/media/platform/renesas/vsp1/vsp1_histo.c
> > index 3f87a2c9df0e..72f6ef2fdc4f 100644
> > --- a/drivers/media/platform/renesas/vsp1/vsp1_histo.c
> > +++ b/drivers/media/platform/renesas/vsp1/vsp1_histo.c
> > @@ -196,18 +196,15 @@ static int histo_get_selection(struct v4l2_subdev *subdev,
> >  	struct v4l2_subdev_state *state;
> >  	struct v4l2_mbus_framefmt *format;
> >  	struct v4l2_rect *crop;
> > -	int ret = 0;
> >  
> >  	if (sel->pad != HISTO_PAD_SINK)
> >  		return -EINVAL;
> >  
> > -	mutex_lock(&histo->entity.lock);
> > +	guard(mutex)(&histo->entity.lock);
> >  
> >  	state = vsp1_entity_get_state(&histo->entity, sd_state, sel->which);
> > -	if (!state) {
> > -		ret = -EINVAL;
> > -		goto done;
> > -	}
> > +	if (!state)
> > +		return -EINVAL;
> >  
> >  	switch (sel->target) {
> >  	case V4L2_SEL_TGT_COMPOSE_BOUNDS:
> > @@ -237,13 +234,10 @@ static int histo_get_selection(struct v4l2_subdev *subdev,
> >  		break;
> >  
> >  	default:
> > -		ret = -EINVAL;
> > -		break;
> > +		return -EINVAL;
> >  	}
> >  
> > -done:
> > -	mutex_unlock(&histo->entity.lock);
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  static int histo_set_crop(struct v4l2_subdev *subdev,
> > @@ -321,29 +315,22 @@ static int histo_set_selection(struct v4l2_subdev *subdev,
> >  {
> >  	struct vsp1_histogram *histo = subdev_to_histo(subdev);
> >  	struct v4l2_subdev_state *state;
> > -	int ret;
> >  
> >  	if (sel->pad != HISTO_PAD_SINK)
> >  		return -EINVAL;
> >  
> > -	mutex_lock(&histo->entity.lock);
> > +	guard(mutex)(&histo->entity.lock);
> >  
> >  	state = vsp1_entity_get_state(&histo->entity, sd_state, sel->which);
> > -	if (!state) {
> > -		ret = -EINVAL;
> > -		goto done;
> > -	}
> > +	if (!state)
> > +		return -EINVAL;
> >  
> >  	if (sel->target == V4L2_SEL_TGT_CROP)
> > -		ret = histo_set_crop(subdev, state, sel);
> > +		return histo_set_crop(subdev, state, sel);
> >  	else if (sel->target == V4L2_SEL_TGT_COMPOSE)
> > -		ret = histo_set_compose(subdev, state, sel);
> > +		return histo_set_compose(subdev, state, sel);
> >  	else
> > -		ret = -EINVAL;
> > -
> > -done:
> > -	mutex_unlock(&histo->entity.lock);
> > -	return ret;
> > +		return -EINVAL;
> >  }
> >  
> >  static int histo_set_format(struct v4l2_subdev *subdev,
> > diff --git a/drivers/media/platform/renesas/vsp1/vsp1_hsit.c b/drivers/media/platform/renesas/vsp1/vsp1_hsit.c
> > index 830e124beb7b..df069c228243 100644
> > --- a/drivers/media/platform/renesas/vsp1/vsp1_hsit.c
> > +++ b/drivers/media/platform/renesas/vsp1/vsp1_hsit.c
> > @@ -115,15 +115,12 @@ static int hsit_set_format(struct v4l2_subdev *subdev,
> >  	struct vsp1_hsit *hsit = to_hsit(subdev);
> >  	struct v4l2_subdev_state *state;
> >  	struct v4l2_mbus_framefmt *format;
> > -	int ret = 0;
> >  
> > -	mutex_lock(&hsit->entity.lock);
> > +	guard(mutex)(&hsit->entity.lock);
> >  
> >  	state = vsp1_entity_get_state(&hsit->entity, sd_state, fmt->which);
> > -	if (!state) {
> > -		ret = -EINVAL;
> > -		goto done;
> > -	}
> > +	if (!state)
> > +		return -EINVAL;
> >  
> >  	format = v4l2_subdev_state_get_format(state, fmt->pad);
> >  
> > @@ -133,7 +130,7 @@ static int hsit_set_format(struct v4l2_subdev *subdev,
> >  		 * modified.
> >  		 */
> >  		fmt->format = *format;
> > -		goto done;
> > +		return 0;
> >  	}
> >  
> >  	format->code = hsit->inverse ? MEDIA_BUS_FMT_AHSV8888_1X32
> > @@ -161,9 +158,7 @@ static int hsit_set_format(struct v4l2_subdev *subdev,
> >  
> >  	vsp1_entity_adjust_color_space(format);
> >  
> > -done:
> > -	mutex_unlock(&hsit->entity.lock);
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  static const struct v4l2_subdev_pad_ops hsit_pad_ops = {
> > diff --git a/drivers/media/platform/renesas/vsp1/vsp1_rwpf.c b/drivers/media/platform/renesas/vsp1/vsp1_rwpf.c
> > index c72518b29f84..ced01870acd6 100644
> > --- a/drivers/media/platform/renesas/vsp1/vsp1_rwpf.c
> > +++ b/drivers/media/platform/renesas/vsp1/vsp1_rwpf.c
> > @@ -116,15 +116,12 @@ static int vsp1_rwpf_set_format(struct v4l2_subdev *subdev,
> >  	struct vsp1_rwpf *rwpf = to_rwpf(subdev);
> >  	struct v4l2_subdev_state *state;
> >  	struct v4l2_mbus_framefmt *format;
> > -	int ret = 0;
> >  
> > -	mutex_lock(&rwpf->entity.lock);
> > +	guard(mutex)(&rwpf->entity.lock);
> >  
> >  	state = vsp1_entity_get_state(&rwpf->entity, sd_state, fmt->which);
> > -	if (!state) {
> > -		ret = -EINVAL;
> > -		goto done;
> > -	}
> > +	if (!state)
> > +		return -EINVAL;
> >  
> >  	/* Default to YUV if the requested format is not supported. */
> >  	if (fmt->format.code != MEDIA_BUS_FMT_ARGB8888_1X32 &&
> > @@ -174,7 +171,7 @@ static int vsp1_rwpf_set_format(struct v4l2_subdev *subdev,
> >  		fmt->format = *format;
> >  		fmt->format.flags = flags;
> >  
> > -		goto done;
> > +		return 0;
> >  	}
> >  
> >  	format->code = fmt->format.code;
> > @@ -213,9 +210,7 @@ static int vsp1_rwpf_set_format(struct v4l2_subdev *subdev,
> >  		format->height = fmt->format.width;
> >  	}
> >  
> > -done:
> > -	mutex_unlock(&rwpf->entity.lock);
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  static int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev,
> > @@ -225,7 +220,6 @@ static int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev,
> >  	struct vsp1_rwpf *rwpf = to_rwpf(subdev);
> >  	struct v4l2_subdev_state *state;
> >  	struct v4l2_mbus_framefmt *format;
> > -	int ret = 0;
> >  
> >  	/*
> >  	 * Cropping is only supported on the RPF and is implemented on the sink
> > @@ -234,13 +228,11 @@ static int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev,
> >  	if (rwpf->entity.type == VSP1_ENTITY_WPF || sel->pad != RWPF_PAD_SINK)
> >  		return -EINVAL;
> >  
> > -	mutex_lock(&rwpf->entity.lock);
> > +	guard(mutex)(&rwpf->entity.lock);
> >  
> >  	state = vsp1_entity_get_state(&rwpf->entity, sd_state, sel->which);
> > -	if (!state) {
> > -		ret = -EINVAL;
> > -		goto done;
> > -	}
> > +	if (!state)
> > +		return -EINVAL;
> >  
> >  	switch (sel->target) {
> >  	case V4L2_SEL_TGT_CROP:
> > @@ -256,13 +248,10 @@ static int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev,
> >  		break;
> >  
> >  	default:
> > -		ret = -EINVAL;
> > -		break;
> > +		return -EINVAL;
> >  	}
> >  
> > -done:
> > -	mutex_unlock(&rwpf->entity.lock);
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  static int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev,
> > @@ -275,7 +264,6 @@ static int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev,
> >  	struct v4l2_subdev_state *state;
> >  	struct v4l2_mbus_framefmt *format;
> >  	struct v4l2_rect *crop;
> > -	int ret = 0;
> >  
> >  	/*
> >  	 * Cropping is only supported on the RPF and is implemented on the sink
> > @@ -287,13 +275,11 @@ static int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev,
> >  	if (sel->target != V4L2_SEL_TGT_CROP)
> >  		return -EINVAL;
> >  
> > -	mutex_lock(&rwpf->entity.lock);
> > +	guard(mutex)(&rwpf->entity.lock);
> >  
> >  	state = vsp1_entity_get_state(&rwpf->entity, sd_state, sel->which);
> > -	if (!state) {
> > -		ret = -EINVAL;
> > -		goto done;
> > -	}
> > +	if (!state)
> > +		return -EINVAL;
> >  
> >  	/* Make sure the crop rectangle is entirely contained in the image. */
> >  	format = v4l2_subdev_state_get_format(state, RWPF_PAD_SINK);
> > @@ -342,9 +328,7 @@ static int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev,
> >  	format->width = crop->width;
> >  	format->height = crop->height;
> >  
> > -done:
> > -	mutex_unlock(&rwpf->entity.lock);
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  static const struct v4l2_subdev_pad_ops vsp1_rwpf_pad_ops = {
> > diff --git a/drivers/media/platform/renesas/vsp1/vsp1_sru.c b/drivers/media/platform/renesas/vsp1/vsp1_sru.c
> > index 94149da0c900..3fd9fde5c724 100644
> > --- a/drivers/media/platform/renesas/vsp1/vsp1_sru.c
> > +++ b/drivers/media/platform/renesas/vsp1/vsp1_sru.c
> > @@ -216,15 +216,12 @@ static int sru_set_format(struct v4l2_subdev *subdev,
> >  	struct vsp1_sru *sru = to_sru(subdev);
> >  	struct v4l2_subdev_state *state;
> >  	struct v4l2_mbus_framefmt *format;
> > -	int ret = 0;
> >  
> > -	mutex_lock(&sru->entity.lock);
> > +	guard(mutex)(&sru->entity.lock);
> >  
> >  	state = vsp1_entity_get_state(&sru->entity, sd_state, fmt->which);
> > -	if (!state) {
> > -		ret = -EINVAL;
> > -		goto done;
> > -	}
> > +	if (!state)
> > +		return -EINVAL;
> >  
> >  	sru_try_format(sru, state, fmt->pad, &fmt->format);
> >  
> > @@ -239,9 +236,7 @@ static int sru_set_format(struct v4l2_subdev *subdev,
> >  		sru_try_format(sru, state, SRU_PAD_SOURCE, format);
> >  	}
> >  
> > -done:
> > -	mutex_unlock(&sru->entity.lock);
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  static const struct v4l2_subdev_pad_ops sru_pad_ops = {
> > diff --git a/drivers/media/platform/renesas/vsp1/vsp1_uds.c b/drivers/media/platform/renesas/vsp1/vsp1_uds.c
> > index dd4722315c56..9f7bb112929e 100644
> > --- a/drivers/media/platform/renesas/vsp1/vsp1_uds.c
> > +++ b/drivers/media/platform/renesas/vsp1/vsp1_uds.c
> > @@ -199,15 +199,12 @@ static int uds_set_format(struct v4l2_subdev *subdev,
> >  	struct vsp1_uds *uds = to_uds(subdev);
> >  	struct v4l2_subdev_state *state;
> >  	struct v4l2_mbus_framefmt *format;
> > -	int ret = 0;
> >  
> > -	mutex_lock(&uds->entity.lock);
> > +	guard(mutex)(&uds->entity.lock);
> >  
> >  	state = vsp1_entity_get_state(&uds->entity, sd_state, fmt->which);
> > -	if (!state) {
> > -		ret = -EINVAL;
> > -		goto done;
> > -	}
> > +	if (!state)
> > +		return -EINVAL;
> >  
> >  	uds_try_format(uds, state, fmt->pad, &fmt->format);
> >  
> > @@ -222,9 +219,7 @@ static int uds_set_format(struct v4l2_subdev *subdev,
> >  		uds_try_format(uds, state, UDS_PAD_SOURCE, format);
> >  	}
> >  
> > -done:
> > -	mutex_unlock(&uds->entity.lock);
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  /* -----------------------------------------------------------------------------
> > diff --git a/drivers/media/platform/renesas/vsp1/vsp1_uif.c b/drivers/media/platform/renesas/vsp1/vsp1_uif.c
> > index 3aefe5c9d421..52dbfe58a70d 100644
> > --- a/drivers/media/platform/renesas/vsp1/vsp1_uif.c
> > +++ b/drivers/media/platform/renesas/vsp1/vsp1_uif.c
> > @@ -60,18 +60,15 @@ static int uif_get_selection(struct v4l2_subdev *subdev,
> >  	struct vsp1_uif *uif = to_uif(subdev);
> >  	struct v4l2_subdev_state *state;
> >  	struct v4l2_mbus_framefmt *format;
> > -	int ret = 0;
> >  
> >  	if (sel->pad != UIF_PAD_SINK)
> >  		return -EINVAL;
> >  
> > -	mutex_lock(&uif->entity.lock);
> > +	guard(mutex)(&uif->entity.lock);
> >  
> >  	state = vsp1_entity_get_state(&uif->entity, sd_state, sel->which);
> > -	if (!state) {
> > -		ret = -EINVAL;
> > -		goto done;
> > -	}
> > +	if (!state)
> > +		return -EINVAL;
> >  
> >  	switch (sel->target) {
> >  	case V4L2_SEL_TGT_CROP_BOUNDS:
> > @@ -88,13 +85,10 @@ static int uif_get_selection(struct v4l2_subdev *subdev,
> >  		break;
> >  
> >  	default:
> > -		ret = -EINVAL;
> > -		break;
> > +		return -EINVAL;
> >  	}
> >  
> > -done:
> > -	mutex_unlock(&uif->entity.lock);
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  static int uif_set_selection(struct v4l2_subdev *subdev,
> > @@ -105,19 +99,16 @@ static int uif_set_selection(struct v4l2_subdev *subdev,
> >  	struct v4l2_subdev_state *state;
> >  	struct v4l2_mbus_framefmt *format;
> >  	struct v4l2_rect *selection;
> > -	int ret = 0;
> >  
> >  	if (sel->pad != UIF_PAD_SINK ||
> >  	    sel->target != V4L2_SEL_TGT_CROP)
> >  		return -EINVAL;
> >  
> > -	mutex_lock(&uif->entity.lock);
> > +	guard(mutex)(&uif->entity.lock);
> >  
> >  	state = vsp1_entity_get_state(&uif->entity, sd_state, sel->which);
> > -	if (!state) {
> > -		ret = -EINVAL;
> > -		goto done;
> > -	}
> > +	if (!state)
> > +		return -EINVAL;
> >  
> >  	/* The crop rectangle must be inside the input frame. */
> >  	format = v4l2_subdev_state_get_format(state, UIF_PAD_SINK);
> > @@ -133,9 +124,7 @@ static int uif_set_selection(struct v4l2_subdev *subdev,
> >  	selection = v4l2_subdev_state_get_crop(state, sel->pad);
> >  	*selection = sel->r;
> >  
> > -done:
> > -	mutex_unlock(&uif->entity.lock);
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  /* -----------------------------------------------------------------------------
> > diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c
> > index a8db94bdb670..4cf2cc370416 100644
> > --- a/drivers/media/platform/renesas/vsp1/vsp1_video.c
> > +++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c
> > @@ -590,9 +590,9 @@ static void vsp1_video_pipeline_put(struct vsp1_pipeline *pipe)
> >  {
> >  	struct media_device *mdev = &pipe->output->entity.vsp1->media_dev;
> >  
> > -	mutex_lock(&mdev->graph_mutex);
> > +	guard(mutex)(&mdev->graph_mutex);
> > +
> >  	kref_put(&pipe->kref, vsp1_video_pipeline_release);
> > -	mutex_unlock(&mdev->graph_mutex);
> >  }
> >  
> >  /* -----------------------------------------------------------------------------
> > @@ -933,9 +933,9 @@ vsp1_video_get_format(struct file *file, void *fh, struct v4l2_format *format)
> >  	if (format->type != video->queue.type)
> >  		return -EINVAL;
> >  
> > -	mutex_lock(&video->lock);
> > +	guard(mutex)(&video->lock);
> > +
> >  	format->fmt.pix_mp = video->rwpf->format;
> > -	mutex_unlock(&video->lock);
> >  
> >  	return 0;
> >  }
> > @@ -967,19 +967,15 @@ vsp1_video_set_format(struct file *file, void *fh, struct v4l2_format *format)
> >  	if (ret < 0)
> >  		return ret;
> >  
> > -	mutex_lock(&video->lock);
> > +	guard(mutex)(&video->lock);
> >  
> > -	if (vb2_is_busy(&video->queue)) {
> > -		ret = -EBUSY;
> > -		goto done;
> > -	}
> > +	if (vb2_is_busy(&video->queue))
> > +		return -EBUSY;
> >  
> >  	video->rwpf->format = format->fmt.pix_mp;
> >  	video->rwpf->fmtinfo = info;
> >  
> > -done:
> > -	mutex_unlock(&video->lock);
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  static int
> > diff --git a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> > index cd6c5592221b..e7ed3c8e9e90 100644
> > --- a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> > +++ b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> > @@ -47,7 +47,6 @@ static int vsp1_wpf_set_rotation(struct vsp1_rwpf *wpf, unsigned int rotation)
> >  	struct v4l2_mbus_framefmt *sink_format;
> >  	struct v4l2_mbus_framefmt *source_format;
> >  	bool rotate;
> > -	int ret = 0;
> >  
> >  	/*
> >  	 * Only consider the 0°/180° from/to 90°/270° modifications, the rest
> > @@ -58,19 +57,17 @@ static int vsp1_wpf_set_rotation(struct vsp1_rwpf *wpf, unsigned int rotation)
> >  		return 0;
> >  
> >  	/* Changing rotation isn't allowed when buffers are allocated. */
> > -	mutex_lock(&video->lock);
> > +	guard(mutex)(&video->lock);
> >  
> > -	if (vb2_is_busy(&video->queue)) {
> > -		ret = -EBUSY;
> > -		goto done;
> > -	}
> > +	if (vb2_is_busy(&video->queue))
> > +		return -EBUSY;
> >  
> >  	sink_format = v4l2_subdev_state_get_format(wpf->entity.state,
> >  						   RWPF_PAD_SINK);
> >  	source_format = v4l2_subdev_state_get_format(wpf->entity.state,
> >  						     RWPF_PAD_SOURCE);
> >  
> > -	mutex_lock(&wpf->entity.lock);
> > +	guard(mutex)(&wpf->entity.lock);
> >  
> >  	if (rotate) {
> >  		source_format->width = sink_format->height;
> > @@ -82,11 +79,7 @@ static int vsp1_wpf_set_rotation(struct vsp1_rwpf *wpf, unsigned int rotation)
> >  
> >  	wpf->flip.rotate = rotate;
> >  
> > -	mutex_unlock(&wpf->entity.lock);
> > -
> > -done:
> > -	mutex_unlock(&video->lock);
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  static int vsp1_wpf_s_ctrl(struct v4l2_ctrl *ctrl)

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 09/11] media: renesas: vsp1: Simplify iteration over format arrays
  2026-05-11 23:56 ` [PATCH 09/11] media: renesas: vsp1: Simplify iteration over format arrays Laurent Pinchart
@ 2026-05-13 19:44   ` Niklas Söderlund
  0 siblings, 0 replies; 24+ messages in thread
From: Niklas Söderlund @ 2026-05-13 19:44 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, dri-devel, linux-renesas-soc, Tomi Valkeinen,
	Kieran Bingham, Biju Das, David Airlie, Simona Vetter

Hi Laurent,

Thanks for your work.

On 2026-05-12 02:56:33 +0300, Laurent Pinchart wrote:
> Introduce a vsp1_for_each_format() macro to iterate over format arrays,
> to improve readability. No functional change intended.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> ---
>  .../media/platform/renesas/vsp1/vsp1_pipe.c   | 36 ++++++-------------
>  1 file changed, 10 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
> index f9c7c75a7ad0..7197f2917417 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
> @@ -229,6 +229,10 @@ static const struct vsp1_format_info vsp1_video_hsit_formats[] = {
>  	  1, { 32, 0, 0 }, false, false, 1, 1, false },
>  };
>  
> +#define vsp1_for_each_format(info, formats) \
> +	for (const struct vsp1_format_info *info = &formats[0]; \
> +	     info < formats + ARRAY_SIZE(formats); ++info)
> +
>  /**
>   * vsp1_get_format_info - Retrieve format information for a 4CC
>   * @vsp1: the VSP1 device
> @@ -240,30 +244,20 @@ static const struct vsp1_format_info vsp1_video_hsit_formats[] = {
>  const struct vsp1_format_info *vsp1_get_format_info(struct vsp1_device *vsp1,
>  						    u32 fourcc)
>  {
> -	unsigned int i;
> -
> -	for (i = 0; i < ARRAY_SIZE(vsp1_video_formats); ++i) {
> -		const struct vsp1_format_info *info = &vsp1_video_formats[i];
> -
> +	vsp1_for_each_format(info, vsp1_video_formats) {
>  		if (info->fourcc == fourcc)
>  			return info;
>  	}
>  
>  	if (vsp1->info->gen == 2) {
> -		for (i = 0; i < ARRAY_SIZE(vsp1_video_gen2_formats); ++i) {
> -			const struct vsp1_format_info *info =
> -				&vsp1_video_gen2_formats[i];
> -
> +		vsp1_for_each_format(info, vsp1_video_gen2_formats) {
>  			if (info->fourcc == fourcc)
>  				return info;
>  		}
>  	}
>  
>  	if (vsp1_feature(vsp1, VSP1_HAS_HSIT)) {
> -		for (i = 0; i < ARRAY_SIZE(vsp1_video_hsit_formats); ++i) {
> -			const struct vsp1_format_info *info =
> -				&vsp1_video_hsit_formats[i];
> -
> +		vsp1_for_each_format(info, vsp1_video_hsit_formats) {
>  			if (info->fourcc == fourcc)
>  				return info;
>  		}
> @@ -287,8 +281,6 @@ const struct vsp1_format_info *
>  vsp1_get_format_info_by_index(struct vsp1_device *vsp1, unsigned int index,
>  			      u32 code)
>  {
> -	unsigned int i;
> -
>  	if (!code) {
>  		if (index < ARRAY_SIZE(vsp1_video_formats))
>  			return &vsp1_video_formats[index];
> @@ -308,9 +300,7 @@ vsp1_get_format_info_by_index(struct vsp1_device *vsp1, unsigned int index,
>  		return NULL;
>  	}
>  
> -	for (i = 0; i < ARRAY_SIZE(vsp1_video_formats); ++i) {
> -		const struct vsp1_format_info *info = &vsp1_video_formats[i];
> -
> +	vsp1_for_each_format(info, vsp1_video_formats) {
>  		if (info->mbus == code) {
>  			if (!index)
>  				return info;
> @@ -319,10 +309,7 @@ vsp1_get_format_info_by_index(struct vsp1_device *vsp1, unsigned int index,
>  	}
>  
>  	if (vsp1->info->gen == 2) {
> -		for (i = 0; i < ARRAY_SIZE(vsp1_video_gen2_formats); ++i) {
> -			const struct vsp1_format_info *info =
> -				&vsp1_video_gen2_formats[i];
> -
> +		vsp1_for_each_format(info, vsp1_video_gen2_formats) {
>  			if (info->mbus == code) {
>  				if (!index)
>  					return info;
> @@ -332,10 +319,7 @@ vsp1_get_format_info_by_index(struct vsp1_device *vsp1, unsigned int index,
>  	}
>  
>  	if (vsp1_feature(vsp1, VSP1_HAS_HSIT)) {
> -		for (i = 0; i < ARRAY_SIZE(vsp1_video_hsit_formats); ++i) {
> -			const struct vsp1_format_info *info =
> -				&vsp1_video_hsit_formats[i];
> -
> +		vsp1_for_each_format(info, vsp1_video_hsit_formats) {
>  			if (info->mbus == code) {
>  				if (!index)
>  					return info;
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> 

-- 
Kind Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 10/11] media: renesas: vsp1: Declare index variables in for loop statement
  2026-05-11 23:56 ` [PATCH 10/11] media: renesas: vsp1: Declare index variables in for loop statement Laurent Pinchart
@ 2026-05-13 20:29   ` Niklas Söderlund
  0 siblings, 0 replies; 24+ messages in thread
From: Niklas Söderlund @ 2026-05-13 20:29 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, dri-devel, linux-renesas-soc, Tomi Valkeinen,
	Kieran Bingham, Biju Das, David Airlie, Simona Vetter

Hi Laurent,

Thanks for your patch.

On 2026-05-12 02:56:34 +0300, Laurent Pinchart wrote:
> Using loop indices outside of the loop is a source of out-of-bounds
> accesses and other bugs. It is important to carefully review those
> usages. To make them stand out, declare all loop index variables that
> are not used outside of the loop inside the loop statement.
> 
> No functional change intended.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> ---
>  .../media/platform/renesas/vsp1/vsp1_brx.c    |  7 +---
>  .../media/platform/renesas/vsp1/vsp1_clu.c    |  3 +-
>  drivers/media/platform/renesas/vsp1/vsp1_dl.c | 12 ++----
>  .../media/platform/renesas/vsp1/vsp1_drm.c    | 14 +++----
>  .../media/platform/renesas/vsp1/vsp1_drv.c    | 42 ++++++++-----------
>  .../media/platform/renesas/vsp1/vsp1_entity.c |  4 +-
>  .../media/platform/renesas/vsp1/vsp1_hgo.c    |  7 ++--
>  .../media/platform/renesas/vsp1/vsp1_hgt.c    | 13 +++---
>  .../media/platform/renesas/vsp1/vsp1_lut.c    |  3 +-
>  .../media/platform/renesas/vsp1/vsp1_pipe.c   |  5 +--
>  .../media/platform/renesas/vsp1/vsp1_video.c  | 34 ++++++---------
>  .../media/platform/renesas/vsp1/vsp1_wpf.c    |  8 ++--
>  12 files changed, 56 insertions(+), 96 deletions(-)
> 
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_brx.c b/drivers/media/platform/renesas/vsp1/vsp1_brx.c
> index 325be30836d7..360a42502947 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_brx.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_brx.c
> @@ -155,9 +155,7 @@ static int brx_set_format(struct v4l2_subdev *subdev,
>  
>  	/* Propagate the format code to all pads. */
>  	if (fmt->pad == BRX_PAD_SINK(0)) {
> -		unsigned int i;
> -
> -		for (i = 0; i <= brx->entity.source_pad; ++i) {
> +		for (unsigned int i = 0; i <= brx->entity.source_pad; ++i) {
>  			format = v4l2_subdev_state_get_format(state, i);
>  			format->code = fmt->format.code;
>  		}
> @@ -271,7 +269,6 @@ static void brx_configure_stream(struct vsp1_entity *entity,
>  	struct vsp1_brx *brx = to_brx(&entity->subdev);
>  	struct v4l2_mbus_framefmt *format;
>  	unsigned int flags;
> -	unsigned int i;
>  
>  	format = v4l2_subdev_state_get_format(state, brx->entity.source_pad);
>  
> @@ -315,7 +312,7 @@ static void brx_configure_stream(struct vsp1_entity *entity,
>  			       VI6_BRU_ROP_CROP(VI6_ROP_NOP) |
>  			       VI6_BRU_ROP_AROP(VI6_ROP_NOP));
>  
> -	for (i = 0; i < brx->entity.source_pad; ++i) {
> +	for (unsigned int i = 0; i < brx->entity.source_pad; ++i) {
>  		bool premultiplied = false;
>  		u32 ctrl = 0;
>  
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_clu.c b/drivers/media/platform/renesas/vsp1/vsp1_clu.c
> index a6e4bcab5101..4b7d07d730da 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_clu.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_clu.c
> @@ -43,14 +43,13 @@ static inline void vsp1_clu_write(struct vsp1_clu *clu,
>  static int clu_set_table(struct vsp1_clu *clu, struct v4l2_ctrl *ctrl)
>  {
>  	struct vsp1_dl_body *dlb;
> -	unsigned int i;
>  
>  	dlb = vsp1_dl_body_get(clu->pool);
>  	if (!dlb)
>  		return -ENOMEM;
>  
>  	vsp1_dl_body_write(dlb, VI6_CLU_ADDR, 0);
> -	for (i = 0; i < CLU_SIZE; ++i)
> +	for (unsigned int i = 0; i < CLU_SIZE; ++i)
>  		vsp1_dl_body_write(dlb, VI6_CLU_DATA, ctrl->p_new.p_u32[i]);
>  
>  	scoped_guard(spinlock_irq, &clu->lock) {
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_dl.c b/drivers/media/platform/renesas/vsp1/vsp1_dl.c
> index 3dc74fed91dc..6430f2ec8b32 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_dl.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_dl.c
> @@ -257,7 +257,6 @@ vsp1_dl_body_pool_create(struct vsp1_device *vsp1, unsigned int num_bodies,
>  {
>  	struct vsp1_dl_body_pool *pool;
>  	size_t dlb_size;
> -	unsigned int i;
>  
>  	pool = kzalloc_obj(*pool);
>  	if (!pool)
> @@ -291,7 +290,7 @@ vsp1_dl_body_pool_create(struct vsp1_device *vsp1, unsigned int num_bodies,
>  	spin_lock_init(&pool->lock);
>  	INIT_LIST_HEAD(&pool->free);
>  
> -	for (i = 0; i < num_bodies; ++i) {
> +	for (unsigned int i = 0; i < num_bodies; ++i) {
>  		struct vsp1_dl_body *dlb = &pool->bodies[i];
>  
>  		dlb->pool = pool;
> @@ -426,7 +425,6 @@ vsp1_dl_cmd_pool_create(struct vsp1_device *vsp1, enum vsp1_extcmd_type type,
>  			unsigned int num_cmds)
>  {
>  	struct vsp1_dl_cmd_pool *pool;
> -	unsigned int i;
>  	size_t cmd_size;
>  
>  	pool = kzalloc_obj(*pool);
> @@ -457,7 +455,7 @@ vsp1_dl_cmd_pool_create(struct vsp1_device *vsp1, enum vsp1_extcmd_type type,
>  		return NULL;
>  	}
>  
> -	for (i = 0; i < num_cmds; ++i) {
> +	for (unsigned int i = 0; i < num_cmds; ++i) {
>  		struct vsp1_dl_ext_cmd *cmd = &pool->cmds[i];
>  		size_t cmd_offset = i * cmd_size;
>  		/* data_offset must be 16 byte aligned for DMA. */
> @@ -1046,7 +1044,6 @@ unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm)
>  /* Hardware Setup */
>  void vsp1_dlm_setup(struct vsp1_device *vsp1)
>  {
> -	unsigned int i;
>  	u32 ctrl = (256 << VI6_DL_CTRL_AR_WAIT_SHIFT)
>  		 | VI6_DL_CTRL_DC2 | VI6_DL_CTRL_DC1 | VI6_DL_CTRL_DC0
>  		 | VI6_DL_CTRL_DLE;
> @@ -1054,7 +1051,7 @@ void vsp1_dlm_setup(struct vsp1_device *vsp1)
>  		   | VI6_DL_EXT_CTRL_DLPRI | VI6_DL_EXT_CTRL_EXT;
>  
>  	if (vsp1_feature(vsp1, VSP1_HAS_EXT_DL)) {
> -		for (i = 0; i < vsp1->info->wpf_count; ++i)
> +		for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i)
>  			vsp1_write(vsp1, VI6_DL_EXT_CTRL(i), ext_dl);
>  	}
>  
> @@ -1092,7 +1089,6 @@ struct vsp1_dl_manager *vsp1_dlm_create(struct vsp1_device *vsp1,
>  {
>  	struct vsp1_dl_manager *dlm;
>  	size_t header_size;
> -	unsigned int i;
>  
>  	dlm = devm_kzalloc(vsp1->dev, sizeof(*dlm), GFP_KERNEL);
>  	if (!dlm)
> @@ -1128,7 +1124,7 @@ struct vsp1_dl_manager *vsp1_dlm_create(struct vsp1_device *vsp1,
>  	if (!dlm->pool)
>  		return NULL;
>  
> -	for (i = 0; i < prealloc; ++i) {
> +	for (unsigned int i = 0; i < prealloc; ++i) {
>  		struct vsp1_dl_list *dl;
>  
>  		dl = vsp1_dl_list_alloc(dlm);
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drm.c b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> index f6fbd3475329..9cd5c025d2be 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_drm.c
> @@ -419,13 +419,12 @@ static int vsp1_du_pipeline_setup_inputs(struct vsp1_device *vsp1,
>  	struct vsp1_entity *uif;
>  	bool use_uif = false;
>  	struct vsp1_brx *brx;
> -	unsigned int i;
>  	int ret;
>  
>  	/* Count the number of enabled inputs and sort them by Z-order. */
>  	pipe->num_inputs = 0;
>  
> -	for (i = 0; i < vsp1->info->rpf_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->rpf_count; ++i) {
>  		struct vsp1_rwpf *rpf = vsp1->rpf[i];
>  		unsigned int j;
>  
> @@ -457,7 +456,7 @@ static int vsp1_du_pipeline_setup_inputs(struct vsp1_device *vsp1,
>  	brx = to_brx(&pipe->brx->subdev);
>  
>  	/* Setup the RPF input pipeline for every enabled input. */
> -	for (i = 0; i < pipe->brx->source_pad; ++i) {
> +	for (unsigned int i = 0; i < pipe->brx->source_pad; ++i) {
>  		struct vsp1_rwpf *rpf = inputs[i];
>  
>  		if (!rpf) {
> @@ -732,7 +731,6 @@ int vsp1_du_disable(struct device *dev, unsigned int pipe_index)
>  	struct vsp1_device *vsp1 = dev_get_drvdata(dev);
>  	struct vsp1_drm_pipeline *drm_pipe;
>  	struct vsp1_pipeline *pipe;
> -	unsigned int i;
>  	int ret;
>  
>  	if (pipe_index >= vsp1->info->lif_count)
> @@ -748,7 +746,7 @@ int vsp1_du_disable(struct device *dev, unsigned int pipe_index)
>  		if (ret == -ETIMEDOUT)
>  			dev_err(vsp1->dev, "DRM pipeline stop timeout\n");
>  
> -		for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) {
> +		for (unsigned int i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) {
>  			struct vsp1_rwpf *rpf = pipe->inputs[i];
>  
>  			if (!rpf)
> @@ -964,8 +962,6 @@ EXPORT_SYMBOL_GPL(vsp1_du_unmap_sg);
>  
>  int vsp1_drm_init(struct vsp1_device *vsp1)
>  {
> -	unsigned int i;
> -
>  	vsp1->drm = devm_kzalloc(vsp1->dev, sizeof(*vsp1->drm), GFP_KERNEL);
>  	if (!vsp1->drm)
>  		return -ENOMEM;
> @@ -973,7 +969,7 @@ int vsp1_drm_init(struct vsp1_device *vsp1)
>  	mutex_init(&vsp1->drm->lock);
>  
>  	/* Create one DRM pipeline per LIF. */
> -	for (i = 0; i < vsp1->info->lif_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->lif_count; ++i) {
>  		struct vsp1_drm_pipeline *drm_pipe = &vsp1->drm->pipe[i];
>  		struct vsp1_pipeline *pipe = &drm_pipe->pipe;
>  
> @@ -1010,7 +1006,7 @@ int vsp1_drm_init(struct vsp1_device *vsp1)
>  	}
>  
>  	/* Disable all RPFs initially. */
> -	for (i = 0; i < vsp1->info->rpf_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->rpf_count; ++i) {
>  		struct vsp1_rwpf *input = vsp1->rpf[i];
>  
>  		INIT_LIST_HEAD(&input->entity.list_pipe);
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drv.c b/drivers/media/platform/renesas/vsp1/vsp1_drv.c
> index 627b5046fa80..3fa5a4415fc6 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_drv.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_drv.c
> @@ -51,10 +51,9 @@ static irqreturn_t vsp1_irq_handler(int irq, void *data)
>  		   VI6_WPF_IRQ_STA_UND;
>  	struct vsp1_device *vsp1 = data;
>  	irqreturn_t ret = IRQ_NONE;
> -	unsigned int i;
>  	u32 status;
>  
> -	for (i = 0; i < vsp1->info->wpf_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i) {
>  		struct vsp1_rwpf *wpf = vsp1->wpf[i];
>  
>  		if (wpf == NULL)
> @@ -103,7 +102,6 @@ static int vsp1_create_sink_links(struct vsp1_device *vsp1,
>  {
>  	struct media_entity *entity = &sink->subdev.entity;
>  	struct vsp1_entity *source;
> -	unsigned int pad;
>  	int ret;
>  
>  	list_for_each_entry(source, &vsp1->entities, list_dev) {
> @@ -123,7 +121,7 @@ static int vsp1_create_sink_links(struct vsp1_device *vsp1,
>  			source->index == sink->index
>  		      ? MEDIA_LNK_FL_ENABLED : 0;
>  
> -		for (pad = 0; pad < entity->num_pads; ++pad) {
> +		for (unsigned int pad = 0; pad < entity->num_pads; ++pad) {
>  			if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
>  				continue;
>  
> @@ -144,7 +142,6 @@ static int vsp1_create_sink_links(struct vsp1_device *vsp1,
>  static int vsp1_uapi_create_links(struct vsp1_device *vsp1)
>  {
>  	struct vsp1_entity *entity;
> -	unsigned int i;
>  	int ret;
>  
>  	list_for_each_entry(entity, &vsp1->entities, list_dev) {
> @@ -177,7 +174,7 @@ static int vsp1_uapi_create_links(struct vsp1_device *vsp1)
>  			return ret;
>  	}
>  
> -	for (i = 0; i < vsp1->info->lif_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->lif_count; ++i) {
>  		if (!vsp1->lif[i])
>  			continue;
>  
> @@ -189,7 +186,7 @@ static int vsp1_uapi_create_links(struct vsp1_device *vsp1)
>  			return ret;
>  	}
>  
> -	for (i = 0; i < vsp1->info->rpf_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->rpf_count; ++i) {
>  		struct vsp1_rwpf *rpf = vsp1->rpf[i];
>  
>  		ret = media_create_pad_link(&rpf->video->video.entity, 0,
> @@ -201,7 +198,7 @@ static int vsp1_uapi_create_links(struct vsp1_device *vsp1)
>  			return ret;
>  	}
>  
> -	for (i = 0; i < vsp1->info->wpf_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i) {
>  		/*
>  		 * Connect the video device to the WPF. All connections are
>  		 * immutable.
> @@ -253,7 +250,6 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
>  	struct media_device *mdev = &vsp1->media_dev;
>  	struct v4l2_device *vdev = &vsp1->v4l2_dev;
>  	struct vsp1_entity *entity;
> -	unsigned int i;
>  	int ret;
>  
>  	mdev->dev = vsp1->dev;
> @@ -365,7 +361,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
>  	 * enabled skip the LIFs, even when present.
>  	 */
>  	if (!vsp1->info->uapi) {
> -		for (i = 0; i < vsp1->info->lif_count; ++i) {
> +		for (unsigned int i = 0; i < vsp1->info->lif_count; ++i) {
>  			struct vsp1_lif *lif;
>  
>  			lif = vsp1_lif_create(vsp1, i);
> @@ -389,7 +385,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
>  		list_add_tail(&vsp1->lut->entity.list_dev, &vsp1->entities);
>  	}
>  
> -	for (i = 0; i < vsp1->info->rpf_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->rpf_count; ++i) {
>  		struct vsp1_rwpf *rpf;
>  
>  		rpf = vsp1_rpf_create(vsp1, i);
> @@ -423,7 +419,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
>  		list_add_tail(&vsp1->sru->entity.list_dev, &vsp1->entities);
>  	}
>  
> -	for (i = 0; i < vsp1->info->uds_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->uds_count; ++i) {
>  		struct vsp1_uds *uds;
>  
>  		uds = vsp1_uds_create(vsp1, i);
> @@ -436,7 +432,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
>  		list_add_tail(&uds->entity.list_dev, &vsp1->entities);
>  	}
>  
> -	for (i = 0; i < vsp1->info->uif_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->uif_count; ++i) {
>  		struct vsp1_uif *uif;
>  
>  		uif = vsp1_uif_create(vsp1, i);
> @@ -449,7 +445,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
>  		list_add_tail(&uif->entity.list_dev, &vsp1->entities);
>  	}
>  
> -	for (i = 0; i < vsp1->info->wpf_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i) {
>  		struct vsp1_rwpf *wpf;
>  
>  		wpf = vsp1_wpf_create(vsp1, i);
> @@ -543,11 +539,10 @@ int vsp1_reset_wpf(struct vsp1_device *vsp1, unsigned int index)
>  
>  static int vsp1_device_init(struct vsp1_device *vsp1)
>  {
> -	unsigned int i;
>  	int ret;
>  
>  	/* Reset any channel that might be running. */
> -	for (i = 0; i < vsp1->info->wpf_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i) {
>  		ret = vsp1_reset_wpf(vsp1, i);
>  		if (ret < 0)
>  			return ret;
> @@ -556,13 +551,13 @@ static int vsp1_device_init(struct vsp1_device *vsp1)
>  	vsp1_write(vsp1, VI6_CLK_DCSWT, (8 << VI6_CLK_DCSWT_CSTPW_SHIFT) |
>  		   (8 << VI6_CLK_DCSWT_CSTRW_SHIFT));
>  
> -	for (i = 0; i < vsp1->info->rpf_count; ++i)
> +	for (unsigned int i = 0; i < vsp1->info->rpf_count; ++i)
>  		vsp1_write(vsp1, VI6_DPR_RPF_ROUTE(i), VI6_DPR_NODE_UNUSED);
>  
> -	for (i = 0; i < vsp1->info->uds_count; ++i)
> +	for (unsigned int i = 0; i < vsp1->info->uds_count; ++i)
>  		vsp1_write(vsp1, VI6_DPR_UDS_ROUTE(i), VI6_DPR_NODE_UNUSED);
>  
> -	for (i = 0; i < vsp1->info->uif_count; ++i)
> +	for (unsigned int i = 0; i < vsp1->info->uif_count; ++i)
>  		vsp1_write(vsp1, VI6_DPR_UIF_ROUTE(i), VI6_DPR_NODE_UNUSED);
>  
>  	vsp1_write(vsp1, VI6_DPR_SRU_ROUTE, VI6_DPR_NODE_UNUSED);
> @@ -587,11 +582,9 @@ static int vsp1_device_init(struct vsp1_device *vsp1)
>  
>  static void vsp1_mask_all_interrupts(struct vsp1_device *vsp1)
>  {
> -	unsigned int i;
> -
> -	for (i = 0; i < vsp1->info->lif_count; ++i)
> +	for (unsigned int i = 0; i < vsp1->info->lif_count; ++i)
>  		vsp1_write(vsp1, VI6_DISP_IRQ_ENB(i), 0);
> -	for (i = 0; i < vsp1->info->wpf_count; ++i)
> +	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i)
>  		vsp1_write(vsp1, VI6_WPF_IRQ_ENB(i), 0);
>  }
>  
> @@ -891,7 +884,6 @@ static const struct vsp1_device_info rzg2l_vsp2_device_info = {
>  static const struct vsp1_device_info *vsp1_lookup_info(struct vsp1_device *vsp1)
>  {
>  	const struct vsp1_device_info *info;
> -	unsigned int i;
>  	u32 model;
>  	u32 soc;
>  
> @@ -909,7 +901,7 @@ static const struct vsp1_device_info *vsp1_lookup_info(struct vsp1_device *vsp1)
>  	model = vsp1->version & VI6_IP_VERSION_MODEL_MASK;
>  	soc = vsp1->version & VI6_IP_VERSION_SOC_MASK;
>  
> -	for (i = 0; i < ARRAY_SIZE(vsp1_device_infos); ++i) {
> +	for (unsigned int i = 0; i < ARRAY_SIZE(vsp1_device_infos); ++i) {
>  		info = &vsp1_device_infos[i];
>  
>  		if (model == info->version && (!info->soc || soc == info->soc))
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_entity.c b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
> index 2ae2a573f0de..26b21559878d 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_entity.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_entity.c
> @@ -372,10 +372,8 @@ int vsp1_subdev_set_pad_format(struct v4l2_subdev *subdev,
>  static int vsp1_entity_init_state(struct v4l2_subdev *subdev,
>  				  struct v4l2_subdev_state *sd_state)
>  {
> -	unsigned int pad;
> -
>  	/* Initialize all pad formats with default values. */
> -	for (pad = 0; pad < subdev->entity.num_pads - 1; ++pad) {
> +	for (unsigned int pad = 0; pad < subdev->entity.num_pads - 1; ++pad) {
>  		struct v4l2_subdev_format format = {
>  			.pad = pad,
>  			.which = sd_state ? V4L2_SUBDEV_FORMAT_TRY
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_hgo.c b/drivers/media/platform/renesas/vsp1/vsp1_hgo.c
> index 0ef512e3a94b..d3eaa7c2d595 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_hgo.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_hgo.c
> @@ -42,7 +42,6 @@ void vsp1_hgo_frame_end(struct vsp1_entity *entity)
>  {
>  	struct vsp1_hgo *hgo = to_hgo(&entity->subdev);
>  	struct vsp1_histogram_buffer *buf;
> -	unsigned int i;
>  	size_t size;
>  	u32 *data;
>  
> @@ -56,7 +55,7 @@ void vsp1_hgo_frame_end(struct vsp1_entity *entity)
>  		*data++ = vsp1_hgo_read(hgo, VI6_HGO_G_MAXMIN);
>  		*data++ = vsp1_hgo_read(hgo, VI6_HGO_G_SUM);
>  
> -		for (i = 0; i < 256; ++i) {
> +		for (unsigned int i = 0; i < 256; ++i) {
>  			vsp1_write(hgo->histo.entity.vsp1,
>  				   VI6_HGO_EXT_HIST_ADDR, i);
>  			*data++ = vsp1_hgo_read(hgo, VI6_HGO_EXT_HIST_DATA);
> @@ -67,7 +66,7 @@ void vsp1_hgo_frame_end(struct vsp1_entity *entity)
>  		*data++ = vsp1_hgo_read(hgo, VI6_HGO_G_MAXMIN);
>  		*data++ = vsp1_hgo_read(hgo, VI6_HGO_G_SUM);
>  
> -		for (i = 0; i < 64; ++i)
> +		for (unsigned int i = 0; i < 64; ++i)
>  			*data++ = vsp1_hgo_read(hgo, VI6_HGO_G_HISTO(i));
>  
>  		size = (2 + 64) * sizeof(u32);
> @@ -80,7 +79,7 @@ void vsp1_hgo_frame_end(struct vsp1_entity *entity)
>  		*data++ = vsp1_hgo_read(hgo, VI6_HGO_G_SUM);
>  		*data++ = vsp1_hgo_read(hgo, VI6_HGO_B_SUM);
>  
> -		for (i = 0; i < 64; ++i) {
> +		for (unsigned int i = 0; i < 64; ++i) {
>  			data[i] = vsp1_hgo_read(hgo, VI6_HGO_R_HISTO(i));
>  			data[i+64] = vsp1_hgo_read(hgo, VI6_HGO_G_HISTO(i));
>  			data[i+128] = vsp1_hgo_read(hgo, VI6_HGO_B_HISTO(i));
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_hgt.c b/drivers/media/platform/renesas/vsp1/vsp1_hgt.c
> index 78b5a9201c70..8c04bdec8510 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_hgt.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_hgt.c
> @@ -42,8 +42,6 @@ void vsp1_hgt_frame_end(struct vsp1_entity *entity)
>  {
>  	struct vsp1_hgt *hgt = to_hgt(&entity->subdev);
>  	struct vsp1_histogram_buffer *buf;
> -	unsigned int m;
> -	unsigned int n;
>  	u32 *data;
>  
>  	buf = vsp1_histogram_buffer_get(&hgt->histo);
> @@ -55,9 +53,10 @@ void vsp1_hgt_frame_end(struct vsp1_entity *entity)
>  	*data++ = vsp1_hgt_read(hgt, VI6_HGT_MAXMIN);
>  	*data++ = vsp1_hgt_read(hgt, VI6_HGT_SUM);
>  
> -	for (m = 0; m < 6; ++m)
> -		for (n = 0; n < 32; ++n)
> +	for (unsigned int m = 0; m < 6; ++m) {
> +		for (unsigned int n = 0; n < 32; ++n)
>  			*data++ = vsp1_hgt_read(hgt, VI6_HGT_HISTO(m, n));
> +	}
>  
>  	vsp1_histogram_buffer_complete(&hgt->histo, buf, HGT_DATA_SIZE);
>  }
> @@ -71,7 +70,6 @@ void vsp1_hgt_frame_end(struct vsp1_entity *entity)
>  static int hgt_hue_areas_try_ctrl(struct v4l2_ctrl *ctrl)
>  {
>  	const u8 *values = ctrl->p_new.p_u8;
> -	unsigned int i;
>  
>  	/*
>  	 * The hardware has constraints on the hue area boundaries beyond the
> @@ -83,7 +81,7 @@ static int hgt_hue_areas_try_ctrl(struct v4l2_ctrl *ctrl)
>  	 *
>  	 * Start by verifying the common part...
>  	 */
> -	for (i = 1; i < (HGT_NUM_HUE_AREAS * 2) - 1; ++i) {
> +	for (unsigned int i = 1; i < (HGT_NUM_HUE_AREAS * 2) - 1; ++i) {
>  		if (values[i] > values[i+1])
>  			return -EINVAL;
>  	}
> @@ -138,7 +136,6 @@ static void hgt_configure_stream(struct vsp1_entity *entity,
>  	unsigned int vratio;
>  	u8 lower;
>  	u8 upper;
> -	unsigned int i;
>  
>  	crop = v4l2_subdev_state_get_crop(state, HISTO_PAD_SINK);
>  	compose = v4l2_subdev_state_get_compose(state, HISTO_PAD_SINK);
> @@ -153,7 +150,7 @@ static void hgt_configure_stream(struct vsp1_entity *entity,
>  		       (crop->height << VI6_HGT_SIZE_VSIZE_SHIFT));
>  
>  	scoped_guard(mutex, hgt->ctrls.lock) {
> -		for (i = 0; i < HGT_NUM_HUE_AREAS; ++i) {
> +		for (unsigned int i = 0; i < HGT_NUM_HUE_AREAS; ++i) {
>  			lower = hgt->hue_areas[i*2 + 0];
>  			upper = hgt->hue_areas[i*2 + 1];
>  			vsp1_hgt_write(hgt, dlb, VI6_HGT_HUE_AREA(i),
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_lut.c b/drivers/media/platform/renesas/vsp1/vsp1_lut.c
> index a22c31e17cb7..6433b5515ef9 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_lut.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_lut.c
> @@ -40,13 +40,12 @@ static inline void vsp1_lut_write(struct vsp1_lut *lut,
>  static int lut_set_table(struct vsp1_lut *lut, struct v4l2_ctrl *ctrl)
>  {
>  	struct vsp1_dl_body *dlb;
> -	unsigned int i;
>  
>  	dlb = vsp1_dl_body_get(lut->pool);
>  	if (!dlb)
>  		return -ENOMEM;
>  
> -	for (i = 0; i < LUT_SIZE; ++i)
> +	for (unsigned int i = 0; i < LUT_SIZE; ++i)
>  		vsp1_dl_body_write(dlb, VI6_LUT_TABLE + 4 * i,
>  				       ctrl->p_new.p_u32[i]);
>  
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
> index 7197f2917417..ca0ec00b9deb 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_pipe.c
> @@ -391,16 +391,15 @@ void vsp1_adjust_color_space(u32 code, u32 *colorspace, u8 *xfer_func,
>  void vsp1_pipeline_reset(struct vsp1_pipeline *pipe)
>  {
>  	struct vsp1_entity *entity;
> -	unsigned int i;
>  
>  	if (pipe->brx) {
>  		struct vsp1_brx *brx = to_brx(&pipe->brx->subdev);
>  
> -		for (i = 0; i < ARRAY_SIZE(brx->inputs); ++i)
> +		for (unsigned int i = 0; i < ARRAY_SIZE(brx->inputs); ++i)
>  			brx->inputs[i].rpf = NULL;
>  	}
>  
> -	for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i)
> +	for (unsigned int i = 0; i < ARRAY_SIZE(pipe->inputs); ++i)
>  		pipe->inputs[i] = NULL;
>  
>  	pipe->output = NULL;
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c
> index b0eae54273a0..fa57e241f827 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c
> @@ -104,14 +104,13 @@ static int __vsp1_video_try_format(struct vsp1_video *video,
>  	const struct vsp1_format_info *info;
>  	unsigned int width = pix->width;
>  	unsigned int height = pix->height;
> -	unsigned int i;
>  
>  	/*
>  	 * Backward compatibility: replace deprecated RGB formats by their XRGB
>  	 * equivalent. This selects the format older userspace applications want
>  	 * while still exposing the new format.
>  	 */
> -	for (i = 0; i < ARRAY_SIZE(xrgb_formats); ++i) {
> +	for (unsigned int i = 0; i < ARRAY_SIZE(xrgb_formats); ++i) {
>  		if (xrgb_formats[i][0] == pix->pixelformat) {
>  			pix->pixelformat = xrgb_formats[i][1];
>  			break;
> @@ -161,7 +160,7 @@ static int __vsp1_video_try_format(struct vsp1_video *video,
>  	 * the datasheet, strides not aligned to a multiple of 128 bytes result
>  	 * in image corruption.
>  	 */
> -	for (i = 0; i < min(info->planes, 2U); ++i) {
> +	for (unsigned int i = 0; i < min(info->planes, 2U); ++i) {
>  		unsigned int hsub = i > 0 ? info->hsub : 1;
>  		unsigned int vsub = i > 0 ? info->vsub : 1;
>  		unsigned int align = 128;
> @@ -209,7 +208,6 @@ vsp1_video_complete_buffer(struct vsp1_video *video)
>  	struct vsp1_pipeline *pipe = video->rwpf->entity.pipe;
>  	struct vsp1_vb2_buffer *next = NULL;
>  	struct vsp1_vb2_buffer *done;
> -	unsigned int i;
>  
>  	scoped_guard(spinlock_irqsave, &video->irqlock) {
>  		if (list_empty(&video->irqqueue))
> @@ -227,7 +225,7 @@ vsp1_video_complete_buffer(struct vsp1_video *video)
>  
>  	done->buf.sequence = pipe->sequence;
>  	done->buf.vb2_buf.timestamp = ktime_get_ns();
> -	for (i = 0; i < done->buf.vb2_buf.num_planes; ++i)
> +	for (unsigned int i = 0; i < done->buf.vb2_buf.num_planes; ++i)
>  		vb2_set_plane_payload(&done->buf.vb2_buf, i,
>  				      vb2_plane_size(&done->buf.vb2_buf, i));
>  	vb2_buffer_done(&done->buf.vb2_buf, VB2_BUF_STATE_DONE);
> @@ -267,7 +265,6 @@ static void vsp1_video_pipeline_run(struct vsp1_pipeline *pipe)
>  	struct vsp1_entity *entity;
>  	struct vsp1_dl_body *dlb;
>  	struct vsp1_dl_list *dl;
> -	unsigned int partition;
>  
>  	dl = vsp1_dl_list_get(pipe->output->dlm);
>  
> @@ -289,7 +286,7 @@ static void vsp1_video_pipeline_run(struct vsp1_pipeline *pipe)
>  	vsp1_video_pipeline_run_partition(pipe, dl, 0);
>  
>  	/* Process consecutive partitions as necessary. */
> -	for (partition = 1; partition < pipe->partitions; ++partition) {
> +	for (unsigned int partition = 1; partition < pipe->partitions; ++partition) {
>  		struct vsp1_dl_list *dl_next;
>  
>  		dl_next = vsp1_dl_list_get(pipe->output->dlm);
> @@ -320,13 +317,12 @@ static void vsp1_video_pipeline_frame_end(struct vsp1_pipeline *pipe,
>  {
>  	struct vsp1_device *vsp1 = pipe->output->entity.vsp1;
>  	enum vsp1_pipeline_state state;
> -	unsigned int i;
>  
>  	/* M2M Pipelines should never call here with an incomplete frame. */
>  	WARN_ON_ONCE(!(completion & VSP1_DL_FRAME_END_COMPLETED));
>  
>  	/* Complete buffers on all video nodes. */
> -	for (i = 0; i < vsp1->info->rpf_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->rpf_count; ++i) {
>  		if (!pipe->inputs[i])
>  			continue;
>  
> @@ -444,7 +440,6 @@ static int vsp1_video_pipeline_build(struct vsp1_pipeline *pipe,
>  	struct media_graph graph;
>  	struct media_entity *entity = &video->video.entity;
>  	struct media_device *mdev = entity->graph_obj.mdev;
> -	unsigned int i;
>  	int ret;
>  
>  	/* Walk the graph to locate the entities and video nodes. */
> @@ -512,7 +507,7 @@ static int vsp1_video_pipeline_build(struct vsp1_pipeline *pipe,
>  	 * Follow links downstream for each input and make sure the graph
>  	 * contains no loop and that all branches end at the output WPF.
>  	 */
> -	for (i = 0; i < video->vsp1->info->rpf_count; ++i) {
> +	for (unsigned int i = 0; i < video->vsp1->info->rpf_count; ++i) {
>  		if (!pipe->inputs[i])
>  			continue;
>  
> @@ -601,13 +596,12 @@ vsp1_video_queue_setup(struct vb2_queue *vq,
>  {
>  	struct vsp1_video *video = vb2_get_drv_priv(vq);
>  	const struct v4l2_pix_format_mplane *format = &video->rwpf->format;
> -	unsigned int i;
>  
>  	if (*nplanes) {
>  		if (*nplanes != format->num_planes)
>  			return -EINVAL;
>  
> -		for (i = 0; i < *nplanes; i++)
> +		for (unsigned int i = 0; i < *nplanes; i++)
>  			if (sizes[i] < format->plane_fmt[i].sizeimage)
>  				return -EINVAL;
>  		return 0;
> @@ -615,7 +609,7 @@ vsp1_video_queue_setup(struct vb2_queue *vq,
>  
>  	*nplanes = format->num_planes;
>  
> -	for (i = 0; i < format->num_planes; ++i)
> +	for (unsigned int i = 0; i < format->num_planes; ++i)
>  		sizes[i] = format->plane_fmt[i].sizeimage;
>  
>  	return 0;
> @@ -677,7 +671,6 @@ static int vsp1_video_pipeline_setup_partitions(struct vsp1_pipeline *pipe)
>  	const struct v4l2_mbus_framefmt *format;
>  	struct vsp1_entity *entity;
>  	unsigned int div_size;
> -	unsigned int i;
>  
>  	/*
>  	 * Partitions are computed on the size before rotation, use the format
> @@ -711,7 +704,7 @@ static int vsp1_video_pipeline_setup_partitions(struct vsp1_pipeline *pipe)
>  	if (!pipe->part_table)
>  		return -ENOMEM;
>  
> -	for (i = 0; i < pipe->partitions; ++i)
> +	for (unsigned int i = 0; i < pipe->partitions; ++i)
>  		vsp1_pipeline_calculate_partition(pipe, &pipe->part_table[i],
>  						  div_size, i);
>  
> @@ -1111,7 +1104,6 @@ static const struct media_entity_operations vsp1_video_media_ops = {
>  
>  void vsp1_video_suspend(struct vsp1_device *vsp1)
>  {
> -	unsigned int i;
>  	int ret;
>  
>  	/*
> @@ -1119,7 +1111,7 @@ void vsp1_video_suspend(struct vsp1_device *vsp1)
>  	 * pipelines twice, first to set them all to the stopping state, and
>  	 * then to wait for the stop to complete.
>  	 */
> -	for (i = 0; i < vsp1->info->wpf_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i) {
>  		struct vsp1_rwpf *wpf = vsp1->wpf[i];
>  		struct vsp1_pipeline *pipe;
>  
> @@ -1136,7 +1128,7 @@ void vsp1_video_suspend(struct vsp1_device *vsp1)
>  		}
>  	}
>  
> -	for (i = 0; i < vsp1->info->wpf_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i) {
>  		struct vsp1_rwpf *wpf = vsp1->wpf[i];
>  		struct vsp1_pipeline *pipe;
>  
> @@ -1157,10 +1149,8 @@ void vsp1_video_suspend(struct vsp1_device *vsp1)
>  
>  void vsp1_video_resume(struct vsp1_device *vsp1)
>  {
> -	unsigned int i;
> -
>  	/* Resume all running pipelines. */
> -	for (i = 0; i < vsp1->info->wpf_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->wpf_count; ++i) {
>  		struct vsp1_rwpf *wpf = vsp1->wpf[i];
>  		struct vsp1_pipeline *pipe;
>  
> diff --git a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> index 0ec707d2913f..821887815eb2 100644
> --- a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> +++ b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c
> @@ -232,7 +232,6 @@ static void wpf_configure_stream(struct vsp1_entity *entity,
>  	const struct v4l2_mbus_framefmt *source_format;
>  	const struct v4l2_mbus_framefmt *sink_format;
>  	unsigned int index = wpf->entity.index;
> -	unsigned int i;
>  	u32 outfmt = 0;
>  	u32 srcrpf = 0;
>  	int ret;
> @@ -314,7 +313,7 @@ static void wpf_configure_stream(struct vsp1_entity *entity,
>  	 * inputs as sub-layers and select the virtual RPF as the master
>  	 * layer. For VSPX configure the enabled sources as masters.
>  	 */
> -	for (i = 0; i < vsp1->info->rpf_count; ++i) {
> +	for (unsigned int i = 0; i < vsp1->info->rpf_count; ++i) {
>  		struct vsp1_rwpf *input = pipe->inputs[i];
>  
>  		if (!input)
> @@ -399,7 +398,6 @@ static void wpf_configure_partition(struct vsp1_entity *entity,
>  	unsigned int left;
>  	unsigned int offset;
>  	unsigned int flip;
> -	unsigned int i;
>  
>  	/*
>  	 * Cropping. The partition algorithm can split the image into multiple
> @@ -448,7 +446,7 @@ static void wpf_configure_partition(struct vsp1_entity *entity,
>  	else
>  		offset = left;
>  
> -	for (i = 0; i < format->num_planes; ++i) {
> +	for (unsigned int i = 0; i < format->num_planes; ++i) {
>  		unsigned int hsub = i > 0 ? fmtinfo->hsub : 1;
>  		unsigned int vsub = i > 0 ? fmtinfo->vsub : 1;
>  
> @@ -490,7 +488,7 @@ static void wpf_configure_partition(struct vsp1_entity *entity,
>  		 * Compute the output coordinate. The partition
>  		 * horizontal (left) offset becomes a vertical offset.
>  		 */
> -		for (i = 0; i < format->num_planes; ++i) {
> +		for (unsigned int i = 0; i < format->num_planes; ++i) {
>  			unsigned int hsub = i > 0 ? fmtinfo->hsub : 1;
>  
>  			mem.addr[i] += hoffset / hsub
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> 

-- 
Kind Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 11/11] media: renesas: vsp1: Drop deprecated vsp1_du_setup_lif() function
  2026-05-11 23:56 ` [PATCH 11/11] media: renesas: vsp1: Drop deprecated vsp1_du_setup_lif() function Laurent Pinchart
@ 2026-05-13 20:31   ` Niklas Söderlund
  0 siblings, 0 replies; 24+ messages in thread
From: Niklas Söderlund @ 2026-05-13 20:31 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, dri-devel, linux-renesas-soc, Tomi Valkeinen,
	Kieran Bingham, Biju Das, David Airlie, Simona Vetter

Hi Laurent,

Nice series!

On 2026-05-12 02:56:35 +0300, Laurent Pinchart wrote:
> The vsp1_du_setup_lif() is deprecated and its last users are gone. Drop
> it.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> ---
>  include/media/vsp1.h | 9 ---------
>  1 file changed, 9 deletions(-)
> 
> diff --git a/include/media/vsp1.h b/include/media/vsp1.h
> index d2085cdb7fcb..98089e0a4385 100644
> --- a/include/media/vsp1.h
> +++ b/include/media/vsp1.h
> @@ -48,15 +48,6 @@ int vsp1_du_enable(struct device *dev, unsigned int pipe_index,
>  		   const struct vsp1_du_lif_config *cfg);
>  int vsp1_du_disable(struct device *dev, unsigned int pipe_index);
>  
> -static inline int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
> -				    const struct vsp1_du_lif_config *cfg)
> -{
> -	if (cfg)
> -		return vsp1_du_enable(dev, pipe_index, cfg);
> -	else
> -		return vsp1_du_disable(dev, pipe_index);
> -}
> -
>  /**
>   * struct vsp1_du_atomic_config - VSP atomic configuration parameters
>   * @pixelformat: plane pixel format (V4L2 4CC)
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> 

-- 
Kind Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2026-05-13 20:31 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-11 23:56 [PATCH 00/11] media: renesas: vsp1: Modernize the driver Laurent Pinchart
2026-05-11 23:56 ` [PATCH 01/11] media: renesas: vsp1: Avoid forward function declaration Laurent Pinchart
2026-05-13 19:09   ` Niklas Söderlund
2026-05-11 23:56 ` [PATCH 02/11] media: renesas: vsp1: Split vsp1_du_setup_lif() Laurent Pinchart
2026-05-13 19:11   ` Niklas Söderlund
2026-05-11 23:56 ` [PATCH 03/11] drm: renesas: rcar-du: Switch to new VSP API Laurent Pinchart
2026-05-13 19:12   ` Niklas Söderlund
2026-05-11 23:56 ` [PATCH 04/11] drm: renesas: rz-du: " Laurent Pinchart
2026-05-13 19:13   ` Niklas Söderlund
2026-05-11 23:56 ` [PATCH 05/11] media: renesas: vsp1: Use mutex guards Laurent Pinchart
2026-05-13 19:20   ` Niklas Söderlund
2026-05-13 19:40     ` Laurent Pinchart
2026-05-11 23:56 ` [PATCH 06/11] media: renesas: vsp1: Use mutex scoped guards Laurent Pinchart
2026-05-13 19:24   ` Niklas Söderlund
2026-05-11 23:56 ` [PATCH 07/11] media: renesas: vsp1: Use spinlock guards Laurent Pinchart
2026-05-13 19:29   ` Niklas Söderlund
2026-05-11 23:56 ` [PATCH 08/11] media: renesas: vsp1: Use spinlock scoped guards Laurent Pinchart
2026-05-13 19:37   ` Niklas Söderlund
2026-05-11 23:56 ` [PATCH 09/11] media: renesas: vsp1: Simplify iteration over format arrays Laurent Pinchart
2026-05-13 19:44   ` Niklas Söderlund
2026-05-11 23:56 ` [PATCH 10/11] media: renesas: vsp1: Declare index variables in for loop statement Laurent Pinchart
2026-05-13 20:29   ` Niklas Söderlund
2026-05-11 23:56 ` [PATCH 11/11] media: renesas: vsp1: Drop deprecated vsp1_du_setup_lif() function Laurent Pinchart
2026-05-13 20:31   ` Niklas Söderlund

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox