From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8FD34C4452A for ; Mon, 20 Jul 2026 13:35:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=DFS3JEHYMiNPefoSJZe76OBIlWJWMB9X0ah6mtfSEbU=; b=sQLOQqysDJqmp3vTzoPxmWa4Pc ZUTy4Ay9wQTQrFpB4ek0OIiGtjinl2aWUMf/bx6QJQUBCR48NWLoJiA0hJR/s5hTKOg9M5Ef6Kv38 05EMzWZTaHn+1gNFKvAjQohLJ/tKIGU/I+WN2yygakCT6ITqfLrVSrV6DDhqE855DhIvNSEwqcYIL 68OOEZlAKwIdMJXaKWlnr1XR2KWCrjTCUxOg4bkK84uPoEriyTpA3G7po0RtOsp4EvtByXaQNxKtX YLaEogbPwtWA86zQBM17ijjUTG3+e/QpvDDMUS/B/zYgo84kSgQkefITHdb5tQnsi8Vu1fg0V9QhF jIpO+L9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wlo9X-00000006pO7-3Z42; Mon, 20 Jul 2026 13:35:27 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wlo8v-00000006otA-3UmV; Mon, 20 Jul 2026 13:34:51 +0000 X-UUID: c4dc0804843f11f1acbe4559397dec65-20260720 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=DFS3JEHYMiNPefoSJZe76OBIlWJWMB9X0ah6mtfSEbU=; b=HKGW6/4/HnUzGzBw2NcNPNAjd7gZemfBgNNxd12dmK2fy7sEwSaLhi0MIJWpA+0yisOZZo0be6aEmOBnjAR492uxnfOM7OnGe+w2Du5oUAgYCWTqxo4e9WFvbu0oRQNH6N3FZLYYUJANTx9AFy9htLdhSeN+d6xzTBI00bAOpas=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.18,REQID:18c9fd3d-31c7-4b3f-9589-4bfc9dc38a10,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:8a735a6,CLOUDID:b4d47c3f-46cf-453a-bd84-ad9fc7cb0e8c,B ulkID:nil,BulkQuantity:0,SF:81|82|102|136|836|865|888|898,TC:-5,Content:0| 15|50|99|100|102|154|155,EDM:-3|-100,IP:nil,URL:0,File:130,RT:0,Bulk:nil,Q S:nil,BEC:-1,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,A RC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: c4dc0804843f11f1acbe4559397dec65-20260720 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 881262140; Mon, 20 Jul 2026 06:34:44 -0700 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.29; Mon, 20 Jul 2026 21:34:42 +0800 Received: from gcnsap21.gcn.mediatek.inc (10.17.81.22) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.2562.29 via Frontend Transport; Mon, 20 Jul 2026 21:34:41 +0800 From: Kyrie Wu To: Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Bin Liu , kyrie wu , Hans Verkuil , irui wang , Nicolas Dufresne , , , , , CC: Kyrie Wu Subject: [PATCH v16 06/12] media: mediatek: jpeg: fix buffer state update timing Date: Mon, 20 Jul 2026 21:34:26 +0800 Message-ID: <20260720133432.1042046-7-kyrie.wu@mediatek.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260720133432.1042046-1-kyrie.wu@mediatek.com> References: <20260720133432.1042046-1-kyrie.wu@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260720_063449_876164_89CBA535 X-CRM114-Status: GOOD ( 13.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Update the destination buffer state only after the decoder has selected a hardware core and resumed its runtime PM state successfully. This avoids assigning frame tracking data to buffers that will be returned early, such as when a source resolution change is detected. Protect the destination buffer state update with the hardware spinlock so the completion path observes a consistent context and frame number. Stop walking the done queue after completing the next expected frame, since the remaining buffers still need to wait for their own frame order. Fixes: dedc21500334 ("media: mtk-jpegdec: add jpeg decode worker interface") Signed-off-by: Kyrie Wu Reviewed-by: Nicolas Dufresne --- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 9 +++------ drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 1 + drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 1 + 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c index a5a1f6126..e152ebae0 100644 --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c @@ -1735,7 +1735,6 @@ static void mtk_jpegdec_worker(struct work_struct *work) v4l2_m2m_buf_copy_metadata(src_buf, dst_buf); jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(&src_buf->vb2_buf); - jpeg_dst_buf = mtk_jpeg_vb2_to_srcbuf(&dst_buf->vb2_buf); if (mtk_jpeg_check_resolution_change(ctx, &jpeg_src_buf->dec_param)) { @@ -1744,11 +1743,6 @@ static void mtk_jpegdec_worker(struct work_struct *work) goto getbuf_fail; } - jpeg_src_buf->curr_ctx = ctx; - jpeg_src_buf->frame_num = ctx->total_frame_num; - jpeg_dst_buf->curr_ctx = ctx; - jpeg_dst_buf->frame_num = ctx->total_frame_num; - mtk_jpegdec_set_hw_param(ctx, hw_id, src_buf, dst_buf); ret = pm_runtime_resume_and_get(comp_jpeg[hw_id]->dev); if (ret < 0) { @@ -1773,6 +1767,9 @@ static void mtk_jpegdec_worker(struct work_struct *work) msecs_to_jiffies(MTK_JPEG_HW_TIMEOUT_MSEC)); spin_lock_irqsave(&comp_jpeg[hw_id]->hw_lock, flags); + jpeg_dst_buf = mtk_jpeg_vb2_to_srcbuf(&dst_buf->vb2_buf); + jpeg_dst_buf->curr_ctx = ctx; + jpeg_dst_buf->frame_num = ctx->total_frame_num; ctx->total_frame_num++; mtk_jpeg_dec_reset(comp_jpeg[hw_id]->reg_base); mtk_jpeg_dec_set_config(comp_jpeg[hw_id]->reg_base, diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c index 970c0a30e..426150bff 100644 --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c @@ -513,6 +513,7 @@ static void mtk_jpegdec_put_buf(struct mtk_jpegdec_comp_dev *jpeg) v4l2_m2m_buf_done(&tmp_dst_done_buf->b, VB2_BUF_STATE_DONE); ctx->last_done_frame_num++; + break; } } } diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c index 5f5f071d8..eb34698d2 100644 --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c @@ -242,6 +242,7 @@ static void mtk_jpegenc_put_buf(struct mtk_jpegenc_comp_dev *jpeg) v4l2_m2m_buf_done(&tmp_dst_done_buf->b, VB2_BUF_STATE_DONE); ctx->last_done_frame_num++; + break; } } } -- 2.51.0.windows.2