Re: [PATCH v2 5/6] media: iris: gen2: Add sanity check for session stop

From: Dikshita Agarwal

Date: Wed Jan 07 2026 - 05:06:31 EST




On 12/30/2025 4:03 PM, Bryan O'Donoghue wrote:
> On 29/12/2025 06:31, Dikshita Agarwal wrote:
>> In iris_kill_session, inst->state is set to IRIS_INST_ERROR and
>> session_close is executed, which will kfree(inst_hfi_gen2->packet).
>> If stop_streaming is called afterward, it will cause a crash.
>>
>> Add a NULL check for inst_hfi_gen2->packet before sendling STOP packet
>> to firmware to fix that.
>>
>> Fixes: 11712ce70f8e ("media: iris: implement vb2 streaming ops")
>> Signed-off-by: Dikshita Agarwal <dikshita.agarwal@xxxxxxxxxxxxxxxx>
>> ---
>>   drivers/media/platform/qcom/iris/iris_hfi_gen2_command.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/media/platform/qcom/iris/iris_hfi_gen2_command.c
>> b/drivers/media/platform/qcom/iris/iris_hfi_gen2_command.c
>> index
>> 6a772db2ec33fb002d8884753a41dc98b3a8439d..59e41adcce9aadd7c60bb1d369d68a4954f62aef 100644
>> --- a/drivers/media/platform/qcom/iris/iris_hfi_gen2_command.c
>> +++ b/drivers/media/platform/qcom/iris/iris_hfi_gen2_command.c
>> @@ -963,6 +963,9 @@ static int iris_hfi_gen2_session_stop(struct
>> iris_inst *inst, u32 plane)
>>       struct iris_inst_hfi_gen2 *inst_hfi_gen2 =
>> to_iris_inst_hfi_gen2(inst);
>>       int ret = 0;
>>
>> +    if (!inst_hfi_gen2->packet)
>> +        return -EINVAL;
>> +
>>       reinit_completion(&inst->completion);
>>
>>       iris_hfi_gen2_packet_session_command(inst,
>>
>> --
>> 2.34.1
>>
>
> Are you sure this NULL check is concurrency safe ?
>
> i.e. that ->session_stop() and ->session_close() cannot be executed
> concurrently ?

Yes, this is concurrency safe.

Both iris_hfi_gen2_session_stop() and iris_kill_session() are invoked while
holding inst->lock. For instance, iris_vb2_stop_streaming() locks the mutex
before calling session_stop(), and iris_kill_session() / session_close()
also grab the same lock before freeing inst_hfi_gen2->packet.

That ensures they never run concurrently, so the NULL-check protects
against the packet having been freed earlier without racing.

Thanks,
Dikshita

>
> ---
> bod