kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing
Subsystems (3)
PATCH 1/1 kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing
This fixes error handling in the function mpic_set_default_irq_routing by checking if the call to the function kvm_set_irq_routing has failed and if so exit immediately to the caller by first freeing the structure pointer routing in order to avoid a memory leak before returning the error code returned by the call to mpic_set_default_irq_routing.
--- arch/powerpc/kvm/mpic.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/powerpc/kvm/mpic.c +6 -1
@@ -1641,13 +1641,18 @@ static void mpic_destroy(struct kvm_device *dev)static int mpic_set_default_irq_routing (struct openpic *opp) {struct kvm_irq_routing_entry *routing; +int ret;/* Create a nop default map, so that dereferencing it still works */ routing =kzalloc ((sizeof (*routing)),GFP_KERNEL );if (!routing)return -ENOMEM ; -kvm_set_irq_routing (opp->kvm, routing,0 ,0 ); + ret =kvm_set_irq_routing (opp->kvm, routing,0 ,0 ); +if (ret) { +kfree (routing); +return ret; + }kfree (routing);return 0 ;
Signature · 6 lines
2.1.4 _______________________________________________ Linuxppc-dev mailing list [email protected] https://lists.ozlabs.org/listinfo/linuxppc-dev
Paolo Bonzini
maintainerarch/powerpc/kvm/mpic.c static void mpic_destroy(struct kvm_device *dev) · line 1658
Quoted 9 lines · Nicholas Krause
arch/powerpc/kvm/mpic.c +5
-1-kvm_set_irq_routing (opp->kvm, routing,0 ,0 ); + ret =kvm_set_irq_routing (opp->kvm, routing,0 ,0 ); +if (ret) { +kfree (routing); +return ret; + }kfree (routing);return 0 ;
You could just return ret here. The new "if" is not necessary.
Paolo
Quoted 10 lines · Paolo Bonzini
Quoted 7 lines · Nicholas Krause
arch/powerpc/kvm/mpic.c +5
-1-kvm_set_irq_routing (opp->kvm, routing,0 ,0 ); + ret =kvm_set_irq_routing (opp->kvm, routing,0 ,0 ); +if (ret) { +kfree (routing); +return ret; + }
Quoted 7 lines
arch/powerpc/kvm/mpic.c static void mpic_destroy(struct kvm_device *dev) · line 1658
Quoted 2 lines
arch/powerpc/kvm/mpic.c +0
-0kfree (routing);return 0 ;You could just return ret here. The new "if" is not necessary.
Paolo
Ok sure that seems fine to be and much simpler then this. Sorry about the wasting your time with this patch. Nick
_______________________________________________
Linuxppc-dev mailing list [email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev