]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools, 9p: Fix init error handling
authorPekka Enberg <penberg@kernel.org>
Thu, 28 Jul 2011 16:10:24 +0000 (19:10 +0300)
committerPekka Enberg <penberg@kernel.org>
Thu, 28 Jul 2011 16:10:24 +0000 (19:10 +0300)
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/builtin-run.c
tools/kvm/include/kvm/virtio-9p.h
tools/kvm/virtio/9p.c

index 941129c52c0ffcaad3ed5173966d67788bb18c60..02c066bc43e314700563a5fdc70bac9ce2ea9b94 100644 (file)
@@ -129,9 +129,10 @@ static int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, i
                *tag_name = '\0';
                tag_name++;
        }
-       if (realpath(arg, tmp))
-               virtio_9p__init(kvm, tmp, tag_name);
-       else
+       if (realpath(arg, tmp)) {
+               if (virtio_9p__init(kvm, tmp, tag_name) < 0)
+                       die("Unable to initialize virtio 9p");
+       } else
                die("Failed resolving 9p path");
        return 0;
 }
index b9c10de57997332084eacd35a0a38622b0dbedab..8584f49a92ac5aae3f210ac5ce61cccd727dceb0 100644 (file)
@@ -15,7 +15,6 @@
 #define VIRTIO_P9_VERSION      "9P2000"
 #define MAX_TAG_LEN            32
 
-
 struct p9_msg {
        u32                     size;
        u8                      cmd;
@@ -67,7 +66,8 @@ struct p9_pdu {
 
 struct kvm;
 
-void virtio_9p__init(struct kvm *kvm, const char *root, const char *tag_name);
+int virtio_9p__init(struct kvm *kvm, const char *root, const char *tag_name);
 int virtio_p9_pdu_readf(struct p9_pdu *pdu, const char *fmt, ...);
 int virtio_p9_pdu_writef(struct p9_pdu *pdu, const char *fmt, ...);
+
 #endif
index a2fe5ca870d77015f2e3fd1094146705ac0e323a..3b5555c64dc2d24ce6aa988d256aa2181cbea7a2 100644 (file)
@@ -773,21 +773,26 @@ static struct ioport_operations virtio_p9_io_ops = {
        .io_out                         = virtio_p9_pci_io_out,
 };
 
-void virtio_9p__init(struct kvm *kvm, const char *root, const char *tag_name)
+int virtio_9p__init(struct kvm *kvm, const char *root, const char *tag_name)
 {
+       struct p9_dev *p9dev;
        u8 pin, line, dev;
-       u32 i, root_len;
        u16 p9_base_addr;
-       struct p9_dev *p9dev;
+       u32 i, root_len;
+       int err = 0;
 
        p9dev = calloc(1, sizeof(*p9dev));
        if (!p9dev)
-               return;
+               return -ENOMEM;
+
        if (!tag_name)
                tag_name = VIRTIO_P9_DEFAULT_TAG;
+
        p9dev->config = calloc(1, sizeof(*p9dev->config) + strlen(tag_name) + 1);
-       if (p9dev->config == NULL)
+       if (p9dev->config == NULL) {
+               err = -ENOMEM;
                goto free_p9dev;
+       }
 
        strcpy(p9dev->root_dir, root);
        root_len = strlen(root);
@@ -800,19 +805,22 @@ void virtio_9p__init(struct kvm *kvm, const char *root, const char *tag_name)
                p9dev->fids[i].path = p9dev->fids[i].abs_path + root_len;
        }
        p9dev->config->tag_len = strlen(tag_name);
-       if (p9dev->config->tag_len > MAX_TAG_LEN)
+       if (p9dev->config->tag_len > MAX_TAG_LEN) {
+               err = -EINVAL;
                goto free_p9dev_config;
+       }
 
        memcpy(p9dev->config->tag, tag_name, strlen(tag_name));
        p9dev->features |= 1 << VIRTIO_9P_MOUNT_TAG;
 
-       if (irq__register_device(VIRTIO_ID_9P, &dev, &pin, &line) < 0)
+       err = irq__register_device(VIRTIO_ID_9P, &dev, &pin, &line);
+       if (err < 0)
                goto free_p9dev_config;
 
-       p9_base_addr                    = ioport__register(IOPORT_EMPTY,
-                                                          &virtio_p9_io_ops,
-                                                          IOPORT_SIZE, p9dev);
-       p9dev->base_addr                    = p9_base_addr;
+       p9_base_addr = ioport__register(IOPORT_EMPTY, &virtio_p9_io_ops, IOPORT_SIZE, p9dev);
+
+       p9dev->base_addr = p9_base_addr;
+
        p9dev->pci_hdr = (struct pci_device_header) {
                .vendor_id              = PCI_VENDOR_ID_REDHAT_QUMRANET,
                .device_id              = PCI_DEVICE_ID_VIRTIO_P9,
@@ -827,9 +835,11 @@ void virtio_9p__init(struct kvm *kvm, const char *root, const char *tag_name)
        };
        pci__register(&p9dev->pci_hdr, dev);
 
-       return;
+       return err;
+
 free_p9dev_config:
        free(p9dev->config);
 free_p9dev:
        free(p9dev);
+       return err;
 }