Re: [PATCH] media: iris: fix module removal if firmware download failed

From: Dikshita Agarwal
Date: Fri Aug 22 2025 - 01:29:53 EST




On 8/21/2025 5:57 PM, Neil Armstrong wrote:
> On 21/08/2025 11:42, Dikshita Agarwal wrote:
>>
>>
>> On 8/20/2025 10:36 PM, Neil Armstrong wrote:
>>> Fix remove if firmware failed to load:
>>> qcom-iris aa00000.video-codec: Direct firmware load for
>>> qcom/vpu/vpu33_p4.mbn failed with error -2
>>> qcom-iris aa00000.video-codec: firmware download failed
>>> qcom-iris aa00000.video-codec: core init failed
>>>
>>> then:
>>> $ echo aa00000.video-codec > /sys/bus/platform/drivers/qcom-iris/unbind
>>>
>>> Triggers:
>>> genpd genpd:1:aa00000.video-codec: Runtime PM usage count underflow!
>>> ------------[ cut here ]------------
>>> video_cc_mvs0_clk already disabled
>>> WARNING: drivers/clk/clk.c:1206 at clk_core_disable+0xa4/0xac, CPU#1:
>>> sh/542
>>> <snip>
>>> pc : clk_core_disable+0xa4/0xac
>>> lr : clk_core_disable+0xa4/0xac
>>> <snip>
>>> Call trace:
>>>   clk_core_disable+0xa4/0xac (P)
>>>   clk_disable+0x30/0x4c
>>>   iris_disable_unprepare_clock+0x20/0x48 [qcom_iris]
>>>   iris_vpu_power_off_hw+0x48/0x58 [qcom_iris]
>>>   iris_vpu33_power_off_hardware+0x44/0x230 [qcom_iris]
>>>   iris_vpu_power_off+0x34/0x84 [qcom_iris]
>>>   iris_core_deinit+0x44/0xc8 [qcom_iris]
>>>   iris_remove+0x20/0x48 [qcom_iris]
>>>   platform_remove+0x20/0x30
>>>   device_remove+0x4c/0x80
>>> <snip>
>>> ---[ end trace 0000000000000000 ]---
>>> ------------[ cut here ]------------
>>> video_cc_mvs0_clk already unprepared
>>> WARNING: drivers/clk/clk.c:1065 at clk_core_unprepare+0xf0/0x110, CPU#2:
>>> sh/542
>>> <snip>
>>> pc : clk_core_unprepare+0xf0/0x110
>>> lr : clk_core_unprepare+0xf0/0x110
>>> <snip>
>>> Call trace:
>>>   clk_core_unprepare+0xf0/0x110 (P)
>>>   clk_unprepare+0x2c/0x44
>>>   iris_disable_unprepare_clock+0x28/0x48 [qcom_iris]
>>>   iris_vpu_power_off_hw+0x48/0x58 [qcom_iris]
>>>   iris_vpu33_power_off_hardware+0x44/0x230 [qcom_iris]
>>>   iris_vpu_power_off+0x34/0x84 [qcom_iris]
>>>   iris_core_deinit+0x44/0xc8 [qcom_iris]
>>>   iris_remove+0x20/0x48 [qcom_iris]
>>>   platform_remove+0x20/0x30
>>>   device_remove+0x4c/0x80
>>> <snip>
>>> ---[ end trace 0000000000000000 ]---
>>> genpd genpd:0:aa00000.video-codec: Runtime PM usage count underflow!
>>> ------------[ cut here ]------------
>>> gcc_video_axi0_clk already disabled
>>> WARNING: drivers/clk/clk.c:1206 at clk_core_disable+0xa4/0xac, CPU#4:
>>> sh/542
>>> <snip>
>>> pc : clk_core_disable+0xa4/0xac
>>> lr : clk_core_disable+0xa4/0xac
>>> <snip>
>>> Call trace:
>>>   clk_core_disable+0xa4/0xac (P)
>>>   clk_disable+0x30/0x4c
>>>   iris_disable_unprepare_clock+0x20/0x48 [qcom_iris]
>>>   iris_vpu33_power_off_controller+0x17c/0x428 [qcom_iris]
>>>   iris_vpu_power_off+0x48/0x84 [qcom_iris]
>>>   iris_core_deinit+0x44/0xc8 [qcom_iris]
>>>   iris_remove+0x20/0x48 [qcom_iris]
>>>   platform_remove+0x20/0x30
>>>   device_remove+0x4c/0x80
>>> <snip>
>>> ------------[ cut here ]------------
>>> gcc_video_axi0_clk already unprepared
>>> WARNING: drivers/clk/clk.c:1065 at clk_core_unprepare+0xf0/0x110, CPU#4:
>>> sh/542
>>> <snip>
>>> pc : clk_core_unprepare+0xf0/0x110
>>> lr : clk_core_unprepare+0xf0/0x110
>>> <snip>
>>> Call trace:
>>>   clk_core_unprepare+0xf0/0x110 (P)
>>>   clk_unprepare+0x2c/0x44
>>>   iris_disable_unprepare_clock+0x28/0x48 [qcom_iris]
>>>   iris_vpu33_power_off_controller+0x17c/0x428 [qcom_iris]
>>>   iris_vpu_power_off+0x48/0x84 [qcom_iris]
>>>   iris_core_deinit+0x44/0xc8 [qcom_iris]
>>>   iris_remove+0x20/0x48 [qcom_iris]
>>>   platform_remove+0x20/0x30
>>>   device_remove+0x4c/0x80
>>> <snip>
>>> ---[ end trace 0000000000000000 ]---
>>>
>>> Skip deinit if initialization never succeeded.
>>>
>>> Signed-off-by: Neil Armstrong <neil.armstrong@xxxxxxxxxx>
>>> ---
>>>   drivers/media/platform/qcom/iris/iris_core.c | 10 ++++++----
>>>   1 file changed, 6 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/drivers/media/platform/qcom/iris/iris_core.c
>>> b/drivers/media/platform/qcom/iris/iris_core.c
>>> index
>>> 0fa0a3b549a23877af57c9950a5892e821b9473a..8406c48d635b6eba0879396ce9f9ae2292743f09 100644
>>> --- a/drivers/media/platform/qcom/iris/iris_core.c
>>> +++ b/drivers/media/platform/qcom/iris/iris_core.c
>>> @@ -15,10 +15,12 @@ void iris_core_deinit(struct iris_core *core)
>>>       pm_runtime_resume_and_get(core->dev);
>>>         mutex_lock(&core->lock);
>>> -    iris_fw_unload(core);
>>> -    iris_vpu_power_off(core);
>>> -    iris_hfi_queues_deinit(core);
>>> -    core->state = IRIS_CORE_DEINIT;
>>> +    if (core->state != IRIS_CORE_DEINIT) {
>>> +        iris_fw_unload(core);
>>> +        iris_vpu_power_off(core);
>>> +        iris_hfi_queues_deinit(core);
>>> +        core->state = IRIS_CORE_DEINIT;
>>> +    }
>>>       mutex_unlock(&core->lock);
>>>         pm_runtime_put_sync(core->dev);
>>>
>>
>> The iris_core_deinit() API should ideally not be called when core->state is
>> in IRIS_CORE_DEINIT. Better to handle this check in the caller itself.
>
> Checking core->state in iris_remove() won't be protected by the core->lock,
> so the check and call to iris_core_deinit() should be done _after_
> unregistering
> the v4l2 devices to make sure there's no more users of core.
>
> As you want, I think my approach is simpler and don't change the state if
> already in deinit state.

Agree.

Reviewed-by: Dikshita Agarwal <quic_dikshita@xxxxxxxxxxx>

>
> Neil
>
>>
>>> ---
>>> base-commit: 5303936d609e09665deda94eaedf26a0e5c3a087
>>> change-id: 20250820-topic-sm8x50-iris-remove-fix-76f86621d6ac
>>>
>>> Best regards,
>