Revision 5ea3c2b4

b/hw/xen_disk.c
616 616
{
617 617
    struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
618 618
    int index, qflags, have_barriers, info = 0;
619
    char *h;
620 619

  
621 620
    /* read xenstore entries */
622 621
    if (blkdev->params == NULL) {
622
        char *h = NULL;
623 623
        blkdev->params = xenstore_read_be_str(&blkdev->xendev, "params");
624
        h = strchr(blkdev->params, ':');
624
        if (blkdev->params != NULL) {
625
            h = strchr(blkdev->params, ':');
626
        }
625 627
        if (h != NULL) {
626 628
            blkdev->fileproto = blkdev->params;
627 629
            blkdev->filename  = h+1;
......
649 651
        blkdev->mode == NULL   ||
650 652
        blkdev->type == NULL   ||
651 653
        blkdev->dev == NULL) {
652
        return -1;
654
        goto out_error;
653 655
    }
654 656

  
655 657
    /* read-only ? */
......
672 674
        /* setup via xenbus -> create new block driver instance */
673 675
        xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
674 676
        blkdev->bs = bdrv_new(blkdev->dev);
675
        if (bdrv_open(blkdev->bs, blkdev->filename, qflags,
676
                      bdrv_find_whitelisted_format(blkdev->fileproto)) != 0) {
677
            bdrv_delete(blkdev->bs);
678
            return -1;
677
        if (blkdev->bs) {
678
            if (bdrv_open(blkdev->bs, blkdev->filename, qflags,
679
                        bdrv_find_whitelisted_format(blkdev->fileproto)) != 0) {
680
                bdrv_delete(blkdev->bs);
681
                blkdev->bs = NULL;
682
            }
683
        }
684
        if (!blkdev->bs) {
685
            goto out_error;
679 686
        }
680 687
    } else {
681 688
        /* setup via qemu cmdline -> already setup for us */
......
704 711
    xenstore_write_be_int(&blkdev->xendev, "sectors",
705 712
                          blkdev->file_size / blkdev->file_blk);
706 713
    return 0;
714

  
715
out_error:
716
    qemu_free(blkdev->params);
717
    blkdev->params = NULL;
718
    qemu_free(blkdev->mode);
719
    blkdev->mode = NULL;
720
    qemu_free(blkdev->type);
721
    blkdev->type = NULL;
722
    qemu_free(blkdev->dev);
723
    blkdev->dev = NULL;
724
    qemu_free(blkdev->devtype);
725
    blkdev->devtype = NULL;
726
    return -1;
707 727
}
708 728

  
709 729
static int blk_connect(struct XenDevice *xendev)

Also available in: Unified diff