Patchwork spapr_vscsi: Error handling fixes

login
register
mail settings
Submitter Benjamin Herrenschmidt
Date June 19, 2012, 6:02 a.m.
Message ID <1340085758.28143.4.camel@pasglop>
Download mbox | patch
Permalink /patch/165652/
State New
Headers show

Comments

Benjamin Herrenschmidt - June 19, 2012, 6:02 a.m.
We were incorrectly g_free'ing an object that isn't allocated
in one error path and failed to release it completely in another

This fixes qemu crashes with some cases of IO errors.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 hw/spapr_vscsi.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)



--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andreas Färber - June 19, 2012, 11:31 a.m.
Am 19.06.2012 08:02, schrieb Benjamin Herrenschmidt:
> We were incorrectly g_free'ing an object that isn't allocated
> in one error path and failed to release it completely in another
> 
> This fixes qemu crashes with some cases of IO errors.
> 
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> ---
>  hw/spapr_vscsi.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/spapr_vscsi.c b/hw/spapr_vscsi.c
> index d2fe3e5..6afc3b4 100644
> --- a/hw/spapr_vscsi.c
> +++ b/hw/spapr_vscsi.c
> @@ -801,6 +801,7 @@ static void vscsi_got_payload(VSCSIState *s, vscsi_crq *crq)
>      if (crq->s.IU_length > sizeof(union viosrp_iu)) {
>          fprintf(stderr, "VSCSI: SRP IU too long (%d bytes) !\n",
>                  crq->s.IU_length);
> +        vscsi_put_req(req);
>          return;
>      }
>  
> @@ -808,7 +809,8 @@ static void vscsi_got_payload(VSCSIState *s, vscsi_crq *crq)
>      if (spapr_vio_dma_read(&s->vdev, crq->s.IU_data_ptr, &req->iu,
>                             crq->s.IU_length)) {
>          fprintf(stderr, "vscsi_got_payload: DMA read failure !\n");
> -        g_free(req);
> +        vscsi_put_req(req);

> +	return;

Tab alert. :)

/-F

>      }
>      memcpy(&req->crq, crq, sizeof(vscsi_crq));
>  
> 
> 
>
Benjamin Herrenschmidt - June 19, 2012, 8:18 p.m.
On Tue, 2012-06-19 at 13:31 +0200, Andreas Färber wrote:
> Tab alert. :)

Argh :-) Gotta get an emacs config for use with qemu :-)

Cheers,
Ben.


--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alexander Graf - June 19, 2012, 8:20 p.m.
On 19.06.2012, at 22:18, Benjamin Herrenschmidt wrote:

> On Tue, 2012-06-19 at 13:31 +0200, Andreas Färber wrote:
>> Tab alert. :)
> 
> Argh :-) Gotta get an emacs config for use with qemu :-)

So do you want to resend? I can just fix it on the fly too.


Alex

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Benjamin Herrenschmidt - June 19, 2012, 8:46 p.m.
On Tue, 2012-06-19 at 22:20 +0200, Alexander Graf wrote:
> So do you want to resend? I can just fix it on the fly too.

If you can then sure, please do :-)

Cheers,
Ben.


--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alexander Graf - June 19, 2012, 8:57 p.m.
On 19.06.2012, at 08:02, Benjamin Herrenschmidt wrote:

> We were incorrectly g_free'ing an object that isn't allocated
> in one error path and failed to release it completely in another
> 
> This fixes qemu crashes with some cases of IO errors.
> 
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

Thanks, applied to ppc-next.


Alex

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/hw/spapr_vscsi.c b/hw/spapr_vscsi.c
index d2fe3e5..6afc3b4 100644
--- a/hw/spapr_vscsi.c
+++ b/hw/spapr_vscsi.c
@@ -801,6 +801,7 @@  static void vscsi_got_payload(VSCSIState *s, vscsi_crq *crq)
     if (crq->s.IU_length > sizeof(union viosrp_iu)) {
         fprintf(stderr, "VSCSI: SRP IU too long (%d bytes) !\n",
                 crq->s.IU_length);
+        vscsi_put_req(req);
         return;
     }
 
@@ -808,7 +809,8 @@  static void vscsi_got_payload(VSCSIState *s, vscsi_crq *crq)
     if (spapr_vio_dma_read(&s->vdev, crq->s.IU_data_ptr, &req->iu,
                            crq->s.IU_length)) {
         fprintf(stderr, "vscsi_got_payload: DMA read failure !\n");
-        g_free(req);
+        vscsi_put_req(req);
+	return;
     }
     memcpy(&req->crq, crq, sizeof(vscsi_crq));