From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
To: Brandon Brnich <b-brnich@ti.com>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: detheridge@ti.com, mchehab@kernel.org, nas.chung@chipsnmedia.com,
jackson.lee@chipsnmedia.com
Subject: Re: [PATCH 2/2] media: chips-media: wave5: Fix Reports from Kernel Lock Validator
Date: Wed, 29 Apr 2026 14:32:19 -0400 [thread overview]
Message-ID: <d755f9d16f64b9c5f2e63334c5984710a6f20ddb.camel@collabora.com> (raw)
In-Reply-To: <20260402184554.1751445-2-b-brnich@ti.com>
[-- Attachment #1: Type: text/plain, Size: 5191 bytes --]
Le jeudi 02 avril 2026 à 13:45 -0500, Brandon Brnich a écrit :
> handle_dynamic_resolution change requires that the state_lock be acquired
> based on the lockdep_assert_held. However, the
> handle_dynamic_resolution_change call in initialize_sequence does not
> properly obtain the lock before calling.
>
> Since the v4l2_ctrl_find and s_ctrl can sleep, they should not be called
> while a lock is already held. Store off the fbc_buf_count then properly
> update control once lock has been freed.
>
> Signed-off-by: Brandon Brnich <b-brnich@ti.com>
> ---
> .../chips-media/wave5/wave5-vpu-dec.c | 50 ++++++++++++++-----
> 1 file changed, 37 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c
> index 80e1831a42e0..62b21b2c5e29 100644
> --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c
> +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c
> @@ -283,10 +283,25 @@ static void send_eos_event(struct vpu_instance *inst)
> inst->sent_eos = true;
> }
>
> +static void wave5_update_min_bufs_ctrl(struct vpu_instance *inst, u32 fbc_buf_count)
> +{
> + struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx;
> + struct v4l2_ctrl *ctrl;
> +
> + if (!fbc_buf_count ||
> + fbc_buf_count == v4l2_m2m_num_dst_bufs_ready(m2m_ctx))
> + return;
> +
> + ctrl = v4l2_ctrl_find(&inst->v4l2_ctrl_hdl,
> + V4L2_CID_MIN_BUFFERS_FOR_CAPTURE);
> + if (ctrl)
> + v4l2_ctrl_s_ctrl(ctrl, fbc_buf_count);
> +}
> +
> +
I might have to drop that extra line, but I'll take care.
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
> static int handle_dynamic_resolution_change(struct vpu_instance *inst)
> {
> struct v4l2_fh *fh = &inst->v4l2_fh;
> - struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx;
>
> static const struct v4l2_event vpu_event_src_ch = {
> .type = V4L2_EVENT_SOURCE_CHANGE,
> @@ -305,14 +320,6 @@ static int handle_dynamic_resolution_change(struct vpu_instance *inst)
>
> inst->needs_reallocation = true;
> inst->fbc_buf_count = initial_info->min_frame_buffer_count + 1;
> - if (inst->fbc_buf_count != v4l2_m2m_num_dst_bufs_ready(m2m_ctx)) {
> - struct v4l2_ctrl *ctrl;
> -
> - ctrl = v4l2_ctrl_find(&inst->v4l2_ctrl_hdl,
> - V4L2_CID_MIN_BUFFERS_FOR_CAPTURE);
> - if (ctrl)
> - v4l2_ctrl_s_ctrl(ctrl, inst->fbc_buf_count);
> - }
>
> if (p_dec_info->initial_info_obtained) {
> const struct vpu_format *vpu_fmt;
> @@ -439,19 +446,24 @@ static void wave5_vpu_dec_finish_decode(struct vpu_instance *inst)
> if ((dec_info.index_frame_display == DISPLAY_IDX_FLAG_SEQ_END ||
> dec_info.sequence_changed)) {
> unsigned long flags;
> + u32 fbc_buf_count = 0;
>
> spin_lock_irqsave(&inst->state_spinlock, flags);
> if (!v4l2_m2m_has_stopped(m2m_ctx)) {
> switch_state(inst, VPU_INST_STATE_STOP);
>
> - if (dec_info.sequence_changed)
> + if (dec_info.sequence_changed) {
> handle_dynamic_resolution_change(inst);
> - else
> + fbc_buf_count = inst->fbc_buf_count;
> + } else {
> send_eos_event(inst);
> + }
>
> flag_last_buffer_done(inst);
> }
> spin_unlock_irqrestore(&inst->state_spinlock, flags);
> +
> + wave5_update_min_bufs_ctrl(inst, fbc_buf_count);
> }
>
> if (inst->sent_eos &&
> @@ -1583,6 +1595,8 @@ static const struct vpu_instance_ops wave5_vpu_dec_inst_ops = {
> static int initialize_sequence(struct vpu_instance *inst)
> {
> struct dec_initial_info initial_info;
> + unsigned long flags;
> + u32 fbc_buf_count;
> int ret = 0;
>
> memset(&initial_info, 0, sizeof(struct dec_initial_info));
> @@ -1605,7 +1619,12 @@ static int initialize_sequence(struct vpu_instance *inst)
> return ret;
> }
>
> + spin_lock_irqsave(&inst->state_spinlock, flags);
> handle_dynamic_resolution_change(inst);
> + fbc_buf_count = inst->fbc_buf_count;
> + spin_unlock_irqrestore(&inst->state_spinlock, flags);
> +
> + wave5_update_min_bufs_ctrl(inst, fbc_buf_count);
>
> return 0;
> }
> @@ -1647,6 +1666,7 @@ static void wave5_vpu_dec_device_run(void *priv)
> ret = initialize_sequence(inst);
> if (ret) {
> unsigned long flags;
> + u32 fbc_buf_count = 0;
>
> spin_lock_irqsave(&inst->state_spinlock, flags);
> if (wave5_is_draining_or_eos(inst) &&
> @@ -1655,14 +1675,18 @@ static void wave5_vpu_dec_device_run(void *priv)
>
> switch_state(inst, VPU_INST_STATE_STOP);
>
> - if (vb2_is_streaming(dst_vq))
> + if (vb2_is_streaming(dst_vq)) {
> send_eos_event(inst);
> - else
> + } else {
> handle_dynamic_resolution_change(inst);
> + fbc_buf_count = inst->fbc_buf_count;
> + }
>
> flag_last_buffer_done(inst);
> }
> spin_unlock_irqrestore(&inst->state_spinlock, flags);
> +
> + wave5_update_min_bufs_ctrl(inst, fbc_buf_count);
> } else {
> set_instance_state(inst, VPU_INST_STATE_INIT_SEQ);
> }
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-04-29 18:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 18:45 [PATCH 1/2] media: chips-media: wave5: Release m2m_ctx after Instance Removed from List Brandon Brnich
2026-04-02 18:45 ` [PATCH 2/2] media: chips-media: wave5: Fix Reports from Kernel Lock Validator Brandon Brnich
2026-04-03 0:52 ` jackson.lee
2026-04-29 18:32 ` Nicolas Dufresne [this message]
2026-04-03 0:51 ` [PATCH 1/2] media: chips-media: wave5: Release m2m_ctx after Instance Removed from List jackson.lee
2026-04-29 18:29 ` Nicolas Dufresne
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d755f9d16f64b9c5f2e63334c5984710a6f20ddb.camel@collabora.com \
--to=nicolas.dufresne@collabora.com \
--cc=b-brnich@ti.com \
--cc=detheridge@ti.com \
--cc=jackson.lee@chipsnmedia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=nas.chung@chipsnmedia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox