Commit 900add27 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost

Pull virtio bugfixes from Michael Tsirkin:
 "A couple of minor bugfixes"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
  virtio_net: fix return value check in receive_mergeable()
  virtio_mmio: add cleanup for virtio_mmio_remove
  virtio_mmio: add cleanup for virtio_mmio_probe
parents 32abeb09 03e9f8a0
...@@ -756,7 +756,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, ...@@ -756,7 +756,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
int num_skb_frags; int num_skb_frags;
buf = virtqueue_get_buf_ctx(rq->vq, &len, &ctx); buf = virtqueue_get_buf_ctx(rq->vq, &len, &ctx);
if (unlikely(!ctx)) { if (unlikely(!buf)) {
pr_debug("%s: rx error: %d buffers out of %d missing\n", pr_debug("%s: rx error: %d buffers out of %d missing\n",
dev->name, num_buf, dev->name, num_buf,
virtio16_to_cpu(vi->vdev, virtio16_to_cpu(vi->vdev,
......
...@@ -493,7 +493,16 @@ static const struct virtio_config_ops virtio_mmio_config_ops = { ...@@ -493,7 +493,16 @@ static const struct virtio_config_ops virtio_mmio_config_ops = {
}; };
static void virtio_mmio_release_dev_empty(struct device *_d) {} static void virtio_mmio_release_dev(struct device *_d)
{
struct virtio_device *vdev =
container_of(_d, struct virtio_device, dev);
struct virtio_mmio_device *vm_dev =
container_of(vdev, struct virtio_mmio_device, vdev);
struct platform_device *pdev = vm_dev->pdev;
devm_kfree(&pdev->dev, vm_dev);
}
/* Platform device */ /* Platform device */
...@@ -513,25 +522,30 @@ static int virtio_mmio_probe(struct platform_device *pdev) ...@@ -513,25 +522,30 @@ static int virtio_mmio_probe(struct platform_device *pdev)
return -EBUSY; return -EBUSY;
vm_dev = devm_kzalloc(&pdev->dev, sizeof(*vm_dev), GFP_KERNEL); vm_dev = devm_kzalloc(&pdev->dev, sizeof(*vm_dev), GFP_KERNEL);
if (!vm_dev) if (!vm_dev) {
return -ENOMEM; rc = -ENOMEM;
goto free_mem;
}
vm_dev->vdev.dev.parent = &pdev->dev; vm_dev->vdev.dev.parent = &pdev->dev;
vm_dev->vdev.dev.release = virtio_mmio_release_dev_empty; vm_dev->vdev.dev.release = virtio_mmio_release_dev;
vm_dev->vdev.config = &virtio_mmio_config_ops; vm_dev->vdev.config = &virtio_mmio_config_ops;
vm_dev->pdev = pdev; vm_dev->pdev = pdev;
INIT_LIST_HEAD(&vm_dev->virtqueues); INIT_LIST_HEAD(&vm_dev->virtqueues);
spin_lock_init(&vm_dev->lock); spin_lock_init(&vm_dev->lock);
vm_dev->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); vm_dev->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
if (vm_dev->base == NULL) if (vm_dev->base == NULL) {
return -EFAULT; rc = -EFAULT;
goto free_vmdev;
}
/* Check magic value */ /* Check magic value */
magic = readl(vm_dev->base + VIRTIO_MMIO_MAGIC_VALUE); magic = readl(vm_dev->base + VIRTIO_MMIO_MAGIC_VALUE);
if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) { if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic); dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic);
return -ENODEV; rc = -ENODEV;
goto unmap;
} }
/* Check device version */ /* Check device version */
...@@ -539,7 +553,8 @@ static int virtio_mmio_probe(struct platform_device *pdev) ...@@ -539,7 +553,8 @@ static int virtio_mmio_probe(struct platform_device *pdev)
if (vm_dev->version < 1 || vm_dev->version > 2) { if (vm_dev->version < 1 || vm_dev->version > 2) {
dev_err(&pdev->dev, "Version %ld not supported!\n", dev_err(&pdev->dev, "Version %ld not supported!\n",
vm_dev->version); vm_dev->version);
return -ENXIO; rc = -ENXIO;
goto unmap;
} }
vm_dev->vdev.id.device = readl(vm_dev->base + VIRTIO_MMIO_DEVICE_ID); vm_dev->vdev.id.device = readl(vm_dev->base + VIRTIO_MMIO_DEVICE_ID);
...@@ -548,7 +563,8 @@ static int virtio_mmio_probe(struct platform_device *pdev) ...@@ -548,7 +563,8 @@ static int virtio_mmio_probe(struct platform_device *pdev)
* virtio-mmio device with an ID 0 is a (dummy) placeholder * virtio-mmio device with an ID 0 is a (dummy) placeholder
* with no function. End probing now with no error reported. * with no function. End probing now with no error reported.
*/ */
return -ENODEV; rc = -ENODEV;
goto unmap;
} }
vm_dev->vdev.id.vendor = readl(vm_dev->base + VIRTIO_MMIO_VENDOR_ID); vm_dev->vdev.id.vendor = readl(vm_dev->base + VIRTIO_MMIO_VENDOR_ID);
...@@ -573,13 +589,34 @@ static int virtio_mmio_probe(struct platform_device *pdev) ...@@ -573,13 +589,34 @@ static int virtio_mmio_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, vm_dev); platform_set_drvdata(pdev, vm_dev);
return register_virtio_device(&vm_dev->vdev); rc = register_virtio_device(&vm_dev->vdev);
if (rc) {
iounmap(vm_dev->base);
devm_release_mem_region(&pdev->dev, mem->start,
resource_size(mem));
put_device(&vm_dev->vdev.dev);
}
return rc;
unmap:
iounmap(vm_dev->base);
free_mem:
devm_release_mem_region(&pdev->dev, mem->start,
resource_size(mem));
free_vmdev:
devm_kfree(&pdev->dev, vm_dev);
return rc;
} }
static int virtio_mmio_remove(struct platform_device *pdev) static int virtio_mmio_remove(struct platform_device *pdev)
{ {
struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev); struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev);
struct resource *mem;
iounmap(vm_dev->base);
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (mem)
devm_release_mem_region(&pdev->dev, mem->start,
resource_size(mem));
unregister_virtio_device(&vm_dev->vdev); unregister_virtio_device(&vm_dev->vdev);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment