aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-12-15 15:56:23 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-12-15 15:56:23 -0500
commitd6e47eed0501478d2b55f0f1375b3cd96d0f6535 (patch)
tree6342435a53c58470ecfa49f008c89afd1c7f2798
parentee1b43ece1533ee60b876fd75ddb20ba1ea186bb (diff)
parentc2e90800aef22e7ea14ea7560ba99993f11d3616 (diff)
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio regression fixes from Michael Tsirkin: "Fixes two issues in the latest kernel" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: virtio_mmio: fix devm cleanup ptr_ring: fix up after recent ptr_ring changes
-rw-r--r--drivers/virtio/virtio_mmio.c43
-rw-r--r--tools/virtio/ringtest/ptr_ring.c29
2 files changed, 32 insertions, 40 deletions
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index a9192fe4f345..c92131edfaba 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -522,10 +522,8 @@ static int virtio_mmio_probe(struct platform_device *pdev)
522 return -EBUSY; 522 return -EBUSY;
523 523
524 vm_dev = devm_kzalloc(&pdev->dev, sizeof(*vm_dev), GFP_KERNEL); 524 vm_dev = devm_kzalloc(&pdev->dev, sizeof(*vm_dev), GFP_KERNEL);
525 if (!vm_dev) { 525 if (!vm_dev)
526 rc = -ENOMEM; 526 return -ENOMEM;
527 goto free_mem;
528 }
529 527
530 vm_dev->vdev.dev.parent = &pdev->dev; 528 vm_dev->vdev.dev.parent = &pdev->dev;
531 vm_dev->vdev.dev.release = virtio_mmio_release_dev; 529 vm_dev->vdev.dev.release = virtio_mmio_release_dev;
@@ -535,17 +533,14 @@ static int virtio_mmio_probe(struct platform_device *pdev)
535 spin_lock_init(&vm_dev->lock); 533 spin_lock_init(&vm_dev->lock);
536 534
537 vm_dev->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); 535 vm_dev->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
538 if (vm_dev->base == NULL) { 536 if (vm_dev->base == NULL)
539 rc = -EFAULT; 537 return -EFAULT;
540 goto free_vmdev;
541 }
542 538
543 /* Check magic value */ 539 /* Check magic value */
544 magic = readl(vm_dev->base + VIRTIO_MMIO_MAGIC_VALUE); 540 magic = readl(vm_dev->base + VIRTIO_MMIO_MAGIC_VALUE);
545 if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) { 541 if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
546 dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic); 542 dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic);
547 rc = -ENODEV; 543 return -ENODEV;
548 goto unmap;
549 } 544 }
550 545
551 /* Check device version */ 546 /* Check device version */
@@ -553,8 +548,7 @@ static int virtio_mmio_probe(struct platform_device *pdev)
553 if (vm_dev->version < 1 || vm_dev->version > 2) { 548 if (vm_dev->version < 1 || vm_dev->version > 2) {
554 dev_err(&pdev->dev, "Version %ld not supported!\n", 549 dev_err(&pdev->dev, "Version %ld not supported!\n",
555 vm_dev->version); 550 vm_dev->version);
556 rc = -ENXIO; 551 return -ENXIO;
557 goto unmap;
558 } 552 }
559 553
560 vm_dev->vdev.id.device = readl(vm_dev->base + VIRTIO_MMIO_DEVICE_ID); 554 vm_dev->vdev.id.device = readl(vm_dev->base + VIRTIO_MMIO_DEVICE_ID);
@@ -563,8 +557,7 @@ static int virtio_mmio_probe(struct platform_device *pdev)
563 * virtio-mmio device with an ID 0 is a (dummy) placeholder 557 * virtio-mmio device with an ID 0 is a (dummy) placeholder
564 * with no function. End probing now with no error reported. 558 * with no function. End probing now with no error reported.
565 */ 559 */
566 rc = -ENODEV; 560 return -ENODEV;
567 goto unmap;
568 } 561 }
569 vm_dev->vdev.id.vendor = readl(vm_dev->base + VIRTIO_MMIO_VENDOR_ID); 562 vm_dev->vdev.id.vendor = readl(vm_dev->base + VIRTIO_MMIO_VENDOR_ID);
570 563
@@ -590,33 +583,15 @@ static int virtio_mmio_probe(struct platform_device *pdev)
590 platform_set_drvdata(pdev, vm_dev); 583 platform_set_drvdata(pdev, vm_dev);
591 584
592 rc = register_virtio_device(&vm_dev->vdev); 585 rc = register_virtio_device(&vm_dev->vdev);
593 if (rc) { 586 if (rc)
594 iounmap(vm_dev->base);
595 devm_release_mem_region(&pdev->dev, mem->start,
596 resource_size(mem));
597 put_device(&vm_dev->vdev.dev); 587 put_device(&vm_dev->vdev.dev);
598 } 588
599 return rc;
600unmap:
601 iounmap(vm_dev->base);
602free_mem:
603 devm_release_mem_region(&pdev->dev, mem->start,
604 resource_size(mem));
605free_vmdev:
606 devm_kfree(&pdev->dev, vm_dev);
607 return rc; 589 return rc;
608} 590}
609 591
610static int virtio_mmio_remove(struct platform_device *pdev) 592static int virtio_mmio_remove(struct platform_device *pdev)
611{ 593{
612 struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev); 594 struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev);
613 struct resource *mem;
614
615 iounmap(vm_dev->base);
616 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
617 if (mem)
618 devm_release_mem_region(&pdev->dev, mem->start,
619 resource_size(mem));
620 unregister_virtio_device(&vm_dev->vdev); 595 unregister_virtio_device(&vm_dev->vdev);
621 596
622 return 0; 597 return 0;
diff --git a/tools/virtio/ringtest/ptr_ring.c b/tools/virtio/ringtest/ptr_ring.c
index 38bb171aceba..e6e81305ef46 100644
--- a/tools/virtio/ringtest/ptr_ring.c
+++ b/tools/virtio/ringtest/ptr_ring.c
@@ -16,24 +16,41 @@
16#define unlikely(x) (__builtin_expect(!!(x), 0)) 16#define unlikely(x) (__builtin_expect(!!(x), 0))
17#define likely(x) (__builtin_expect(!!(x), 1)) 17#define likely(x) (__builtin_expect(!!(x), 1))
18#define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a)) 18#define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a))
19#define SIZE_MAX (~(size_t)0)
20
19typedef pthread_spinlock_t spinlock_t; 21typedef pthread_spinlock_t spinlock_t;
20 22
21typedef int gfp_t; 23typedef int gfp_t;
22static void *kmalloc(unsigned size, gfp_t gfp) 24#define __GFP_ZERO 0x1
23{
24 return memalign(64, size);
25}
26 25
27static void *kzalloc(unsigned size, gfp_t gfp) 26static void *kmalloc(unsigned size, gfp_t gfp)
28{ 27{
29 void *p = memalign(64, size); 28 void *p = memalign(64, size);
30 if (!p) 29 if (!p)
31 return p; 30 return p;
32 memset(p, 0, size);
33 31
32 if (gfp & __GFP_ZERO)
33 memset(p, 0, size);
34 return p; 34 return p;
35} 35}
36 36
37static inline void *kzalloc(unsigned size, gfp_t flags)
38{
39 return kmalloc(size, flags | __GFP_ZERO);
40}
41
42static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
43{
44 if (size != 0 && n > SIZE_MAX / size)
45 return NULL;
46 return kmalloc(n * size, flags);
47}
48
49static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
50{
51 return kmalloc_array(n, size, flags | __GFP_ZERO);
52}
53
37static void kfree(void *p) 54static void kfree(void *p)
38{ 55{
39 if (p) 56 if (p)