Commit-ID: ed639676ed86d851f57b8edc46fccc80847579b6 Gitweb: http://git.kernel.org/tip/ed639676ed86d851f57b8edc46fccc80847579b6 Author: Pekka Enberg <penberg@xxxxxxxxxx> AuthorDate: Thu, 28 Jul 2011 19:10:24 +0300 Committer: Pekka Enberg <penberg@xxxxxxxxxx> CommitDate: Thu, 28 Jul 2011 19:10:24 +0300 kvm tools, 9p: Fix init error handling Cc: Aneesh Kumar K.V <aneesh.kumar@xxxxxxxxxxxxxxxxxx> Cc: Sasha Levin <levinsasha928@xxxxxxxxx> Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx> --- tools/kvm/builtin-run.c | 7 ++++--- tools/kvm/include/kvm/virtio-9p.h | 4 ++-- tools/kvm/virtio/9p.c | 34 ++++++++++++++++++++++------------ 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 941129c..02c066b 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -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; } diff --git a/tools/kvm/include/kvm/virtio-9p.h b/tools/kvm/include/kvm/virtio-9p.h index b9c10de..8584f49 100644 --- a/tools/kvm/include/kvm/virtio-9p.h +++ b/tools/kvm/include/kvm/virtio-9p.h @@ -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 diff --git a/tools/kvm/virtio/9p.c b/tools/kvm/virtio/9p.c index a2fe5ca..3b5555c 100644 --- a/tools/kvm/virtio/9p.c +++ b/tools/kvm/virtio/9p.c @@ -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; } -- To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html
![]() |