media: venus: factor out inst destruction routine
authorSergey Senozhatsky <senozhatsky@chromium.org>
Fri, 25 Oct 2024 16:56:43 +0000 (01:56 +0900)
committerHans Verkuil <hverkuil@xs4all.nl>
Thu, 7 Nov 2024 10:43:31 +0000 (10:43 +0000)
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>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Stanimir Varbanov <stanimir.k.varbanov@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
drivers/media/platform/qcom/venus/core.c
drivers/media/platform/qcom/venus/core.h
drivers/media/platform/qcom/venus/vdec.c
drivers/media/platform/qcom/venus/vdec.h
drivers/media/platform/qcom/venus/vdec_ctrls.c
drivers/media/platform/qcom/venus/venc.c
drivers/media/platform/qcom/venus/venc.h
drivers/media/platform/qcom/venus/venc_ctrls.c

index 5caa88b932b07f2807cfe0894dfa0e17f95b8b39..4e26b18790537885a77d66c1917a4e7a146eaf57 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 #include <media/videobuf2-v4l2.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-mem2mem.h>
 #include <media/v4l2-ioctl.h>
 
@@ -502,6 +503,30 @@ err_cpucfg_path:
        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);
+       v4l2_ctrl_handler_free(&inst->ctrl_handler);
+
+       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);
index fd46a7778d8c4496cebeb938088e5842e3144fef..27784fd7082c321222b23ca4b2902a04c49e19ca 100644 (file)
@@ -568,4 +568,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
index 90fd4cb4eea9f550b9b1f51add1f5a337a956b1d..98c22b9f9372180a113923bcd56fb24808eb1d94 100644 (file)
@@ -1735,7 +1735,7 @@ err_m2m_release:
 err_session_destroy:
        hfi_session_destroy(inst);
 err_ctrl_deinit:
-       vdec_ctrl_deinit(inst);
+       v4l2_ctrl_handler_free(&inst->ctrl_handler);
 err_free:
        kfree(inst);
        return ret;
@@ -1746,29 +1746,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);
index 6b262d0bf561b8f0781de6b6473e70cefeac29a0..0cf981108ff08cf591bfad61c8e7608065f4c6d4 100644 (file)
@@ -9,6 +9,5 @@
 struct venus_inst;
 
 int vdec_ctrl_init(struct venus_inst *inst);
-void vdec_ctrl_deinit(struct venus_inst *inst);
 
 #endif
index 7e0f29bf7fae067ef1c2caa9b49a823552c37ca5..36ed955b041941d33c50fcbca0f685918cac2698 100644 (file)
@@ -187,8 +187,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);
-}
index 00819483bdc4f253a966bccf6b5ce0856358de31..c1c543535aaf5e1326d99f496f8403d124b04944 100644 (file)
@@ -1528,7 +1528,7 @@ err_m2m_release:
 err_session_destroy:
        hfi_session_destroy(inst);
 err_ctrl_deinit:
-       venc_ctrl_deinit(inst);
+       v4l2_ctrl_handler_free(&inst->ctrl_handler);
 err_free:
        kfree(inst);
        return ret;
@@ -1539,28 +1539,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);
index 4ea37fdcd9b8f01f7e79b2ef2a2cacaad1d46847..719d0f73b14b80ef31a42b831abdc7269ce411f3 100644 (file)
@@ -9,6 +9,5 @@
 struct venus_inst;
 
 int venc_ctrl_init(struct venus_inst *inst);
-void venc_ctrl_deinit(struct venus_inst *inst);
 
 #endif
index e340783a4ef28e6aadc1517689ccc5189386bf7f..51801a962ed2cc271137e06c84cfb0d1520d962b 100644 (file)
@@ -733,8 +733,3 @@ err:
        v4l2_ctrl_handler_free(&inst->ctrl_handler);
        return ret;
 }
-
-void venc_ctrl_deinit(struct venus_inst *inst)
-{
-       v4l2_ctrl_handler_free(&inst->ctrl_handler);
-}