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
This commit is contained in:
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;
vm_dev = devm_kzalloc(&pdev->dev, sizeof(*vm_dev), GFP_KERNEL);
if (!vm_dev) {
rc = -ENOMEM;
goto free_mem;
}
if (!vm_dev)
return -ENOMEM;
vm_dev->vdev.dev.parent = &pdev->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);
vm_dev->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
if (vm_dev->base == NULL) {
rc = -EFAULT;
goto free_vmdev;
}
if (vm_dev->base == NULL)
return -EFAULT;
/* Check magic value */
magic = readl(vm_dev->base + VIRTIO_MMIO_MAGIC_VALUE);
if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic);
rc = -ENODEV;
goto unmap;
return -ENODEV;
}
/* 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) {
dev_err(&pdev->dev, "Version %ld not supported!\n",
vm_dev->version);
rc = -ENXIO;
goto unmap;
return -ENXIO;
}
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
* with no function. End probing now with no error reported.
*/
rc = -ENODEV;
goto unmap;
return -ENODEV;
}
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);
rc = register_virtio_device(&vm_dev->vdev);
if (rc) {
iounmap(vm_dev->base);
devm_release_mem_region(&pdev->dev, mem->start,
resource_size(mem));
if (rc)
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)
{
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);
return 0;

View File

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