Skip to content

Commit

Permalink
media: s5p-mfc: Fix to handle reference queue during finishing
Browse files Browse the repository at this point in the history
[ Upstream commit d8a46bc ]

On receiving last buffer driver puts MFC to MFCINST_FINISHING state which
in turn skips transferring of frame from SRC to REF queue. This causes
driver to stop MFC encoding and last frame is lost.

This patch guarantees safe handling of frames during MFCINST_FINISHING and
correct clearing of workbit to avoid early stopping of encoding.

Fixes: af93574 ("[media] MFC: Add MFC 5.1 V4L2 driver")

Cc: stable@vger.kernel.org
Cc: linux-fsd@tesla.com
Signed-off-by: Smitha T Murthy <smitha.t@samsung.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
smithatmurthy authored and gregkh committed Jan 12, 2023
1 parent 1bd7283 commit 4653ba3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
Expand Up @@ -1218,6 +1218,7 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
unsigned long mb_y_addr, mb_c_addr;
int slice_type;
unsigned int strm_size;
bool src_ready;

slice_type = s5p_mfc_hw_call(dev->mfc_ops, get_enc_slice_type, dev);
strm_size = s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size, dev);
Expand Down Expand Up @@ -1257,7 +1258,8 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
}
}
}
if ((ctx->src_queue_cnt > 0) && (ctx->state == MFCINST_RUNNING)) {
if (ctx->src_queue_cnt > 0 && (ctx->state == MFCINST_RUNNING ||
ctx->state == MFCINST_FINISHING)) {
mb_entry = list_entry(ctx->src_queue.next, struct s5p_mfc_buf,
list);
if (mb_entry->flags & MFC_BUF_FLAG_USED) {
Expand Down Expand Up @@ -1288,7 +1290,13 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
vb2_set_plane_payload(&mb_entry->b->vb2_buf, 0, strm_size);
vb2_buffer_done(&mb_entry->b->vb2_buf, VB2_BUF_STATE_DONE);
}
if ((ctx->src_queue_cnt == 0) || (ctx->dst_queue_cnt == 0))

src_ready = true;
if (ctx->state == MFCINST_RUNNING && ctx->src_queue_cnt == 0)
src_ready = false;
if (ctx->state == MFCINST_FINISHING && ctx->ref_queue_cnt == 0)
src_ready = false;
if (!src_ready || ctx->dst_queue_cnt == 0)
clear_work_bit(ctx);

return 0;
Expand Down

0 comments on commit 4653ba3

Please sign in to comment.