2022-12-10 07:34:50

by Yunfei Dong (董云飞)

[permalink] [raw]
Subject: [PATCH 0/5] media: mediatek: vcodec: Fix power_VideoCall test fail

Random getting below error message when test power_VideoCall/control.49_vp9:
pc : __list_del_entry_valid+0xb0/0xfc
lr : __list_del_entry_valid+0xac/0xfc
sp : ffffffc020f23ce0

The lat_buf in core list won't be deleted when one instance decode done.
Will access invalid released lat_buf list when queue work continue to decode.
Firstly, remove all unused lat_buf to the top of core list, making sure
these buffers can be decoded in highest priority; lastly, remove all unused
lat_buf when the instance is freed.

patch 1 add params to record lat and core lat_buf count.
patch 2 using each instance lat_buf count replace core ready list.
patch 3 move lat_buf to the top of core list.
patch 4 add core decode done event.
patch 5 remove unused lat_buf.
---
Yunfei Dong (5):
media: mediatek: vcodec: add params to record lat and core lat_buf
count
media: mediatek: vcodec: using each instance lat_buf count replace
core ready list
media: mediatek: vcodec: move lat_buf to the top of core list
media: mediatek: vcodec: add core decode done event
media: mediatek: vcodec: remove unused lat_buf

.../platform/mediatek/vcodec/vdec_msg_queue.c | 74 +++++++++++++++++--
.../platform/mediatek/vcodec/vdec_msg_queue.h | 13 ++++
2 files changed, 81 insertions(+), 6 deletions(-)

--
2.18.0


2022-12-10 07:37:41

by Yunfei Dong (董云飞)

[permalink] [raw]
Subject: [PATCH 5/5] media: mediatek: vcodec: remove unused lat_buf

Remove unused lat_buf from core list, or leading to core list access
NULL point.

Fixes: 365e4ba01df4 ("media: mtk-vcodec: Add work queue for core hardware decode")
Signed-off-by: Yunfei Dong <[email protected]>
---
.../platform/mediatek/vcodec/vdec_msg_queue.c | 20 ++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
index 9bbbd3fa20eb..3f18eca7dbdd 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
@@ -185,7 +185,7 @@ bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue)
struct vdec_lat_buf *buf, *tmp;
struct vdec_msg_queue_ctx *core_ctx;
long timeout_jiff;
- int ret;
+ int ret, count = 0;

core_ctx = &msg_queue->ctx->dev->msg_queue_core_ctx;
spin_lock(&core_ctx->ready_lock);
@@ -209,8 +209,22 @@ bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue)
msg_queue->lat_ctx.ready_num);
return true;
}
- mtk_v4l2_err("failed with lat buf isn't full: %d",
- msg_queue->lat_ctx.ready_num);
+
+ spin_lock(&core_ctx->ready_lock);
+ list_for_each_entry_safe(buf, tmp, &core_ctx->ready_queue, core_list) {
+ if (buf && buf->ctx == msg_queue->ctx) {
+ count++;
+ spin_lock(&msg_queue->lat_ctx.ready_lock);
+ list_del(&buf->core_list);
+ spin_unlock(&msg_queue->lat_ctx.ready_lock);
+ }
+ }
+ spin_unlock(&core_ctx->ready_lock);
+
+ mtk_v4l2_err("failed with lat buf isn't full: list(%d %d) count:%d",
+ atomic_read(&msg_queue->lat_list_cnt),
+ atomic_read(&msg_queue->core_list_cnt), count);
+
return false;
}

--
2.18.0

2022-12-10 07:54:42

by Yunfei Dong (董云飞)

[permalink] [raw]
Subject: [PATCH 2/5] media: mediatek: vcodec: using each instance lat_buf count replace core ready list

Core Hardware decoder depends on each instance lat_buf count,
calling queue_work decode again when the lat_buf count of each instance
isn't zero.

Fixes: 365e4ba01df4 ("media: mtk-vcodec: Add work queue for core hardware decode")
Signed-off-by: Yunfei Dong <[email protected]>
---
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
index af7ddba1923a..2b88065d4d2a 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
@@ -247,7 +247,7 @@ static void vdec_msg_queue_core_work(struct work_struct *work)
mtk_vcodec_dec_disable_hardware(ctx, MTK_VDEC_CORE);
vdec_msg_queue_qbuf(&ctx->msg_queue.lat_ctx, lat_buf);

- if (!list_empty(&dev->msg_queue_core_ctx.ready_queue)) {
+ if (atomic_read(&lat_buf->ctx->msg_queue.core_list_cnt)) {
mtk_v4l2_debug(3, "re-schedule to decode for core: %d",
dev->msg_queue_core_ctx.ready_num);
queue_work(dev->core_workqueue, &msg_queue->core_work);
--
2.18.0

2022-12-10 08:04:41

by Yunfei Dong (董云飞)

[permalink] [raw]
Subject: [PATCH 4/5] media: mediatek: vcodec: add core decode done event

Need to make sure core decode done before current instance is free.

Fixes: 365e4ba01df4 ("media: mtk-vcodec: Add work queue for core hardware decode")
Signed-off-by: Yunfei Dong <[email protected]>
---
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c | 4 +++-
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
index 6275536d5063..9bbbd3fa20eb 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
@@ -201,7 +201,7 @@ bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue)
spin_unlock(&core_ctx->ready_lock);

timeout_jiff = msecs_to_jiffies(1000 * (NUM_BUFFER_COUNT + 2));
- ret = wait_event_timeout(msg_queue->lat_ctx.ready_to_use,
+ ret = wait_event_timeout(msg_queue->ctx->msg_queue.core_dec_done,
msg_queue->lat_ctx.ready_num == NUM_BUFFER_COUNT,
timeout_jiff);
if (ret) {
@@ -262,6 +262,7 @@ static void vdec_msg_queue_core_work(struct work_struct *work)
mtk_vcodec_dec_disable_hardware(ctx, MTK_VDEC_CORE);
vdec_msg_queue_qbuf(&ctx->msg_queue.lat_ctx, lat_buf);

+ wake_up_all(&ctx->msg_queue.core_dec_done);
if (atomic_read(&lat_buf->ctx->msg_queue.core_list_cnt)) {
mtk_v4l2_debug(3, "re-schedule to decode for core: %d",
dev->msg_queue_core_ctx.ready_num);
@@ -287,6 +288,7 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue,
atomic_set(&msg_queue->lat_list_cnt, 0);
atomic_set(&msg_queue->core_list_cnt, 0);
mutex_init(&msg_queue->list_cnt_mutex);
+ init_waitqueue_head(&msg_queue->core_dec_done);

msg_queue->wdma_addr.size =
vde_msg_queue_get_trans_size(ctx->picinfo.buf_w,
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
index 53ad05396c8c..0944b6436fb6 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
+++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
@@ -77,6 +77,7 @@ struct vdec_lat_buf {
* @lat_list_cnt: used to record each instance lat list count
* @core_list_cnt: used to record each instance core list count
* @list_cnt_mutex: used to protect list count
+ * @core_dec_done: core work queue decode done event
*/
struct vdec_msg_queue {
struct vdec_lat_buf lat_buf[NUM_BUFFER_COUNT];
@@ -93,6 +94,7 @@ struct vdec_msg_queue {
atomic_t core_list_cnt;
/* Protects access to lat and core list cnt */
struct mutex list_cnt_mutex;
+ wait_queue_head_t core_dec_done;
};

/**
--
2.18.0

2022-12-10 08:20:24

by Yunfei Dong (董云飞)

[permalink] [raw]
Subject: [PATCH 1/5] media: mediatek: vcodec: add params to record lat and core lat_buf count

Using lat_buf to share decoder information between lat and core work
queue, adding params to record the buf count.

Fixes: 365e4ba01df4 ("media: mtk-vcodec: Add work queue for core hardware decode")
Signed-off-by: Yunfei Dong <[email protected]>
---
.../platform/mediatek/vcodec/vdec_msg_queue.c | 32 ++++++++++++++++++-
.../platform/mediatek/vcodec/vdec_msg_queue.h | 9 ++++++
2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
index dc2004790a47..af7ddba1923a 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
@@ -52,6 +52,30 @@ static struct list_head *vdec_get_buf_list(int hardware_index, struct vdec_lat_b
}
}

+static void vdec_msg_queue_inc(struct vdec_msg_queue *msg_queue, int hardware_index)
+{
+ mutex_lock(&msg_queue->list_cnt_mutex);
+
+ if (hardware_index == MTK_VDEC_CORE)
+ atomic_inc(&msg_queue->core_list_cnt);
+ else
+ atomic_inc(&msg_queue->lat_list_cnt);
+
+ mutex_unlock(&msg_queue->list_cnt_mutex);
+}
+
+static void vdec_msg_queue_dec(struct vdec_msg_queue *msg_queue, int hardware_index)
+{
+ mutex_lock(&msg_queue->list_cnt_mutex);
+
+ if (hardware_index == MTK_VDEC_CORE)
+ atomic_dec(&msg_queue->core_list_cnt);
+ else
+ atomic_dec(&msg_queue->lat_list_cnt);
+
+ mutex_unlock(&msg_queue->list_cnt_mutex);
+}
+
int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *msg_ctx, struct vdec_lat_buf *buf)
{
struct list_head *head;
@@ -72,6 +96,7 @@ int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *msg_ctx, struct vdec_lat_buf
queue_work(buf->ctx->dev->core_workqueue,
&buf->ctx->msg_queue.core_work);

+ vdec_msg_queue_inc(&buf->ctx->msg_queue, msg_ctx->hardware_index);
mtk_v4l2_debug(3, "enqueue buf type: %d addr: 0x%p num: %d",
msg_ctx->hardware_index, buf, msg_ctx->ready_num);
spin_unlock(&msg_ctx->ready_lock);
@@ -127,6 +152,7 @@ struct vdec_lat_buf *vdec_msg_queue_dqbuf(struct vdec_msg_queue_ctx *msg_ctx)
return NULL;
}
list_del(head);
+ vdec_msg_queue_dec(&buf->ctx->msg_queue, msg_ctx->hardware_index);

msg_ctx->ready_num--;
mtk_v4l2_debug(3, "dqueue buf type:%d addr: 0x%p num: %d",
@@ -241,10 +267,14 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue,

vdec_msg_queue_init_ctx(&msg_queue->lat_ctx, MTK_VDEC_LAT0);
INIT_WORK(&msg_queue->core_work, vdec_msg_queue_core_work);
+
+ atomic_set(&msg_queue->lat_list_cnt, 0);
+ atomic_set(&msg_queue->core_list_cnt, 0);
+ mutex_init(&msg_queue->list_cnt_mutex);
+
msg_queue->wdma_addr.size =
vde_msg_queue_get_trans_size(ctx->picinfo.buf_w,
ctx->picinfo.buf_h);
-
err = mtk_vcodec_mem_alloc(ctx, &msg_queue->wdma_addr);
if (err) {
mtk_v4l2_err("failed to allocate wdma_addr buf");
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
index c43d427f5f54..94e01a618c5a 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
+++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
@@ -72,6 +72,10 @@ struct vdec_lat_buf {
* @wdma_wptr_addr: ube write point
* @core_work: core hardware work
* @lat_ctx: used to store lat buffer list
+ *
+ * @lat_list_cnt: used to record each instance lat list count
+ * @core_list_cnt: used to record each instance core list count
+ * @list_cnt_mutex: used to protect list count
*/
struct vdec_msg_queue {
struct vdec_lat_buf lat_buf[NUM_BUFFER_COUNT];
@@ -82,6 +86,11 @@ struct vdec_msg_queue {

struct work_struct core_work;
struct vdec_msg_queue_ctx lat_ctx;
+
+ atomic_t lat_list_cnt;
+ atomic_t core_list_cnt;
+ /* Protects access to lat and core list cnt */
+ struct mutex list_cnt_mutex;
};

/**
--
2.18.0

2022-12-10 08:22:40

by Yunfei Dong (董云飞)

[permalink] [raw]
Subject: [PATCH 3/5] media: mediatek: vcodec: move lat_buf to the top of core list

Current instance will decode done when begin to wait lat buf full,
move the lat_buf of current instance to the top of core list to make
sure current instance's lat_buf will be used firstly.

Fixes: 365e4ba01df4 ("media: mtk-vcodec: Add work queue for core hardware decode")
Signed-off-by: Yunfei Dong <[email protected]>
---
.../platform/mediatek/vcodec/vdec_msg_queue.c | 16 ++++++++++++++++
.../platform/mediatek/vcodec/vdec_msg_queue.h | 2 ++
2 files changed, 18 insertions(+)

diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
index 2b88065d4d2a..6275536d5063 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
@@ -182,9 +182,24 @@ void vdec_msg_queue_update_ube_wptr(struct vdec_msg_queue *msg_queue, uint64_t u

bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue)
{
+ struct vdec_lat_buf *buf, *tmp;
+ struct vdec_msg_queue_ctx *core_ctx;
long timeout_jiff;
int ret;

+ core_ctx = &msg_queue->ctx->dev->msg_queue_core_ctx;
+ spin_lock(&core_ctx->ready_lock);
+ list_for_each_entry_safe(buf, tmp, &core_ctx->ready_queue, core_list) {
+ if (buf && buf->ctx == msg_queue->ctx) {
+ spin_lock(&msg_queue->lat_ctx.ready_lock);
+ list_move(&buf->core_list, &core_ctx->ready_queue);
+ spin_unlock(&msg_queue->lat_ctx.ready_lock);
+ queue_work(buf->ctx->dev->core_workqueue,
+ &buf->ctx->msg_queue.core_work);
+ }
+ }
+ spin_unlock(&core_ctx->ready_lock);
+
timeout_jiff = msecs_to_jiffies(1000 * (NUM_BUFFER_COUNT + 2));
ret = wait_event_timeout(msg_queue->lat_ctx.ready_to_use,
msg_queue->lat_ctx.ready_num == NUM_BUFFER_COUNT,
@@ -268,6 +283,7 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue,
vdec_msg_queue_init_ctx(&msg_queue->lat_ctx, MTK_VDEC_LAT0);
INIT_WORK(&msg_queue->core_work, vdec_msg_queue_core_work);

+ msg_queue->ctx = ctx;
atomic_set(&msg_queue->lat_list_cnt, 0);
atomic_set(&msg_queue->core_list_cnt, 0);
mutex_init(&msg_queue->list_cnt_mutex);
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
index 94e01a618c5a..53ad05396c8c 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
+++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
@@ -72,6 +72,7 @@ struct vdec_lat_buf {
* @wdma_wptr_addr: ube write point
* @core_work: core hardware work
* @lat_ctx: used to store lat buffer list
+ * @ctx: point to mtk_vcodec_ctx
*
* @lat_list_cnt: used to record each instance lat list count
* @core_list_cnt: used to record each instance core list count
@@ -86,6 +87,7 @@ struct vdec_msg_queue {

struct work_struct core_work;
struct vdec_msg_queue_ctx lat_ctx;
+ struct mtk_vcodec_ctx *ctx;

atomic_t lat_list_cnt;
atomic_t core_list_cnt;
--
2.18.0

Subject: Re: [PATCH 1/5] media: mediatek: vcodec: add params to record lat and core lat_buf count

Il 10/12/22 08:32, Yunfei Dong ha scritto:
> Using lat_buf to share decoder information between lat and core work
> queue, adding params to record the buf count.
>
> Fixes: 365e4ba01df4 ("media: mtk-vcodec: Add work queue for core hardware decode")
> Signed-off-by: Yunfei Dong <[email protected]>
> ---
> .../platform/mediatek/vcodec/vdec_msg_queue.c | 32 ++++++++++++++++++-
> .../platform/mediatek/vcodec/vdec_msg_queue.h | 9 ++++++
> 2 files changed, 40 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
> index dc2004790a47..af7ddba1923a 100644
> --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
> +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
> @@ -52,6 +52,30 @@ static struct list_head *vdec_get_buf_list(int hardware_index, struct vdec_lat_b
> }
> }
>
> +static void vdec_msg_queue_inc(struct vdec_msg_queue *msg_queue, int hardware_index)
> +{
> + mutex_lock(&msg_queue->list_cnt_mutex);

I doubt that you need to use this mutex, as you're using atomics...

> +
> + if (hardware_index == MTK_VDEC_CORE)
> + atomic_inc(&msg_queue->core_list_cnt);
> + else
> + atomic_inc(&msg_queue->lat_list_cnt);
> +

This branch (with the relevant appropriate changes) can be simplified as

atomic_inc(&msg_queue->list_cnt[hardware_index]);

...where list_cnt is an array, and hardware_index is an enumeration.

> + mutex_unlock(&msg_queue->list_cnt_mutex);
> +}
> +
> +static void vdec_msg_queue_dec(struct vdec_msg_queue *msg_queue, int hardware_index)
> +{
> + mutex_lock(&msg_queue->list_cnt_mutex);
> +
> + if (hardware_index == MTK_VDEC_CORE)
> + atomic_dec(&msg_queue->core_list_cnt);
> + else
> + atomic_dec(&msg_queue->lat_list_cnt);

Same here.

> +
> + mutex_unlock(&msg_queue->list_cnt_mutex);
> +}
> +

Regards,
Angelo

Subject: Re: [PATCH 3/5] media: mediatek: vcodec: move lat_buf to the top of core list

Il 10/12/22 08:32, Yunfei Dong ha scritto:
> Current instance will decode done when begin to wait lat buf full,
> move the lat_buf of current instance to the top of core list to make
> sure current instance's lat_buf will be used firstly.
>
> Fixes: 365e4ba01df4 ("media: mtk-vcodec: Add work queue for core hardware decode")
> Signed-off-by: Yunfei Dong <[email protected]>
> ---
> .../platform/mediatek/vcodec/vdec_msg_queue.c | 16 ++++++++++++++++
> .../platform/mediatek/vcodec/vdec_msg_queue.h | 2 ++
> 2 files changed, 18 insertions(+)
>
> diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
> index 2b88065d4d2a..6275536d5063 100644
> --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
> +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
> @@ -182,9 +182,24 @@ void vdec_msg_queue_update_ube_wptr(struct vdec_msg_queue *msg_queue, uint64_t u
>
> bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue)
> {
> + struct vdec_lat_buf *buf, *tmp;
> + struct vdec_msg_queue_ctx *core_ctx;
> long timeout_jiff;
> int ret;
>
> + core_ctx = &msg_queue->ctx->dev->msg_queue_core_ctx;
> + spin_lock(&core_ctx->ready_lock);
> + list_for_each_entry_safe(buf, tmp, &core_ctx->ready_queue, core_list) {
> + if (buf && buf->ctx == msg_queue->ctx) {
> + spin_lock(&msg_queue->lat_ctx.ready_lock);
> + list_move(&buf->core_list, &core_ctx->ready_queue);
> + spin_unlock(&msg_queue->lat_ctx.ready_lock);
> + queue_work(buf->ctx->dev->core_workqueue,
> + &buf->ctx->msg_queue.core_work);
> + }
> + }
> + spin_unlock(&core_ctx->ready_lock);
> +
> timeout_jiff = msecs_to_jiffies(1000 * (NUM_BUFFER_COUNT + 2));
> ret = wait_event_timeout(msg_queue->lat_ctx.ready_to_use,
> msg_queue->lat_ctx.ready_num == NUM_BUFFER_COUNT,
> @@ -268,6 +283,7 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue,
> vdec_msg_queue_init_ctx(&msg_queue->lat_ctx, MTK_VDEC_LAT0);
> INIT_WORK(&msg_queue->core_work, vdec_msg_queue_core_work);
>
> + msg_queue->ctx = ctx;

I'd move that at the beginning of this function, even before calling
vdec_msg_queue_init_ctx(), as this assignment is not at all expensive.

In any case,

Reviewed-by: AngeloGioacchino Del Regno <[email protected]>

2022-12-19 07:00:20

by Yunfei Dong (董云飞)

[permalink] [raw]
Subject: Re: [PATCH 1/5] media: mediatek: vcodec: add params to record lat and core lat_buf count

Hi Angelo,

Thanks for your suggestion.
On Tue, 2022-12-13 at 10:09 +0100, AngeloGioacchino Del Regno wrote:
> Il 10/12/22 08:32, Yunfei Dong ha scritto:
> > Using lat_buf to share decoder information between lat and core
> > work
> > queue, adding params to record the buf count.
> >
> > Fixes: 365e4ba01df4 ("media: mtk-vcodec: Add work queue for core
> > hardware decode")
> > Signed-off-by: Yunfei Dong <[email protected]>
> > ---
> > .../platform/mediatek/vcodec/vdec_msg_queue.c | 32
> > ++++++++++++++++++-
> > .../platform/mediatek/vcodec/vdec_msg_queue.h | 9 ++++++
> > 2 files changed, 40 insertions(+), 1 deletion(-)
> >
> > diff --git
> > a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
> > b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
> > index dc2004790a47..af7ddba1923a 100644
> > --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
> > +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
> > @@ -52,6 +52,30 @@ static struct list_head *vdec_get_buf_list(int
> > hardware_index, struct vdec_lat_b
> > }
> > }
> >
> > +static void vdec_msg_queue_inc(struct vdec_msg_queue *msg_queue,
> > int hardware_index)
> > +{
> > + mutex_lock(&msg_queue->list_cnt_mutex);
>
> I doubt that you need to use this mutex, as you're using atomics...
>
Can be removed.
> > +
> > + if (hardware_index == MTK_VDEC_CORE)
> > + atomic_inc(&msg_queue->core_list_cnt);
> > + else
> > + atomic_inc(&msg_queue->lat_list_cnt);
> > +
>
> This branch (with the relevant appropriate changes) can be simplified
> as
>
> atomic_inc(&msg_queue->list_cnt[hardware_index]);
>
> ...where list_cnt is an array, and hardware_index is an enumeration.
>
Only use lat and core, no need to using a array for every hardware.

Best Regards,
Yunfei Dong
> > + mutex_unlock(&msg_queue->list_cnt_mutex);
> > +}
> > +
> > +static void vdec_msg_queue_dec(struct vdec_msg_queue *msg_queue,
> > int hardware_index)
> > +{
> > + mutex_lock(&msg_queue->list_cnt_mutex);
> > +
> > + if (hardware_index == MTK_VDEC_CORE)
> > + atomic_dec(&msg_queue->core_list_cnt);
> > + else
> > + atomic_dec(&msg_queue->lat_list_cnt);
>
> Same here.
>
> > +
> > + mutex_unlock(&msg_queue->list_cnt_mutex);
> > +}
> > +
>
> Regards,
> Angelo
>