mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-09-04 20:51:28 +00:00
kvm tools, 9p: Fix init error handling
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>
This commit is contained in:
committed by
Will Deacon
parent
70f44c742f
commit
54f6802dee
+4
-3
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
+23
-13
@@ -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)
|
||||
{
|
||||
u8 pin, line, dev;
|
||||
u32 i, root_len;
|
||||
u16 p9_base_addr;
|
||||
struct p9_dev *p9dev;
|
||||
u8 pin, line, dev;
|
||||
u16 p9_base_addr;
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user