Use XFREE() instead of xfree() so that vcpu_vgic_free() can be idempotent.
With XFREE(), vgic_vcpu->private_irqs is set to NULL, so calling
vcpu_vgic_free() a second time is not an issue.
Update the prototype of vcpu_vgic_free() to return void to satisfy MISRA
Rule 17.7, since the return value of vcpu_vgic_free() is not used by any
callers.
Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
Change in v4:
- Add Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>.
---
Change in v3:
- New patch.
---
xen/arch/arm/include/asm/vgic.h | 2 +-
xen/arch/arm/vgic.c | 5 ++---
xen/arch/arm/vgic/vgic-init.c | 4 +---
3 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/xen/arch/arm/include/asm/vgic.h b/xen/arch/arm/include/asm/vgic.h
index 31b3d3e5ec5d..6f9ab1c98c1c 100644
--- a/xen/arch/arm/include/asm/vgic.h
+++ b/xen/arch/arm/include/asm/vgic.h
@@ -418,7 +418,7 @@ int domain_vgic_register(struct domain *d, unsigned int *mmio_count);
int domain_vgic_init(struct domain *d, unsigned int nr_spis);
void domain_vgic_free(struct domain *d);
int vcpu_vgic_init(struct vcpu *v);
-int vcpu_vgic_free(struct vcpu *v);
+void vcpu_vgic_free(struct vcpu *v);
void vgic_inject_irq(struct domain *d, struct vcpu *v, unsigned int virq,
bool level);
diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c
index 3ebdf9953f07..6647071ad4d7 100644
--- a/xen/arch/arm/vgic.c
+++ b/xen/arch/arm/vgic.c
@@ -390,10 +390,9 @@ int vcpu_vgic_init(struct vcpu *v)
return 0;
}
-int vcpu_vgic_free(struct vcpu *v)
+void vcpu_vgic_free(struct vcpu *v)
{
- xfree(v->arch.vgic.private_irqs);
- return 0;
+ XFREE(v->arch.vgic.private_irqs);
}
struct vcpu *vgic_get_target_vcpu(struct vcpu *v, unsigned int virq)
diff --git a/xen/arch/arm/vgic/vgic-init.c b/xen/arch/arm/vgic/vgic-init.c
index f8d7d3a226d0..aef526f2e717 100644
--- a/xen/arch/arm/vgic/vgic-init.c
+++ b/xen/arch/arm/vgic/vgic-init.c
@@ -239,13 +239,11 @@ void domain_vgic_free(struct domain *d)
dist->nr_spis = 0;
}
-int vcpu_vgic_free(struct vcpu *v)
+void vcpu_vgic_free(struct vcpu *v)
{
struct vgic_cpu *vgic_cpu = &v->arch.vgic;
INIT_LIST_HEAD(&vgic_cpu->ap_list_head);
-
- return 0;
}
/*
--
2.52.0
On 23/12/2025 18:01, Oleksii Kurochko wrote: > Use XFREE() instead of xfree() so that vcpu_vgic_free() can be idempotent. > With XFREE(), vgic_vcpu->private_irqs is set to NULL, so calling > vcpu_vgic_free() a second time is not an issue. Usually it would be beneficial to back such statement with an example of a situation where this is or will be the issue. > > Update the prototype of vcpu_vgic_free() to return void to satisfy MISRA > Rule 17.7, since the return value of vcpu_vgic_free() is not used by any > callers. > > Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com> > Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com> > Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com> Acked-by: Michal Orzel <michal.orzel@amd.com> ~Michal
On 12/29/25 11:50 AM, Orzel, Michal wrote: > > On 23/12/2025 18:01, Oleksii Kurochko wrote: >> Use XFREE() instead of xfree() so that vcpu_vgic_free() can be idempotent. >> With XFREE(), vgic_vcpu->private_irqs is set to NULL, so calling >> vcpu_vgic_free() a second time is not an issue. > Usually it would be beneficial to back such statement with an example of a > situation where this is or will be the issue. I think there is not a case now in current code base, but just common practice to have such type of functions to be idempotent. > >> Update the prototype of vcpu_vgic_free() to return void to satisfy MISRA >> Rule 17.7, since the return value of vcpu_vgic_free() is not used by any >> callers. >> >> Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com> >> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com> >> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com> > Acked-by: Michal Orzel <michal.orzel@amd.com> Thanks. ~ Oleksii
© 2016 - 2026 Red Hat, Inc.