qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Cc: Erik Rull <904617@bugs.launchpad.net>,
	qemu-devel@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] usb: fix usb_qdev_init() error handling again
Date: Thu, 15 Dec 2011 12:11:26 -0600	[thread overview]
Message-ID: <4EEA384E.5020300@redhat.com> (raw)
In-Reply-To: <1323943518-7546-1-git-send-email-stefanha@linux.vnet.ibm.com>

On 12/15/2011 04:05 AM, Stefan Hajnoczi wrote:
> Commit f462141f18ffdd75847f6459ef83d90b831d12c0 introduced clean up code
> when usb_qdev_init() fails.  Unfortunately it calls .handle_destroy()
> when .init() was never invoked or failed.  This can lead to crashes when
> .handle_destroy() tries to clean up things that were never initialized.
>
> This patch is careful to undo only those steps that completed along the
> usb_qdev_init() code path.  It's not as pretty as the unified error
> handling in f462141f18ffdd75847f6459ef83d90b831d12c0 but it's necessary.
>
> Signed-off-by: Stefan Hajnoczi<stefanha@linux.vnet.ibm.com>

Applied.  Thanks.

Regards,

Anthony Liguori

> ---
>   hw/usb-bus.c |   12 +++++-------
>   1 files changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/hw/usb-bus.c b/hw/usb-bus.c
> index 8cafb76..8203390 100644
> --- a/hw/usb-bus.c
> +++ b/hw/usb-bus.c
> @@ -77,23 +77,21 @@ static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
>       QLIST_INIT(&dev->strings);
>       rc = usb_claim_port(dev);
>       if (rc != 0) {
> -        goto err;
> +        return rc;
>       }
>       rc = dev->info->init(dev);
>       if (rc != 0) {
> -        goto err;
> +        usb_release_port(dev);
> +        return rc;
>       }
>       if (dev->auto_attach) {
>           rc = usb_device_attach(dev);
>           if (rc != 0) {
> -            goto err;
> +            usb_qdev_exit(qdev);
> +            return rc;
>           }
>       }
>       return 0;
> -
> -err:
> -    usb_qdev_exit(qdev);
> -    return rc;
>   }
>
>   static int usb_qdev_exit(DeviceState *qdev)

      reply	other threads:[~2011-12-15 18:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-15 10:05 [Qemu-devel] [PATCH] usb: fix usb_qdev_init() error handling again Stefan Hajnoczi
2011-12-15 18:11 ` Anthony Liguori [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EEA384E.5020300@redhat.com \
    --to=anthony@codemonkey.ws \
    --cc=904617@bugs.launchpad.net \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).