From: Dikshita Agarwal <quic_dikshita@quicinc.com>
To: Sergey Senozhatsky <senozhatsky@chromium.org>,
Stanimir Varbanov <stanimir.k.varbanov@gmail.com>,
Vikash Garodia <quic_vgarodia@quicinc.com>,
Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Cc: <linux-media@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCHv3 3/3] media: venus: factor out inst destruction routine
Date: Fri, 25 Oct 2024 13:36:44 +0530 [thread overview]
Message-ID: <eb8b998a-98b8-704d-8783-9a0def327424@quicinc.com> (raw)
In-Reply-To: <20241025034629.660047-4-senozhatsky@chromium.org>
On 10/25/2024 9:16 AM, Sergey Senozhatsky wrote:
> Factor out common instance destruction code into
> a common function.
>
> Suggested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> ---
> drivers/media/platform/qcom/venus/core.c | 25 +++++++++++++++++++
> drivers/media/platform/qcom/venus/core.h | 2 ++
> drivers/media/platform/qcom/venus/vdec.c | 22 +---------------
> drivers/media/platform/qcom/venus/vdec.h | 7 +++++-
> .../media/platform/qcom/venus/vdec_ctrls.c | 6 -----
> drivers/media/platform/qcom/venus/venc.c | 22 +---------------
> 6 files changed, 35 insertions(+), 49 deletions(-)
>
> diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c
> index 423deb5e94dc..4d90fc1c21fe 100644
> --- a/drivers/media/platform/qcom/venus/core.c
> +++ b/drivers/media/platform/qcom/venus/core.c
> @@ -26,6 +26,7 @@
> #include "firmware.h"
> #include "pm_helpers.h"
> #include "hfi_venus_io.h"
> +#include "vdec.h"
>
> static void venus_coredump(struct venus_core *core)
> {
> @@ -502,6 +503,30 @@ static __maybe_unused int venus_runtime_suspend(struct device *dev)
> return ret;
> }
>
> +void venus_close_common(struct venus_inst *inst)
> +{
> + /*
> + * First, remove the inst from the ->instances list, so that
> + * to_instance() will return NULL.
> + */
> + hfi_session_destroy(inst);
> + /*
> + * Second, make sure we don't have IRQ/IRQ-thread currently running
> + * or pending execution, which would race with the inst destruction.
> + */
> + synchronize_irq(inst->core->irq);
> +
> + v4l2_m2m_ctx_release(inst->m2m_ctx);
> + v4l2_m2m_release(inst->m2m_dev);
> + v4l2_fh_del(&inst->fh);
> + v4l2_fh_exit(&inst->fh);
> + vdec_ctrl_deinit(inst);
vdec specific APIs shouldn't be invoked from common API.
Pls call v4l2_ctrl_handler_free(&inst->ctrl_handler) directly from here.
and remove vdec/venc_ctrl_init.
> +
> + mutex_destroy(&inst->lock);
> + mutex_destroy(&inst->ctx_q_lock);
> +}
> +EXPORT_SYMBOL_GPL(venus_close_common);
> +
> static __maybe_unused int venus_runtime_resume(struct device *dev)
> {
> struct venus_core *core = dev_get_drvdata(dev);
> diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h
> index 435325432922..7bb36a270e15 100644
> --- a/drivers/media/platform/qcom/venus/core.h
> +++ b/drivers/media/platform/qcom/venus/core.h
> @@ -560,4 +560,6 @@ is_fw_rev_or_older(struct venus_core *core, u32 vmajor, u32 vminor, u32 vrev)
> (core)->venus_ver.minor == vminor &&
> (core)->venus_ver.rev <= vrev);
> }
> +
> +void venus_close_common(struct venus_inst *inst);
> #endif
> diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
> index b3192a36f388..9a680402c711 100644
> --- a/drivers/media/platform/qcom/venus/vdec.c
> +++ b/drivers/media/platform/qcom/venus/vdec.c
> @@ -1748,29 +1748,9 @@ static int vdec_close(struct file *file)
> struct venus_inst *inst = to_inst(file);
>
> vdec_pm_get(inst);
> -
> cancel_work_sync(&inst->delayed_process_work);
> - /*
> - * First, remove the inst from the ->instances list, so that
> - * to_instance() will return NULL.
> - */
> - hfi_session_destroy(inst);
> - /*
> - * Second, make sure we don't have IRQ/IRQ-thread currently running
> - * or pending execution, which would race with the inst destruction.
> - */
> - synchronize_irq(inst->core->irq);
> -
> - v4l2_m2m_ctx_release(inst->m2m_ctx);
> - v4l2_m2m_release(inst->m2m_dev);
> + venus_close_common(inst);
> ida_destroy(&inst->dpb_ids);
> - v4l2_fh_del(&inst->fh);
> - v4l2_fh_exit(&inst->fh);
> - vdec_ctrl_deinit(inst);
> -
> - mutex_destroy(&inst->lock);
> - mutex_destroy(&inst->ctx_q_lock);
> -
> vdec_pm_put(inst, false);
>
> kfree(inst);
> diff --git a/drivers/media/platform/qcom/venus/vdec.h b/drivers/media/platform/qcom/venus/vdec.h
> index 6b262d0bf561..2687255b1616 100644
> --- a/drivers/media/platform/qcom/venus/vdec.h
> +++ b/drivers/media/platform/qcom/venus/vdec.h
> @@ -6,9 +6,14 @@
> #ifndef __VENUS_VDEC_H__
> #define __VENUS_VDEC_H__
>
> +#include <media/v4l2-ctrls.h>
> +
> struct venus_inst;
>
> int vdec_ctrl_init(struct venus_inst *inst);
> -void vdec_ctrl_deinit(struct venus_inst *inst);
> +static inline void vdec_ctrl_deinit(struct venus_inst *inst)
> +{
> + v4l2_ctrl_handler_free(&inst->ctrl_handler);
> +}
>
> #endif
> diff --git a/drivers/media/platform/qcom/venus/vdec_ctrls.c b/drivers/media/platform/qcom/venus/vdec_ctrls.c
> index 7e0f29bf7fae..fa034a7fdbed 100644
> --- a/drivers/media/platform/qcom/venus/vdec_ctrls.c
> +++ b/drivers/media/platform/qcom/venus/vdec_ctrls.c
> @@ -4,7 +4,6 @@
> * Copyright (C) 2017 Linaro Ltd.
> */
> #include <linux/types.h>
> -#include <media/v4l2-ctrls.h>
>
> #include "core.h"
> #include "helpers.h"
> @@ -187,8 +186,3 @@ int vdec_ctrl_init(struct venus_inst *inst)
>
> return 0;
> }
> -
> -void vdec_ctrl_deinit(struct venus_inst *inst)
> -{
> - v4l2_ctrl_handler_free(&inst->ctrl_handler);
> -}
> diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c
> index 36981ce448f5..2ae22ba156bb 100644
> --- a/drivers/media/platform/qcom/venus/venc.c
> +++ b/drivers/media/platform/qcom/venus/venc.c
> @@ -1516,28 +1516,8 @@ static int venc_close(struct file *file)
> struct venus_inst *inst = to_inst(file);
>
> venc_pm_get(inst);
> -
> - /*
> - * First, remove the inst from the ->instances list, so that
> - * to_instance() will return NULL.
> - */
> - hfi_session_destroy(inst);
> - /*
> - * Second, make sure we don't have IRQ/IRQ-thread currently running
> - * or pending execution, which would race with the inst destruction.
> - */
> - synchronize_irq(inst->core->irq);
> -
> - v4l2_m2m_ctx_release(inst->m2m_ctx);
> - v4l2_m2m_release(inst->m2m_dev);
> - v4l2_fh_del(&inst->fh);
> - v4l2_fh_exit(&inst->fh);
> - venc_ctrl_deinit(inst);
> -
> + venus_close_common(inst);
> inst->enc_state = VENUS_ENC_STATE_DEINIT;
> - mutex_destroy(&inst->lock);
> - mutex_destroy(&inst->ctx_q_lock);
> -
> venc_pm_put(inst, false);
>
> kfree(inst);
prev parent reply other threads:[~2024-10-25 8:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-25 3:46 [PATCHv3 0/3] media: venus: close() fixes Sergey Senozhatsky
2024-10-25 3:46 ` [PATCHv3 1/3] media: venus: fix enc/dec destruction order Sergey Senozhatsky
2024-10-25 7:20 ` Dikshita Agarwal
2024-10-25 9:47 ` Sergey Senozhatsky
2024-10-25 3:46 ` [PATCHv3 2/3] media: venus: sync with threaded IRQ during inst destruction Sergey Senozhatsky
2024-10-25 3:46 ` [PATCHv3 3/3] media: venus: factor out inst destruction routine Sergey Senozhatsky
2024-10-25 8:06 ` Dikshita Agarwal [this message]
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=eb8b998a-98b8-704d-8783-9a0def327424@quicinc.com \
--to=quic_dikshita@quicinc.com \
--cc=bryan.odonoghue@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=quic_vgarodia@quicinc.com \
--cc=senozhatsky@chromium.org \
--cc=stanimir.k.varbanov@gmail.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
all inboxes | Powered by JetHome®