1
0
Fork 0

virtio: regression fixes

Fixes two issues in the latest kernel.
 
 Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
 -----BEGIN PGP SIGNATURE-----
 
 iQEcBAABAgAGBQJaMs2CAAoJECgfDbjSjVRpUIgIAKxKE1Q/kK5ySNTCmbDUE5h7
 XUtsKBqP9iwGaICVrlwcK0VZ6wq7ljwJIks9wBWRCu0AelbSm24VrbM5aZh8S6ij
 JOesH4qhTpeqeCD/IC16hTYEtg2FOElgYbnAPEOLlJihUvuJWn2xgXD6Ci2YXyKg
 waokN/7uTwB/i3tn67JZ2k5ICeaCYG4QhKzFy8cB3ktn1AcI3BD2iB/tzpzPBVQM
 SIh+OYytc4MUnDKaa5s6wVHfnBLuxn9j98K6NwTXZbyHsIcw5sFKid/2y2B0u2BE
 WUy4tYPJbzUGnQliuTKk2WQ1lo2XfiicgJ+BM2/7SEYJcqKFQd1j328UXID04sw=
 =yIX/
 -----END PGP SIGNATURE-----

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
hifive-unleashed-5.1
Linus Torvalds 2017-12-15 12:56:23 -08:00
commit d6e47eed05
2 changed files with 32 additions and 40 deletions

View File

@ -522,10 +522,8 @@ 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)
rc = -ENOMEM; return -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; vm_dev->vdev.dev.release = virtio_mmio_release_dev;
@ -535,17 +533,14 @@ static int virtio_mmio_probe(struct platform_device *pdev)
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)
rc = -EFAULT; return -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);
rc = -ENODEV; return -ENODEV;
goto unmap;
} }
/* Check device version */ /* Check device version */
@ -553,8 +548,7 @@ 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);
rc = -ENXIO; return -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);
@ -563,8 +557,7 @@ 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.
*/ */
rc = -ENODEV; return -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);
@ -590,33 +583,15 @@ static int virtio_mmio_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, vm_dev); platform_set_drvdata(pdev, vm_dev);
rc = register_virtio_device(&vm_dev->vdev); rc = register_virtio_device(&vm_dev->vdev);
if (rc) { if (rc)
iounmap(vm_dev->base);
devm_release_mem_region(&pdev->dev, mem->start,
resource_size(mem));
put_device(&vm_dev->vdev.dev); 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; 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;

View File

@ -16,24 +16,41 @@
#define unlikely(x) (__builtin_expect(!!(x), 0)) #define unlikely(x) (__builtin_expect(!!(x), 0))
#define likely(x) (__builtin_expect(!!(x), 1)) #define likely(x) (__builtin_expect(!!(x), 1))
#define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a)) #define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a))
#define SIZE_MAX (~(size_t)0)
typedef pthread_spinlock_t spinlock_t; typedef pthread_spinlock_t spinlock_t;
typedef int gfp_t; typedef int gfp_t;
static void *kmalloc(unsigned size, gfp_t gfp) #define __GFP_ZERO 0x1
{
return memalign(64, size);
}
static void *kzalloc(unsigned size, gfp_t gfp) static void *kmalloc(unsigned size, gfp_t gfp)
{ {
void *p = memalign(64, size); void *p = memalign(64, size);
if (!p) if (!p)
return p; return p;
memset(p, 0, size);
if (gfp & __GFP_ZERO)
memset(p, 0, size);
return p; return p;
} }
static inline void *kzalloc(unsigned size, gfp_t flags)
{
return kmalloc(size, flags | __GFP_ZERO);
}
static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
{
if (size != 0 && n > SIZE_MAX / size)
return NULL;
return kmalloc(n * size, flags);
}
static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
{
return kmalloc_array(n, size, flags | __GFP_ZERO);
}
static void kfree(void *p) static void kfree(void *p)
{ {
if (p) if (p)