All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing
@ 2015-08-07 13:47 ` Nicholas Krause
  0 siblings, 0 replies; 10+ messages in thread
From: Nicholas Krause @ 2015-08-07 13:47 UTC (permalink / raw)
  To: agraf; +Cc: kvm, gleb, linux-kernel, kvm-ppc, pbonzini, linuxppc-dev

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.

Signed-off-by: Nicholas Krause <xerofoify@gmail.com>
---
 arch/powerpc/kvm/mpic.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c
index 6249cdc..7b1375a 100644
--- a/arch/powerpc/kvm/mpic.c
+++ b/arch/powerpc/kvm/mpic.c
@@ -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;
-- 
2.1.4

_______________________________________________
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing
@ 2015-08-07 13:47 ` Nicholas Krause
  0 siblings, 0 replies; 10+ messages in thread
From: Nicholas Krause @ 2015-08-07 13:47 UTC (permalink / raw)
  To: agraf; +Cc: gleb, pbonzini, kvm-ppc, kvm, linuxppc-dev, linux-kernel

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.

Signed-off-by: Nicholas Krause <xerofoify@gmail.com>
---
 arch/powerpc/kvm/mpic.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c
index 6249cdc..7b1375a 100644
--- a/arch/powerpc/kvm/mpic.c
+++ b/arch/powerpc/kvm/mpic.c
@@ -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;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing
  2015-08-07 13:47 ` Nicholas Krause
@ 2015-08-07 13:59   ` Paolo Bonzini
  -1 siblings, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2015-08-07 13:59 UTC (permalink / raw)
  To: Nicholas Krause, agraf; +Cc: gleb, kvm-ppc, kvm, linuxppc-dev, linux-kernel



On 07/08/2015 15:47, Nicholas Krause wrote:
> -	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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing
@ 2015-08-07 13:59   ` Paolo Bonzini
  0 siblings, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2015-08-07 13:59 UTC (permalink / raw)
  To: Nicholas Krause, agraf; +Cc: gleb, kvm-ppc, kvm, linuxppc-dev, linux-kernel



On 07/08/2015 15:47, Nicholas Krause wrote:
> -	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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing
  2015-08-07 13:59   ` Paolo Bonzini
@ 2015-08-07 14:00     ` nick
  -1 siblings, 0 replies; 10+ messages in thread
From: nick @ 2015-08-07 14:00 UTC (permalink / raw)
  To: Paolo Bonzini, agraf; +Cc: gleb, linuxppc-dev, kvm, kvm-ppc, linux-kernel



On 2015-08-07 09:59 AM, Paolo Bonzini wrote:
> 
> 
> On 07/08/2015 15:47, Nicholas Krause wrote:
>> -	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
> 

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
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing
@ 2015-08-07 14:00     ` nick
  0 siblings, 0 replies; 10+ messages in thread
From: nick @ 2015-08-07 14:00 UTC (permalink / raw)
  To: Paolo Bonzini, agraf; +Cc: gleb, kvm-ppc, kvm, linuxppc-dev, linux-kernel



On 2015-08-07 09:59 AM, Paolo Bonzini wrote:
> 
> 
> On 07/08/2015 15:47, Nicholas Krause wrote:
>> -	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
> 

Ok sure that seems fine to be and much simpler then this.
Sorry about the wasting your time with this patch.
Nick 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing
  2015-08-06 17:13 ` Nicholas Krause
@ 2015-08-07 10:17   ` Paolo Bonzini
  -1 siblings, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2015-08-07 10:17 UTC (permalink / raw)
  To: Nicholas Krause, agraf; +Cc: gleb, kvm-ppc, kvm, linuxppc-dev, linux-kernel



On 06/08/2015 19:13, Nicholas Krause wrote:
> diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c
> index 6249cdc..5a18859 100644
> --- a/arch/powerpc/kvm/mpic.c
> +++ b/arch/powerpc/kvm/mpic.c
> @@ -1641,13 +1641,16 @@ 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)
> +		return ret;
>  
>  	kfree(routing);
>  	return 0;

The patch leaks the "routing" variable if you hit the error path.

Paolo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing
@ 2015-08-07 10:17   ` Paolo Bonzini
  0 siblings, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2015-08-07 10:17 UTC (permalink / raw)
  To: Nicholas Krause, agraf; +Cc: gleb, kvm-ppc, kvm, linuxppc-dev, linux-kernel



On 06/08/2015 19:13, Nicholas Krause wrote:
> diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c
> index 6249cdc..5a18859 100644
> --- a/arch/powerpc/kvm/mpic.c
> +++ b/arch/powerpc/kvm/mpic.c
> @@ -1641,13 +1641,16 @@ 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)
> +		return ret;
>  
>  	kfree(routing);
>  	return 0;

The patch leaks the "routing" variable if you hit the error path.

Paolo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing
@ 2015-08-06 17:13 ` Nicholas Krause
  0 siblings, 0 replies; 10+ messages in thread
From: Nicholas Krause @ 2015-08-06 17:13 UTC (permalink / raw)
  To: agraf; +Cc: kvm, gleb, linux-kernel, kvm-ppc, pbonzini, linuxppc-dev

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 returning the error code
returned by the call to mpic_set_default_irq_routing.

Signed-off-by: Nicholas Krause <xerofoify@gmail.com>
---
 arch/powerpc/kvm/mpic.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c
index 6249cdc..5a18859 100644
--- a/arch/powerpc/kvm/mpic.c
+++ b/arch/powerpc/kvm/mpic.c
@@ -1641,13 +1641,16 @@ 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)
+		return ret;
 
 	kfree(routing);
 	return 0;
-- 
2.1.4

_______________________________________________
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing
@ 2015-08-06 17:13 ` Nicholas Krause
  0 siblings, 0 replies; 10+ messages in thread
From: Nicholas Krause @ 2015-08-06 17:13 UTC (permalink / raw)
  To: agraf; +Cc: gleb, pbonzini, kvm-ppc, kvm, linuxppc-dev, linux-kernel

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 returning the error code
returned by the call to mpic_set_default_irq_routing.

Signed-off-by: Nicholas Krause <xerofoify@gmail.com>
---
 arch/powerpc/kvm/mpic.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c
index 6249cdc..5a18859 100644
--- a/arch/powerpc/kvm/mpic.c
+++ b/arch/powerpc/kvm/mpic.c
@@ -1641,13 +1641,16 @@ 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)
+		return ret;
 
 	kfree(routing);
 	return 0;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-08-07 14:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-07 13:47 [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing Nicholas Krause
2015-08-07 13:47 ` Nicholas Krause
2015-08-07 13:59 ` Paolo Bonzini
2015-08-07 13:59   ` Paolo Bonzini
2015-08-07 14:00   ` nick
2015-08-07 14:00     ` nick
  -- strict thread matches above, loose matches on Subject: below --
2015-08-06 17:13 Nicholas Krause
2015-08-06 17:13 ` Nicholas Krause
2015-08-07 10:17 ` Paolo Bonzini
2015-08-07 10:17   ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.