From nobody Sun Sep 22 13:12:16 2024 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37EB1C433FE for ; Wed, 17 Nov 2021 13:06:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 163E261BD3 for ; Wed, 17 Nov 2021 13:06:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237385AbhKQNJu (ORCPT ); Wed, 17 Nov 2021 08:09:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232830AbhKQNJt (ORCPT ); Wed, 17 Nov 2021 08:09:49 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0AA3C061570; Wed, 17 Nov 2021 05:06:50 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id 213261F45CAA DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=collabora.com; s=mail; t=1637154409; bh=fkjDwUt5aIF7ZYKWMjK2FWkQxgVnsFK/2/jn4p1kTCk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LBNxrvJdnwH4QXxfJdLoxQ/IcqSV42d7mSOuNYJKvbj0Tc/Q5YMiW2KHRED3o6+p1 eMf/S38jHUfZnOj8NTpujOd+X2q81+HVjQpelIl3SBHaxNS8ypsSTJY+77zL/0AKOj G3ptQarhF+gCfxpBwPOb49PnW6tkqM8FEmcVNA+vcFQyc5Z661dwoC1X7DqjGaCVvo EAlPKke3eS1DGoOQXEImHwue8pmP0qr7NBaOiQCveeEridyEDrmorEGeteLKFE6jCT njjGfmS7tJ+Bg+wVU9jYBDghatyV7D+NOi1k4yzgZif2/qOCTcF1lulSnoRzt2DmLg +i3BoHwF93Isw== From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: Dafna Hirschfeld , kernel@collabora.com, acourbot@chromium.org, andrew-ct.chen@mediatek.com, courbot@chromium.org, dafna3@gmail.com, eizan@chromium.org, houlong.wei@mediatek.com, hsinyi@chromium.org, hverkuil@xs4all.nl, irui.wang@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, maoguang.meng@mediatek.com, matthias.bgg@gmail.com, mchehab@kernel.org, minghsiu.tsai@mediatek.com, tfiga@chromium.org, tiffany.lin@mediatek.com Subject: [PATCH v2 1/7] media: mtk-vcodec: enc: add vp8 profile ctrl Date: Wed, 17 Nov 2021 15:06:29 +0200 Message-Id: <20211117130635.11633-2-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211117130635.11633-1-dafna.hirschfeld@collabora.com> References: <20211117130635.11633-1-dafna.hirschfeld@collabora.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In order for the encoder to work with gstreamer it needs to have the V4L2_CID_MPEG_VIDEO_VP8_PROFILE ctrl. This patch adds that ctrl with only profile 0 supported. Signed-off-by: Dafna Hirschfeld --- drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_enc.c index 8998244ea671..87a5114bf680 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c @@ -103,6 +103,13 @@ static int vidioc_venc_s_ctrl(struct v4l2_ctrl *ctrl) p->gop_size =3D ctrl->val; ctx->param_change |=3D MTK_ENCODE_PARAM_GOP_SIZE; break; + case V4L2_CID_MPEG_VIDEO_VP8_PROFILE: + /* + * FIXME - what vp8 profiles are actually supported? + * The ctrl is added (with only profile 0 supported) for now. + */ + mtk_v4l2_debug(2, "V4L2_CID_MPEG_VIDEO_VP8_PROFILE val =3D %d", ctrl->va= l); + break; case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: mtk_v4l2_debug(2, "V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME"); p->force_intra =3D 1; @@ -1394,6 +1401,9 @@ int mtk_vcodec_enc_ctrls_setup(struct mtk_vcodec_ctx = *ctx) v4l2_ctrl_new_std_menu(handler, ops, V4L2_CID_MPEG_VIDEO_H264_LEVEL, h264_max_level, 0, V4L2_MPEG_VIDEO_H264_LEVEL_4_0); + v4l2_ctrl_new_std_menu(handler, ops, V4L2_CID_MPEG_VIDEO_VP8_PROFILE, + V4L2_MPEG_VIDEO_VP8_PROFILE_0, 0, V4L2_MPEG_VIDEO_VP8_PROFILE_0); + =20 if (handler->error) { mtk_v4l2_err("Init control handler fail %d", --=20 2.17.1 From nobody Sun Sep 22 13:12:16 2024 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82CC6C433F5 for ; Wed, 17 Nov 2021 13:06:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 664EE61B7D for ; Wed, 17 Nov 2021 13:06:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237403AbhKQNJw (ORCPT ); Wed, 17 Nov 2021 08:09:52 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:49498 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237384AbhKQNJu (ORCPT ); Wed, 17 Nov 2021 08:09:50 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id 8DFAD1F45D02 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=collabora.com; s=mail; t=1637154411; bh=wZ+ibyByRP8u5Nw9zLsABoLUSn6ypgyqQXE3oYQlGbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AK3GvCft6MfgelkZPcKOyO8dqcA+EyLc8C9eVChsGlAJHIiwtdfhj96cRRHukFfpP 0syn5EJqfwK6OK7e4//ZIcGSpjtO5u/ruV1mOCHPGh3g3b0MTD2XbcK35sVYCqxaut wdbjW55YKbBewS5ZpHFAKtbpvcNiuDvC2Opzmc95jyHvUVrzHpDy8HGHzRch+X3LuL 8tJC2WMFZaU8C76vJb0OTsHO5vNtQaUgWv+MId2bahJnK0q7NxMyBZwaMJe3Y2KMMH XhBhVL+SORnCkqTtkYMw1lG2kyEh3XvXhpEXqYogfOTTen2weSYBNj2ZJvs+JGgl1/ L0H0jKHEvs91g== From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: Dafna Hirschfeld , kernel@collabora.com, acourbot@chromium.org, andrew-ct.chen@mediatek.com, courbot@chromium.org, dafna3@gmail.com, eizan@chromium.org, houlong.wei@mediatek.com, hsinyi@chromium.org, hverkuil@xs4all.nl, irui.wang@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, maoguang.meng@mediatek.com, matthias.bgg@gmail.com, mchehab@kernel.org, minghsiu.tsai@mediatek.com, tfiga@chromium.org, tiffany.lin@mediatek.com Subject: [PATCH v2 2/7] media: mtk-vcodec: call v4l2_m2m_ctx_release first when file is released Date: Wed, 17 Nov 2021 15:06:30 +0200 Message-Id: <20211117130635.11633-3-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211117130635.11633-1-dafna.hirschfeld@collabora.com> References: <20211117130635.11633-1-dafna.hirschfeld@collabora.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The func v4l2_m2m_ctx_release waits for currently running jobs to finish and then stop streaming both queues and frees the buffers. All this should be done before the call to mtk_vcodec_enc_release which frees the encoder handler. This fixes null-pointer dereference bug: [gst-master] root@debian:~/gst-build# [ 638.019193] Unable to handle kerne= l NULL pointer dereference at virtual address 00000000000001a0 [ 638.028076] Mem abort info: [ 638.030932] ESR =3D 0x96000004 [ 638.033978] EC =3D 0x25: DABT (current EL), IL =3D 32 bits [ 638.039293] SET =3D 0, FnV =3D 0 [ 638.042338] EA =3D 0, S1PTW =3D 0 [ 638.045474] FSC =3D 0x04: level 0 translation fault [ 638.050349] Data abort info: [ 638.053224] ISV =3D 0, ISS =3D 0x00000004 [ 638.057055] CM =3D 0, WnR =3D 0 [ 638.060018] user pgtable: 4k pages, 48-bit VAs, pgdp=3D000000012b6db000 [ 638.066485] [00000000000001a0] pgd=3D0000000000000000, p4d=3D00000000000= 00000 [ 638.073277] Internal error: Oops: 96000004 [#1] SMP [ 638.078145] Modules linked in: rfkill mtk_vcodec_dec mtk_vcodec_enc uvcv= ideo mtk_mdp mtk_vcodec_common videobuf2_dma_contig v4l2_h264 cdc_ether v4l= 2_mem2mem videobuf2_vmalloc usbnet videobuf2_memops videobuf2_v4l2 r8152 vi= deobuf2_common videodev cros_ec_sensors cros_ec_sensors_core industrialio_t= riggered_buffer kfifo_buf elan_i2c elants_i2c sbs_battery mc cros_usbpd_cha= rger cros_ec_chardev cros_usbpd_logger crct10dif_ce mtk_vpu fuse ip_tables = x_tables ipv6 [ 638.118583] CPU: 0 PID: 212 Comm: kworker/u8:5 Not tainted 5.15.0-06427-= g58a1d4dcfc74-dirty #109 [ 638.127357] Hardware name: Google Elm (DT) [ 638.131444] Workqueue: mtk-vcodec-enc mtk_venc_worker [mtk_vcodec_enc] [ 638.137974] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE= =3D--) [ 638.144925] pc : vp8_enc_encode+0x34/0x2b0 [mtk_vcodec_enc] [ 638.150493] lr : venc_if_encode+0xac/0x1b0 [mtk_vcodec_enc] [ 638.156060] sp : ffff8000124d3c40 [ 638.159364] x29: ffff8000124d3c40 x28: 0000000000000000 x27: 00000000000= 00000 [ 638.166493] x26: 0000000000000000 x25: ffff0000e7f252d0 x24: ffff8000124= d3d58 [ 638.173621] x23: ffff8000124d3d58 x22: ffff8000124d3d60 x21: 00000000000= 00001 [ 638.180750] x20: ffff80001137e000 x19: 0000000000000000 x18: 00000000000= 00001 [ 638.187878] x17: 000000040044ffff x16: 00400032b5503510 x15: 00000000000= 00000 [ 638.195006] x14: ffff8000118536c0 x13: ffff8000ee1da000 x12: 0000000030d= 4d91d [ 638.202134] x11: 0000000000000000 x10: 0000000000000980 x9 : ffff8000124= d3b20 [ 638.209262] x8 : ffff0000c18d4ea0 x7 : ffff0000c18d44c0 x6 : ffff0000c18= d44c0 [ 638.216391] x5 : ffff80000904a3b0 x4 : ffff8000124d3d58 x3 : ffff8000124= d3d60 [ 638.223519] x2 : ffff8000124d3d78 x1 : 0000000000000001 x0 : ffff8000113= 7efb8 [ 638.230648] Call trace: [ 638.233084] vp8_enc_encode+0x34/0x2b0 [mtk_vcodec_enc] [ 638.238304] venc_if_encode+0xac/0x1b0 [mtk_vcodec_enc] [ 638.243525] mtk_venc_worker+0x110/0x250 [mtk_vcodec_enc] [ 638.248918] process_one_work+0x1f8/0x498 [ 638.252923] worker_thread+0x140/0x538 [ 638.256664] kthread+0x148/0x158 [ 638.259884] ret_from_fork+0x10/0x20 [ 638.263455] Code: f90023f9 2a0103f5 aa0303f6 aa0403f8 (f940d277) [ 638.269538] ---[ end trace e374fc10f8e181f5 ]--- Fixes: 4e855a6efa547 ("[media] vcodec: mediatek: Add Mediatek V4L2 Video En= coder Driver") Signed-off-by: Dafna Hirschfeld Reviewed-by: Alexandre Courbot --- drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drive= rs/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c index eed67394cf46..f898226fc53e 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c @@ -214,11 +214,11 @@ static int fops_vcodec_release(struct file *file) mtk_v4l2_debug(1, "[%d] encoder", ctx->id); mutex_lock(&dev->dev_mutex); =20 + v4l2_m2m_ctx_release(ctx->m2m_ctx); mtk_vcodec_enc_release(ctx); v4l2_fh_del(&ctx->fh); v4l2_fh_exit(&ctx->fh); v4l2_ctrl_handler_free(&ctx->ctrl_hdl); - v4l2_m2m_ctx_release(ctx->m2m_ctx); =20 list_del_init(&ctx->list); kfree(ctx); --=20 2.17.1 From nobody Sun Sep 22 13:12:16 2024 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96C94C433EF for ; Wed, 17 Nov 2021 13:06:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 73FA961BFE for ; Wed, 17 Nov 2021 13:06:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237417AbhKQNJz (ORCPT ); Wed, 17 Nov 2021 08:09:55 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:49512 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237398AbhKQNJx (ORCPT ); Wed, 17 Nov 2021 08:09:53 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id BE34E1F45CE5 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=collabora.com; s=mail; t=1637154413; bh=eK5TQh9dYAJXudfnkfcZE75BZ5m9URbPB735KQHfCTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dOWE0rBZfXfQUp8NsYuRmpfE+I8lBgTY5lNHMikZQ6KN7RdCGSAkjDYwGdu6VIOCo 7T8tKpluWd/pDhHIVxGDMB7SdUYzTdOWv8xWFG99y4timvsB6pyIMI1nRwsXD5yslZ HSZFujJJ/Rni/Bk0kM0Edc2prOpXU90AlXGxN68lVngygt1zUYUsqI0eSMfhz88eRO Z3LeEekkAa3H3Uqg1RBk78k8pP2f1qaLdSaqvYvHmQ9MXQCGl7I8KB2Y4mdB075MPw GWa69wjSnvUjdoZr4Hbg0TSUAiZb7jVxL1W2TmleI/eMJvG1oftUe3SsX0BfsZ8V11 iS3aYabFR+fKw== From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: Dafna Hirschfeld , kernel@collabora.com, acourbot@chromium.org, andrew-ct.chen@mediatek.com, courbot@chromium.org, dafna3@gmail.com, eizan@chromium.org, houlong.wei@mediatek.com, hsinyi@chromium.org, hverkuil@xs4all.nl, irui.wang@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, maoguang.meng@mediatek.com, matthias.bgg@gmail.com, mchehab@kernel.org, minghsiu.tsai@mediatek.com, tfiga@chromium.org, tiffany.lin@mediatek.com Subject: [PATCH v2 3/7] media: mtk-vcodec: enc: use "stream_started" flag for "stop/start_streaming" Date: Wed, 17 Nov 2021 15:06:31 +0200 Message-Id: <20211117130635.11633-4-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211117130635.11633-1-dafna.hirschfeld@collabora.com> References: <20211117130635.11633-1-dafna.hirschfeld@collabora.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently the mtk-vcodec encoder does runtime pm resume in "start_streaming" cb if both queues are streaming and does runtime pm 'put' in "stop_streaming" if both queues are not streaming. This is wrong since the same queue might be started and then stopped causing the driver to turn off the hardware without turning it on. This cause for example unbalanced calls to pm_runtime_* Fixes: 4e855a6efa547 ("[media] vcodec: mediatek: Add Mediatek V4L2 Video En= coder Driver") Signed-off-by: Dafna Hirschfeld --- to reproduce the issue: patch v4l-utils as follow: static void stateful_m2m(cv4l_fd &fd, cv4l_queue &in, cv4l_queue &out, if (fd.streamon(out.g_type())) return; + if (fd.streamoff(out.g_type())) + return; + + exit(1); fd.s_trace(0); if (exp_fd_p) and call: v4l2-ctl -x width=3D160,height=3D128,pixelformat=3DNM12 -v pixelformat=3DVP= 80 --stream-mmap --stream-out-mmap -d5 then the file /sys/devices/platform/soc/19002000.vcodec/power/runtime_usage will show a negative number and further streaming (with e.g, gstreamer) is = not possible. drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 4 ++++ drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_drv.h index 9d36e3d27369..84c5289f872b 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h @@ -259,6 +259,9 @@ struct vdec_pic_info { * @decoded_frame_cnt: number of decoded frames * @lock: protect variables accessed by V4L2 threads and worker thread suc= h as * mtk_video_dec_buf. + * @stream_started: this flag is turned on when both queues (cap and out) = starts streaming + * and it is turned off once both queues stop streaming. It is used for = a correct + * setup and set-down of the hardware when starting and stopping streami= ng. */ struct mtk_vcodec_ctx { enum mtk_instance_type type; @@ -301,6 +304,7 @@ struct mtk_vcodec_ctx { =20 int decoded_frame_cnt; struct mutex lock; + bool stream_started; =20 }; =20 diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_enc.c index 87a5114bf680..fb3cf804c96a 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c @@ -890,6 +890,9 @@ static int vb2ops_venc_start_streaming(struct vb2_queue= *q, unsigned int count) goto err_start_stream; } =20 + if (ctx->stream_started) + return 0; + /* Do the initialization when both start_streaming have been called */ if (V4L2_TYPE_IS_OUTPUT(q->type)) { if (!vb2_start_streaming_called(&ctx->m2m_ctx->cap_q_ctx.q)) @@ -928,6 +931,7 @@ static int vb2ops_venc_start_streaming(struct vb2_queue= *q, unsigned int count) ctx->state =3D MTK_STATE_HEADER; } =20 + ctx->stream_started =3D true; return 0; =20 err_set_param: @@ -1002,6 +1006,9 @@ static void vb2ops_venc_stop_streaming(struct vb2_que= ue *q) } } =20 + if (!ctx->stream_started) + return; + if ((q->type =3D=3D V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && vb2_is_streaming(&ctx->m2m_ctx->out_q_ctx.q)) || (q->type =3D=3D V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && @@ -1023,6 +1030,7 @@ static void vb2ops_venc_stop_streaming(struct vb2_que= ue *q) mtk_v4l2_err("pm_runtime_put fail %d", ret); =20 ctx->state =3D MTK_STATE_FREE; + ctx->stream_started =3D false; } =20 static int vb2ops_venc_buf_out_validate(struct vb2_buffer *vb) --=20 2.17.1 From nobody Sun Sep 22 13:12:16 2024 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57572C4332F for ; Wed, 17 Nov 2021 13:07:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3955F61C32 for ; Wed, 17 Nov 2021 13:07:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237421AbhKQNKA (ORCPT ); Wed, 17 Nov 2021 08:10:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237419AbhKQNJz (ORCPT ); Wed, 17 Nov 2021 08:09:55 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F1B3C061764; Wed, 17 Nov 2021 05:06:57 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id F11221F45D0A DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=collabora.com; s=mail; t=1637154416; bh=WrZFRJgosj8fXeCgZOypKOsxmSubLEsYuflu3+uxlJs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=elNBWQorW3hIx6mwp2URppQhCyKR2rVRynaFhMibqCmp4aQKnybKhXdeJv5kZhxgv AGAroByy0hDkGvTu+X6BGWdXLhGx7EA/skNIeaiJ42f4/CvbEUtEOXKoKn5aw0bBEx LnGPhAl8UAkOzpwrLJO3v4sD4xEU8oCE/MQWJiJLyAZH5tNVQASq9twg8IugUENzNq HEDw4GPOWEA4FwulhQudr9AV1uXwgZ3DpE2hwTIg7iIx5ERlEZUZUs1oaHVfWThtDZ /D+PQN+4mkcUypPN79eWWcqpADfIScgIjEhGBjrrECtRlOqxuKDMOSkcK8x95AB054 qWTEjT/u1Y10g== From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: Dafna Hirschfeld , kernel@collabora.com, acourbot@chromium.org, andrew-ct.chen@mediatek.com, courbot@chromium.org, dafna3@gmail.com, eizan@chromium.org, houlong.wei@mediatek.com, hsinyi@chromium.org, hverkuil@xs4all.nl, irui.wang@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, maoguang.meng@mediatek.com, matthias.bgg@gmail.com, mchehab@kernel.org, minghsiu.tsai@mediatek.com, tfiga@chromium.org, tiffany.lin@mediatek.com Subject: [PATCH v2 4/7] media: mtk-vcodec: fix debugging defines Date: Wed, 17 Nov 2021 15:06:32 +0200 Message-Id: <20211117130635.11633-5-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211117130635.11633-1-dafna.hirschfeld@collabora.com> References: <20211117130635.11633-1-dafna.hirschfeld@collabora.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The mtk-vcodec uses some internal defined debug formats for printing. This patch fixes some things in those defines: 1. use the 'pr_fmt' define to print function name and line. 2. remove 'if(DEBUG)' condition for the defines. This condition prevents the debugs from being shown in case of dynamic debugs. Instead replace 'pr_info' with 'pr_debug' 3. remove module parameters that enable/disable debug. There is no reason for the driver to have those params. Having those params require the user to explicitly set them when user wants to see debug prints instead of using the global debugs setting as expected by drivers to conform. In addition to that, fix some warnings about debug formatting Signed-off-by: Dafna Hirschfeld --- .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 3 -- .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 3 -- .../platform/mtk-vcodec/mtk_vcodec_util.c | 10 ----- .../platform/mtk-vcodec/mtk_vcodec_util.h | 45 +++++-------------- .../mtk-vcodec/vdec/vdec_h264_req_if.c | 4 +- 5 files changed, 12 insertions(+), 53 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c b/drive= rs/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c index e6e6a8203eeb..f3610a338a01 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c @@ -28,9 +28,6 @@ #define VDEC_IRQ_CLR 0x10 #define VDEC_IRQ_CFG_REG 0xa4 =20 -module_param(mtk_v4l2_dbg_level, int, 0644); -module_param(mtk_vcodec_dbg, bool, 0644); - /* Wake up context wait_queue */ static void wake_up_ctx(struct mtk_vcodec_ctx *ctx) { diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drive= rs/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c index f898226fc53e..ec5ee337c1fd 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c @@ -23,9 +23,6 @@ #include "mtk_vcodec_util.h" #include "mtk_vcodec_fw.h" =20 -module_param(mtk_v4l2_dbg_level, int, S_IRUGO | S_IWUSR); -module_param(mtk_vcodec_dbg, bool, S_IRUGO | S_IWUSR); - static const struct mtk_video_fmt mtk_video_formats_output[] =3D { { .fourcc =3D V4L2_PIX_FMT_NV12M, diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c b/drivers/= media/platform/mtk-vcodec/mtk_vcodec_util.c index ac5973b6735f..5bac820a47fc 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c @@ -10,16 +10,6 @@ #include "mtk_vcodec_drv.h" #include "mtk_vcodec_util.h" =20 -/* For encoder, this will enable logs in venc/*/ -bool mtk_vcodec_dbg; -EXPORT_SYMBOL(mtk_vcodec_dbg); - -/* The log level of v4l2 encoder or decoder driver. - * That is, files under mtk-vcodec/. - */ -int mtk_v4l2_dbg_level; -EXPORT_SYMBOL(mtk_v4l2_dbg_level); - void __iomem *mtk_vcodec_get_reg_addr(struct mtk_vcodec_ctx *data, unsigned int reg_idx) { diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h b/drivers/= media/platform/mtk-vcodec/mtk_vcodec_util.h index b999d7b84ed1..87c3d6d4bfa7 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h @@ -25,54 +25,29 @@ struct mtk_vcodec_fb { struct mtk_vcodec_ctx; struct mtk_vcodec_dev; =20 -extern int mtk_v4l2_dbg_level; -extern bool mtk_vcodec_dbg; - +#undef pr_fmt +#define pr_fmt(fmt) "%s(),%d: " fmt, __func__, __LINE__ =20 #define mtk_v4l2_err(fmt, args...) \ - pr_err("[MTK_V4L2][ERROR] %s:%d: " fmt "\n", __func__, __LINE__, \ - ##args) - -#define mtk_vcodec_err(h, fmt, args...) \ - pr_err("[MTK_VCODEC][ERROR][%d]: %s() " fmt "\n", \ - ((struct mtk_vcodec_ctx *)h->ctx)->id, __func__, ##args) + pr_err("[MTK_V4L2][ERROR] " fmt "\n", ##args) =20 +#define mtk_vcodec_err(h, fmt, args...) \ + pr_err("[MTK_VCODEC][ERROR][%d]: " fmt "\n", \ + ((struct mtk_vcodec_ctx *)(h)->ctx)->id, ##args) =20 -#if defined(DEBUG) =20 -#define mtk_v4l2_debug(level, fmt, args...) \ - do { \ - if (mtk_v4l2_dbg_level >=3D level) \ - pr_info("[MTK_V4L2] level=3D%d %s(),%d: " fmt "\n",\ - level, __func__, __LINE__, ##args); \ - } while (0) +#define mtk_v4l2_debug(level, fmt, args...) pr_debug(fmt, ##args) =20 #define mtk_v4l2_debug_enter() mtk_v4l2_debug(3, "+") #define mtk_v4l2_debug_leave() mtk_v4l2_debug(3, "-") =20 -#define mtk_vcodec_debug(h, fmt, args...) \ - do { \ - if (mtk_vcodec_dbg) \ - pr_info("[MTK_VCODEC][%d]: %s() " fmt "\n", \ - ((struct mtk_vcodec_ctx *)h->ctx)->id, \ - __func__, ##args); \ - } while (0) +#define mtk_vcodec_debug(h, fmt, args...) \ + pr_debug("[MTK_VCODEC][%d]: " fmt "\n", \ + ((struct mtk_vcodec_ctx *)(h)->ctx)->id, ##args) =20 #define mtk_vcodec_debug_enter(h) mtk_vcodec_debug(h, "+") #define mtk_vcodec_debug_leave(h) mtk_vcodec_debug(h, "-") =20 -#else - -#define mtk_v4l2_debug(level, fmt, args...) {} -#define mtk_v4l2_debug_enter() {} -#define mtk_v4l2_debug_leave() {} - -#define mtk_vcodec_debug(h, fmt, args...) {} -#define mtk_vcodec_debug_enter(h) {} -#define mtk_vcodec_debug_leave(h) {} - -#endif - void __iomem *mtk_vcodec_get_reg_addr(struct mtk_vcodec_ctx *data, unsigned int reg_idx); int mtk_vcodec_mem_alloc(struct mtk_vcodec_ctx *data, diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_req_if.c b/dr= ivers/media/platform/mtk-vcodec/vdec/vdec_h264_req_if.c index 946c23088308..88f2e8f9bfe1 100644 --- a/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_req_if.c +++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_req_if.c @@ -527,7 +527,7 @@ static int alloc_mv_buf(struct vdec_h264_slice_inst *in= st, struct mtk_vcodec_mem *mem =3D NULL; unsigned int buf_sz =3D get_mv_buf_size(pic->buf_w, pic->buf_h); =20 - mtk_v4l2_debug(3, "size =3D 0x%lx", buf_sz); + mtk_v4l2_debug(3, "size =3D 0x%x", buf_sz); for (i =3D 0; i < H264_MAX_MV_NUM; i++) { mem =3D &inst->mv_buf[i]; if (mem->va) @@ -637,7 +637,7 @@ static int vdec_h264_slice_init(struct mtk_vcodec_ctx *= ctx) if (err) goto error_deinit; =20 - mtk_vcodec_debug(inst, "struct size =3D %d,%d,%d,%d\n", + mtk_vcodec_debug(inst, "struct size =3D %lu,%lu,%lu,%lu\n", sizeof(struct mtk_h264_sps_param), sizeof(struct mtk_h264_pps_param), sizeof(struct mtk_h264_dec_slice_param), --=20 2.17.1 From nobody Sun Sep 22 13:12:16 2024 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A76ACC433F5 for ; Wed, 17 Nov 2021 13:07:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8EF0461BFE for ; Wed, 17 Nov 2021 13:07:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237442AbhKQNKH (ORCPT ); Wed, 17 Nov 2021 08:10:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237384AbhKQNJ6 (ORCPT ); Wed, 17 Nov 2021 08:09:58 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65C60C061570; Wed, 17 Nov 2021 05:06:59 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id 622681F45D07 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=collabora.com; s=mail; t=1637154418; bh=u270ohJ7t6uCbX7fIMH88BVsQ8r478APACiXzxz20dw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WB3t/tzldWxoDzT1GV4ai4x6hhHSiXabCwqXUw+4ipXx3j92nhqTZpelnJhRkIkfB fCF1QvukWmFQoC4SUew/TFjhECccg6kHdOfvBhJwuLugztw5ReqKzK/oxsiT3izIjT 9JPPxddCLMEIT2pBsn1tTpidWIYLWksP24dFpQBb3X/DUg3P81qHbnD9lt33lpWrQQ dyA9IB98BsDJeMHzDv1fVRhVjCgcONPoyqR6bOkA6VlygMf+BEoM0YavY0CnGXlA32 qkxpcOMx6nE4W7wZ9W5Z2r6nrLn1KYvAlPZvrPuv33GoNK/kgXowAt+GUdMMbETTYe qJKFPUikMo2ag== From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: Dafna Hirschfeld , kernel@collabora.com, acourbot@chromium.org, andrew-ct.chen@mediatek.com, courbot@chromium.org, dafna3@gmail.com, eizan@chromium.org, houlong.wei@mediatek.com, hsinyi@chromium.org, hverkuil@xs4all.nl, irui.wang@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, maoguang.meng@mediatek.com, matthias.bgg@gmail.com, mchehab@kernel.org, minghsiu.tsai@mediatek.com, tfiga@chromium.org, tiffany.lin@mediatek.com Subject: [PATCH v2 5/7] media: mtk-vcodec: replace func vidioc_try_fmt with two funcs for out/cap Date: Wed, 17 Nov 2021 15:06:33 +0200 Message-Id: <20211117130635.11633-6-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211117130635.11633-1-dafna.hirschfeld@collabora.com> References: <20211117130635.11633-1-dafna.hirschfeld@collabora.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The function vidioc_try_fmt has a big 'if-else' for the capture and output cases. There is hardly any code outside of that condition. It is therefore better to split that functions into two different functions, one for each case. Signed-off-by: Dafna Hirschfeld --- .../platform/mtk-vcodec/mtk_vcodec_enc.c | 149 +++++++++--------- 1 file changed, 72 insertions(+), 77 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_enc.c index fb3cf804c96a..be28f2401839 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c @@ -263,87 +263,82 @@ static struct mtk_q_data *mtk_venc_get_q_data(struct = mtk_vcodec_ctx *ctx, return &ctx->q_data[MTK_Q_DATA_DST]; } =20 +static void vidioc_try_fmt_cap(struct v4l2_format *f) +{ + f->fmt.pix_mp.field =3D V4L2_FIELD_NONE; + f->fmt.pix_mp.num_planes =3D 1; + f->fmt.pix_mp.plane_fmt[0].bytesperline =3D 0; + f->fmt.pix_mp.flags =3D 0; +} + /* V4L2 specification suggests the driver corrects the format struct if an= y of * the dimensions is unsupported */ -static int vidioc_try_fmt(struct mtk_vcodec_ctx *ctx, struct v4l2_format *= f, - const struct mtk_video_fmt *fmt) +static int vidioc_try_fmt_out(struct mtk_vcodec_ctx *ctx, struct v4l2_form= at *f, + const struct mtk_video_fmt *fmt) { struct v4l2_pix_format_mplane *pix_fmt_mp =3D &f->fmt.pix_mp; + int tmp_w, tmp_h; + unsigned int max_width, max_height; =20 pix_fmt_mp->field =3D V4L2_FIELD_NONE; =20 - if (f->type =3D=3D V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { - pix_fmt_mp->num_planes =3D 1; - pix_fmt_mp->plane_fmt[0].bytesperline =3D 0; - } else if (f->type =3D=3D V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { - int tmp_w, tmp_h; - unsigned int max_width, max_height; - - if (ctx->dev->enc_capability & MTK_VENC_4K_CAPABILITY_ENABLE) { - max_width =3D MTK_VENC_4K_MAX_W; - max_height =3D MTK_VENC_4K_MAX_H; - } else { - max_width =3D MTK_VENC_HD_MAX_W; - max_height =3D MTK_VENC_HD_MAX_H; - } + if (ctx->dev->enc_capability & MTK_VENC_4K_CAPABILITY_ENABLE) { + max_width =3D MTK_VENC_4K_MAX_W; + max_height =3D MTK_VENC_4K_MAX_H; + } else { + max_width =3D MTK_VENC_HD_MAX_W; + max_height =3D MTK_VENC_HD_MAX_H; + } =20 - pix_fmt_mp->height =3D clamp(pix_fmt_mp->height, - MTK_VENC_MIN_H, - max_height); - pix_fmt_mp->width =3D clamp(pix_fmt_mp->width, - MTK_VENC_MIN_W, - max_width); + pix_fmt_mp->height =3D clamp(pix_fmt_mp->height, MTK_VENC_MIN_H, max_heig= ht); + pix_fmt_mp->width =3D clamp(pix_fmt_mp->width, MTK_VENC_MIN_W, max_width); =20 - /* find next closer width align 16, heign align 32, size align - * 64 rectangle - */ - tmp_w =3D pix_fmt_mp->width; - tmp_h =3D pix_fmt_mp->height; - v4l_bound_align_image(&pix_fmt_mp->width, - MTK_VENC_MIN_W, - max_width, 4, - &pix_fmt_mp->height, - MTK_VENC_MIN_H, - max_height, 5, 6); - - if (pix_fmt_mp->width < tmp_w && - (pix_fmt_mp->width + 16) <=3D max_width) - pix_fmt_mp->width +=3D 16; - if (pix_fmt_mp->height < tmp_h && - (pix_fmt_mp->height + 32) <=3D max_height) - pix_fmt_mp->height +=3D 32; - - mtk_v4l2_debug(0, - "before resize width=3D%d, height=3D%d, after resize width=3D%d, height= =3D%d, sizeimage=3D%d %d", - tmp_w, tmp_h, pix_fmt_mp->width, - pix_fmt_mp->height, - pix_fmt_mp->plane_fmt[0].sizeimage, - pix_fmt_mp->plane_fmt[1].sizeimage); - - pix_fmt_mp->num_planes =3D fmt->num_planes; - pix_fmt_mp->plane_fmt[0].sizeimage =3D - pix_fmt_mp->width * pix_fmt_mp->height + - ((ALIGN(pix_fmt_mp->width, 16) * 2) * 16); - pix_fmt_mp->plane_fmt[0].bytesperline =3D pix_fmt_mp->width; - - if (pix_fmt_mp->num_planes =3D=3D 2) { - pix_fmt_mp->plane_fmt[1].sizeimage =3D - (pix_fmt_mp->width * pix_fmt_mp->height) / 2 + - (ALIGN(pix_fmt_mp->width, 16) * 16); - pix_fmt_mp->plane_fmt[2].sizeimage =3D 0; - pix_fmt_mp->plane_fmt[1].bytesperline =3D - pix_fmt_mp->width; - pix_fmt_mp->plane_fmt[2].bytesperline =3D 0; - } else if (pix_fmt_mp->num_planes =3D=3D 3) { - pix_fmt_mp->plane_fmt[1].sizeimage =3D - pix_fmt_mp->plane_fmt[2].sizeimage =3D - (pix_fmt_mp->width * pix_fmt_mp->height) / 4 + - ((ALIGN(pix_fmt_mp->width, 16) / 2) * 16); - pix_fmt_mp->plane_fmt[1].bytesperline =3D - pix_fmt_mp->plane_fmt[2].bytesperline =3D - pix_fmt_mp->width / 2; - } + /* find next closer width align 16, heign align 32, size align + * 64 rectangle + */ + tmp_w =3D pix_fmt_mp->width; + tmp_h =3D pix_fmt_mp->height; + v4l_bound_align_image(&pix_fmt_mp->width, + MTK_VENC_MIN_W, + max_width, 4, + &pix_fmt_mp->height, + MTK_VENC_MIN_H, + max_height, 5, 6); + + if (pix_fmt_mp->width < tmp_w && (pix_fmt_mp->width + 16) <=3D max_width) + pix_fmt_mp->width +=3D 16; + if (pix_fmt_mp->height < tmp_h && (pix_fmt_mp->height + 32) <=3D max_heig= ht) + pix_fmt_mp->height +=3D 32; + + mtk_v4l2_debug(0, "before resize w=3D%d, h=3D%d, after resize w=3D%d, h= =3D%d, sizeimage=3D%d %d", + tmp_w, tmp_h, pix_fmt_mp->width, + pix_fmt_mp->height, + pix_fmt_mp->plane_fmt[0].sizeimage, + pix_fmt_mp->plane_fmt[1].sizeimage); + + pix_fmt_mp->num_planes =3D fmt->num_planes; + pix_fmt_mp->plane_fmt[0].sizeimage =3D + pix_fmt_mp->width * pix_fmt_mp->height + + ((ALIGN(pix_fmt_mp->width, 16) * 2) * 16); + pix_fmt_mp->plane_fmt[0].bytesperline =3D pix_fmt_mp->width; + + if (pix_fmt_mp->num_planes =3D=3D 2) { + pix_fmt_mp->plane_fmt[1].sizeimage =3D + (pix_fmt_mp->width * pix_fmt_mp->height) / 2 + + (ALIGN(pix_fmt_mp->width, 16) * 16); + pix_fmt_mp->plane_fmt[2].sizeimage =3D 0; + pix_fmt_mp->plane_fmt[1].bytesperline =3D + pix_fmt_mp->width; + pix_fmt_mp->plane_fmt[2].bytesperline =3D 0; + } else if (pix_fmt_mp->num_planes =3D=3D 3) { + pix_fmt_mp->plane_fmt[1].sizeimage =3D + pix_fmt_mp->plane_fmt[2].sizeimage =3D + (pix_fmt_mp->width * pix_fmt_mp->height) / 4 + + ((ALIGN(pix_fmt_mp->width, 16) / 2) * 16); + pix_fmt_mp->plane_fmt[1].bytesperline =3D + pix_fmt_mp->plane_fmt[2].bytesperline =3D + pix_fmt_mp->width / 2; } =20 pix_fmt_mp->flags =3D 0; @@ -432,9 +427,7 @@ static int vidioc_venc_s_fmt_cap(struct file *file, voi= d *priv, } =20 q_data->fmt =3D fmt; - ret =3D vidioc_try_fmt(ctx, f, q_data->fmt); - if (ret) - return ret; + vidioc_try_fmt_cap(f); =20 q_data->coded_width =3D f->fmt.pix_mp.width; q_data->coded_height =3D f->fmt.pix_mp.height; @@ -494,7 +487,7 @@ static int vidioc_venc_s_fmt_out(struct file *file, voi= d *priv, f->fmt.pix.pixelformat =3D fmt->fourcc; } =20 - ret =3D vidioc_try_fmt(ctx, f, fmt); + ret =3D vidioc_try_fmt_out(ctx, f, fmt); if (ret) return ret; =20 @@ -572,7 +565,9 @@ static int vidioc_try_fmt_vid_cap_mplane(struct file *f= ile, void *priv, f->fmt.pix_mp.quantization =3D ctx->quantization; f->fmt.pix_mp.xfer_func =3D ctx->xfer_func; =20 - return vidioc_try_fmt(ctx, f, fmt); + vidioc_try_fmt_cap(f); + + return 0; } =20 static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv, @@ -594,7 +589,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *f= ile, void *priv, f->fmt.pix_mp.xfer_func =3D V4L2_XFER_FUNC_DEFAULT; } =20 - return vidioc_try_fmt(ctx, f, fmt); + return vidioc_try_fmt_out(ctx, f, fmt); } =20 static int vidioc_venc_g_selection(struct file *file, void *priv, --=20 2.17.1 From nobody Sun Sep 22 13:12:16 2024 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDAA2C433EF for ; Wed, 17 Nov 2021 13:07:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF77E61BF9 for ; Wed, 17 Nov 2021 13:07:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237451AbhKQNKC (ORCPT ); Wed, 17 Nov 2021 08:10:02 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:49556 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237416AbhKQNJ7 (ORCPT ); Wed, 17 Nov 2021 08:09:59 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id 8B4BB1F45D05 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=collabora.com; s=mail; t=1637154420; bh=SOIfKJTF3ojVjdj5pNKtgKYrGmMpjOI/etlet6g4CfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oXHaIMrHZL2Kf6Z6hLYftuq3Srst9bAzqCibEfCUy8HilO3ozsLTBneFywPwSp3RU bvTsliBjcRzI1Fx39XAx3mhwVNy2IED95Mx+bBqiHFR8EVXd4k0geTdjhA0uZYBYSS YlZmJytVyITNyhNBY2QKcgg/i/ysEeaYQTrHiO1/a5UKECVVa3XYfA+lvwD02oxY9y xcT/g2OzLx8TiLHb09YGNwLGZr2GtbR97/siReL6t+S9AzkWepXdqOuBsPJQ47yXze R5fELdZnNipwoYgRMwuAL0GZwXEzNmYqOFvFW1528G2KIty2zIY6JhxNePUngj7x+4 TIKgjbar7REiw== From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: Dafna Hirschfeld , kernel@collabora.com, acourbot@chromium.org, andrew-ct.chen@mediatek.com, courbot@chromium.org, dafna3@gmail.com, eizan@chromium.org, houlong.wei@mediatek.com, hsinyi@chromium.org, hverkuil@xs4all.nl, irui.wang@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, maoguang.meng@mediatek.com, matthias.bgg@gmail.com, mchehab@kernel.org, minghsiu.tsai@mediatek.com, tfiga@chromium.org, tiffany.lin@mediatek.com Subject: [PATCH v2 6/7] media: mtk-vcodec: don't check return val of mtk_venc_get_q_data Date: Wed, 17 Nov 2021 15:06:34 +0200 Message-Id: <20211117130635.11633-7-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211117130635.11633-1-dafna.hirschfeld@collabora.com> References: <20211117130635.11633-1-dafna.hirschfeld@collabora.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The function mtk_venc_get_q_data always returns a reference so there is no need to check if the return value is null. In addition move the q_data initialization to the declaration Signed-off-by: Dafna Hirschfeld --- .../platform/mtk-vcodec/mtk_vcodec_enc.c | 39 ++++--------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_enc.c index be28f2401839..5caaeb4773ca 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c @@ -399,7 +399,7 @@ static int vidioc_venc_s_fmt_cap(struct file *file, voi= d *priv, struct mtk_vcodec_ctx *ctx =3D fh_to_ctx(priv); const struct mtk_vcodec_enc_pdata *pdata =3D ctx->dev->venc_pdata; struct vb2_queue *vq; - struct mtk_q_data *q_data; + struct mtk_q_data *q_data =3D mtk_venc_get_q_data(ctx, f->type); int i, ret; const struct mtk_video_fmt *fmt; =20 @@ -414,12 +414,6 @@ static int vidioc_venc_s_fmt_cap(struct file *file, vo= id *priv, return -EBUSY; } =20 - q_data =3D mtk_venc_get_q_data(ctx, f->type); - if (!q_data) { - mtk_v4l2_err("fail to get q data"); - return -EINVAL; - } - fmt =3D mtk_venc_find_format(f->fmt.pix.pixelformat, pdata); if (!fmt) { fmt =3D &ctx->dev->venc_pdata->capture_formats[0]; @@ -460,7 +454,7 @@ static int vidioc_venc_s_fmt_out(struct file *file, voi= d *priv, struct mtk_vcodec_ctx *ctx =3D fh_to_ctx(priv); const struct mtk_vcodec_enc_pdata *pdata =3D ctx->dev->venc_pdata; struct vb2_queue *vq; - struct mtk_q_data *q_data; + struct mtk_q_data *q_data =3D mtk_venc_get_q_data(ctx, f->type); int ret, i; const struct mtk_video_fmt *fmt; =20 @@ -475,12 +469,6 @@ static int vidioc_venc_s_fmt_out(struct file *file, vo= id *priv, return -EBUSY; } =20 - q_data =3D mtk_venc_get_q_data(ctx, f->type); - if (!q_data) { - mtk_v4l2_err("fail to get q data"); - return -EINVAL; - } - fmt =3D mtk_venc_find_format(f->fmt.pix.pixelformat, pdata); if (!fmt) { fmt =3D &ctx->dev->venc_pdata->output_formats[0]; @@ -520,14 +508,13 @@ static int vidioc_venc_g_fmt(struct file *file, void = *priv, struct v4l2_pix_format_mplane *pix =3D &f->fmt.pix_mp; struct mtk_vcodec_ctx *ctx =3D fh_to_ctx(priv); struct vb2_queue *vq; - struct mtk_q_data *q_data; + struct mtk_q_data *q_data =3D mtk_venc_get_q_data(ctx, f->type); int i; =20 vq =3D v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); if (!vq) return -EINVAL; =20 - q_data =3D mtk_venc_get_q_data(ctx, f->type); =20 pix->width =3D q_data->coded_width; pix->height =3D q_data->coded_height; @@ -596,15 +583,11 @@ static int vidioc_venc_g_selection(struct file *file,= void *priv, struct v4l2_selection *s) { struct mtk_vcodec_ctx *ctx =3D fh_to_ctx(priv); - struct mtk_q_data *q_data; + struct mtk_q_data *q_data =3D mtk_venc_get_q_data(ctx, s->type); =20 if (s->type !=3D V4L2_BUF_TYPE_VIDEO_OUTPUT) return -EINVAL; =20 - q_data =3D mtk_venc_get_q_data(ctx, s->type); - if (!q_data) - return -EINVAL; - switch (s->target) { case V4L2_SEL_TGT_CROP_DEFAULT: case V4L2_SEL_TGT_CROP_BOUNDS: @@ -630,15 +613,11 @@ static int vidioc_venc_s_selection(struct file *file,= void *priv, struct v4l2_selection *s) { struct mtk_vcodec_ctx *ctx =3D fh_to_ctx(priv); - struct mtk_q_data *q_data; + struct mtk_q_data *q_data =3D mtk_venc_get_q_data(ctx, s->type); =20 if (s->type !=3D V4L2_BUF_TYPE_VIDEO_OUTPUT) return -EINVAL; =20 - q_data =3D mtk_venc_get_q_data(ctx, s->type); - if (!q_data) - return -EINVAL; - switch (s->target) { case V4L2_SEL_TGT_CROP: /* Only support crop from (0,0) */ @@ -805,11 +784,9 @@ static int vb2ops_venc_queue_setup(struct vb2_queue *v= q, struct device *alloc_devs[]) { struct mtk_vcodec_ctx *ctx =3D vb2_get_drv_priv(vq); - struct mtk_q_data *q_data; + struct mtk_q_data *q_data =3D mtk_venc_get_q_data(ctx, vq->type); unsigned int i; =20 - q_data =3D mtk_venc_get_q_data(ctx, vq->type); - if (q_data =3D=3D NULL) return -EINVAL; =20 @@ -829,11 +806,9 @@ static int vb2ops_venc_queue_setup(struct vb2_queue *v= q, static int vb2ops_venc_buf_prepare(struct vb2_buffer *vb) { struct mtk_vcodec_ctx *ctx =3D vb2_get_drv_priv(vb->vb2_queue); - struct mtk_q_data *q_data; + struct mtk_q_data *q_data =3D mtk_venc_get_q_data(ctx, vb->vb2_queue->typ= e); int i; =20 - q_data =3D mtk_venc_get_q_data(ctx, vb->vb2_queue->type); - for (i =3D 0; i < q_data->fmt->num_planes; i++) { if (vb2_plane_size(vb, i) < q_data->sizeimage[i]) { mtk_v4l2_err("data will not fit into plane %d (%lu < %d)", --=20 2.17.1 From nobody Sun Sep 22 13:12:16 2024 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DD0EC4332F for ; Wed, 17 Nov 2021 13:07:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 801F061C12 for ; Wed, 17 Nov 2021 13:07:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237470AbhKQNKK (ORCPT ); Wed, 17 Nov 2021 08:10:10 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:49570 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237414AbhKQNKC (ORCPT ); Wed, 17 Nov 2021 08:10:02 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id BA1BA1F45D0A DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=collabora.com; s=mail; t=1637154422; bh=6JMAnV3RU7RwxpTblaM1Xwfo9CIzsVLv7HT0qSc5yyQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V0y1+dhcIn4dzVKvvaG1AjlLhVGnJduVtVXopyE9WhW+RYT0wMEZbpUdoN9ct6UAi LIhM69tNYae0SF0Re5z94C+xDKNAdUGrRy9Sl2NjBGpF7A4hDgJZhSPrOBUJFwomxo ut8GcQnJPl7MhrflZOi2NSiHEQB3/VQ7kvGVE2hV1Qo0VAcrhsW8xKUOprzDGx4k/F vIMWgefS827bSjGuV8YQcmhMDeoUPK2ovm39pUKhyOjkBOOi/swrJd+q2CiAEbTtih ZcyUVmreU/5s+MDgFF7BcnDKb+eW8odFOvRwaOdPykC9rPaEHs9u9kR1de0JGWW3ov ga7QaA9XgeX/Q== From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: Dafna Hirschfeld , kernel@collabora.com, acourbot@chromium.org, andrew-ct.chen@mediatek.com, courbot@chromium.org, dafna3@gmail.com, eizan@chromium.org, houlong.wei@mediatek.com, hsinyi@chromium.org, hverkuil@xs4all.nl, irui.wang@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, maoguang.meng@mediatek.com, matthias.bgg@gmail.com, mchehab@kernel.org, minghsiu.tsai@mediatek.com, tfiga@chromium.org, tiffany.lin@mediatek.com Subject: [PATCH v2 7/7] meida: mtk-vcodec: remove unused func parameter Date: Wed, 17 Nov 2021 15:06:35 +0200 Message-Id: <20211117130635.11633-8-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211117130635.11633-1-dafna.hirschfeld@collabora.com> References: <20211117130635.11633-1-dafna.hirschfeld@collabora.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The prarameter bs_size to function vpu_enc_encode is not used. Remove it. Signed-off-by: Dafna Hirschfeld --- drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c | 9 +++------ drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c | 3 +-- drivers/media/platform/mtk-vcodec/venc_vpu_if.c | 1 - drivers/media/platform/mtk-vcodec/venc_vpu_if.h | 1 - 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c b/driver= s/media/platform/mtk-vcodec/venc/venc_h264_if.c index b6a4f2074fa5..bf03888a824f 100644 --- a/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c +++ b/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c @@ -367,8 +367,7 @@ static int h264_encode_sps(struct venc_h264_inst *inst, =20 mtk_vcodec_debug_enter(inst); =20 - ret =3D vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_SPS, NULL, - bs_buf, bs_size, NULL); + ret =3D vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_SPS, NULL, bs_buf, N= ULL); if (ret) return ret; =20 @@ -394,8 +393,7 @@ static int h264_encode_pps(struct venc_h264_inst *inst, =20 mtk_vcodec_debug_enter(inst); =20 - ret =3D vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_PPS, NULL, - bs_buf, bs_size, NULL); + ret =3D vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_PPS, NULL, bs_buf, N= ULL); if (ret) return ret; =20 @@ -451,8 +449,7 @@ static int h264_encode_frame(struct venc_h264_inst *ins= t, mtk_vcodec_debug(inst, "frm_count =3D %d,skip_frm_count =3D%d,frm_type=3D= %d.\n", frame_info.frm_count, frame_info.skip_frm_count, frame_info.frm_type); - ret =3D vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_FRAME, frm_buf, - bs_buf, bs_size, &frame_info); + ret =3D vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_FRAME, frm_buf, bs_b= uf, &frame_info); if (ret) return ret; =20 diff --git a/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c b/drivers= /media/platform/mtk-vcodec/venc/venc_vp8_if.c index 8267a9c4fd25..6b66957d5192 100644 --- a/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c +++ b/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c @@ -302,8 +302,7 @@ static int vp8_enc_encode_frame(struct venc_vp8_inst *i= nst, =20 mtk_vcodec_debug(inst, "->frm_cnt=3D%d", inst->frm_cnt); =20 - ret =3D vpu_enc_encode(&inst->vpu_inst, 0, frm_buf, bs_buf, bs_size, - NULL); + ret =3D vpu_enc_encode(&inst->vpu_inst, 0, frm_buf, bs_buf, NULL); if (ret) return ret; =20 diff --git a/drivers/media/platform/mtk-vcodec/venc_vpu_if.c b/drivers/medi= a/platform/mtk-vcodec/venc_vpu_if.c index be6d8790a41e..e7899d8a3e4e 100644 --- a/drivers/media/platform/mtk-vcodec/venc_vpu_if.c +++ b/drivers/media/platform/mtk-vcodec/venc_vpu_if.c @@ -225,7 +225,6 @@ int vpu_enc_set_param(struct venc_vpu_inst *vpu, int vpu_enc_encode(struct venc_vpu_inst *vpu, unsigned int bs_mode, struct venc_frm_buf *frm_buf, struct mtk_vcodec_mem *bs_buf, - unsigned int *bs_size, struct venc_frame_info *frame_info) { const bool is_ext =3D MTK_ENC_CTX_IS_EXT(vpu->ctx); diff --git a/drivers/media/platform/mtk-vcodec/venc_vpu_if.h b/drivers/medi= a/platform/mtk-vcodec/venc_vpu_if.h index f9be9cab7ff7..f83bc1b3f2bf 100644 --- a/drivers/media/platform/mtk-vcodec/venc_vpu_if.h +++ b/drivers/media/platform/mtk-vcodec/venc_vpu_if.h @@ -45,7 +45,6 @@ int vpu_enc_set_param(struct venc_vpu_inst *vpu, int vpu_enc_encode(struct venc_vpu_inst *vpu, unsigned int bs_mode, struct venc_frm_buf *frm_buf, struct mtk_vcodec_mem *bs_buf, - unsigned int *bs_size, struct venc_frame_info *frame_info); int vpu_enc_deinit(struct venc_vpu_inst *vpu); =20 --=20 2.17.1