]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: renesas: vsp1: Use mutex guards
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Mon, 11 May 2026 23:56:29 +0000 (02:56 +0300)
committerHans Verkuil <hverkuil+cisco@kernel.org>
Thu, 21 May 2026 07:10:15 +0000 (09:10 +0200)
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.

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Link: https://patch.msgid.link/20260511235637.3468558-6-laurent.pinchart+renesas@ideasonboard.com
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
drivers/media/platform/renesas/vsp1/vsp1_brx.c
drivers/media/platform/renesas/vsp1/vsp1_drm.c
drivers/media/platform/renesas/vsp1/vsp1_entity.c
drivers/media/platform/renesas/vsp1/vsp1_histo.c
drivers/media/platform/renesas/vsp1/vsp1_hsit.c
drivers/media/platform/renesas/vsp1/vsp1_rwpf.c
drivers/media/platform/renesas/vsp1/vsp1_sru.c
drivers/media/platform/renesas/vsp1/vsp1_uds.c
drivers/media/platform/renesas/vsp1/vsp1_uif.c
drivers/media/platform/renesas/vsp1/vsp1_video.c
drivers/media/platform/renesas/vsp1/vsp1_wpf.c

index b1a2c68e994462cfcad96a39e294b4357650c29c..ce68d911ac301176093d3cd7dbeaa393fae02311 100644 (file)
@@ -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);
 
@@ -172,9 +169,7 @@ static int brx_set_format(struct v4l2_subdev *subdev,
                *format = fmt->format;
        }
 
-done:
-       mutex_unlock(&brx->entity.lock);
-       return ret;
+       return 0;
 }
 
 static int brx_get_selection(struct v4l2_subdev *subdev,
@@ -219,7 +214,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;
@@ -227,13 +221,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
@@ -254,9 +246,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 = {
index 1f431874064dfab741894f961cdeffaccde02cd8..1439cf7bfb59fa3f9b4c61a229498ef890b6f61a 100644 (file)
@@ -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);
 
index 1dad9589768c2349b806f5cd7a507990a78789f9..1a1dafe5331e05e8816acf48546bba86599ba77f 100644 (file)
@@ -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,
index 3f87a2c9df0ef2550d576c90412c0b57d9772667..72f6ef2fdc4f9f72b7c7598f9e9a18e2c3daa7b8 100644 (file)
@@ -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,
index 830e124beb7bc5f0f804418150b595d5d80f7856..df069c228243a7cabad319a2131fe8d752c94639 100644 (file)
@@ -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 = {
index c72518b29f84b3577dd772e1595bf898531c4b81..ced01870acd6ef884d0a02a8a714f42542622115 100644 (file)
@@ -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 = {
index 94149da0c90032ce6d526ec563f81c2e19701040..3fd9fde5c7242aaa702e9ccb84e9626ea6d6cc4d 100644 (file)
@@ -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 = {
index dd4722315c564e0180847e4bebac1ece35325b59..9f7bb112929ed257f7ccffff28ebada602d63c65 100644 (file)
@@ -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;
 }
 
 /* -----------------------------------------------------------------------------
index 3aefe5c9d421a77ac27dde2fb7ba2ba77c822c76..52dbfe58a70d22a01b22408aa665a0efadb1ee23 100644 (file)
@@ -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;
 }
 
 /* -----------------------------------------------------------------------------
index fe1dac11d4aea1659c6b75a05537ed7d6439024a..a9ed6bc87b0047ae1b0f0ab1dde7f405ec9adc0a 100644 (file)
@@ -595,9 +595,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);
 }
 
 /* -----------------------------------------------------------------------------
@@ -938,9 +938,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;
 }
@@ -972,19 +972,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
index cd6c5592221b6ec2af0dae54cdcc268aff14f05d..e7ed3c8e9e905bbbbe9632b84ec9486320b36271 100644 (file)
@@ -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)