Re: [PATCH v5 3/4] irqchip/gic-v3-its: Fix leak in its_vpe_irq_domain_alloc()
From: Kemeng Shi
Date: Mon Jul 20 2026 - 21:28:49 EST
在 2026/7/20 16:50:00, Marc Zyngier 写道:
> On Mon, 20 Jul 2026 08:12:14 +0100,
> Kemeng Shi <shikemeng@xxxxxxxxxxxxxxx> wrote:
>>
>> When its_irq_gic_domain_alloc() fails, the following
>> its_vpe_irq_domain_free() skips calling its_vep_teardown() for the
>> corresponding irq. Try its_vpe_teardown() in error handling to avoid
>> the leak issue.
>>
>> Fixes: 7d75bbb4bc1ad ("irqchip/gic-v3-its: Add VPE irq domain allocation/teardown")
>> Signed-off-by: Kemeng Shi <shikemeng@xxxxxxxxxxxxxxx>
>> ---
>> drivers/irqchip/irq-gic-v3-its.c | 12 ++++++++----
>> 1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
>> index 3e4edcb64065..5dc91862fc15 100644
>> --- a/drivers/irqchip/irq-gic-v3-its.c
>> +++ b/drivers/irqchip/irq-gic-v3-its.c
>> @@ -4594,9 +4594,11 @@ static int its_vpe_init(struct its_vpe *vpe)
>>
>> static void its_vpe_teardown(struct its_vpe *vpe)
>> {
>> - its_vpe_db_proxy_unmap(vpe);
>> - its_vpe_id_free(vpe->vpe_id);
>> - its_free_pending_table(vpe->vpt_page);
>> + if (vpe->vpt_page != NULL) {
>> + its_vpe_db_proxy_unmap(vpe);
>> + its_vpe_id_free(vpe->vpe_id);
>> + its_free_pending_table(vpe->vpt_page);
>> + }
>
> Please keep the diff minimal by doing an early return. This also
> deserves a comment, because this is not completely obvious:
Sure, I will do it in next version soon.>
> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
> index 6f5811aae59c1..38032067135b6 100644
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c
> @@ -4592,6 +4592,13 @@ static int its_vpe_init(struct its_vpe *vpe)
>
> static void its_vpe_teardown(struct its_vpe *vpe)
> {
> + /*
> + * If vpt_page is NULL, then its_vpe_init() has failed, and
> + * there is nothing to do as no resource has been allocated.
> + */
> + if (!vpe->vpt_page)
> + return;
> +
> its_vpe_db_proxy_unmap(vpe);
> its_vpe_id_free(vpe->vpe_id);
> its_free_pending_table(vpe->vpt_page);
>
> M.
>