Merge tag 'vfio-v5.15-rc1' of git://github.com/awilliam/linux-vfio
[sfrench/cifs-2.6.git] / samples / vfio-mdev / mdpy.c
index 393c9df6f6a01006b10029ba5cd4013026177128..8d1a80a0722aa9bc544e490e7b5949c863783ebb 100644 (file)
@@ -235,17 +235,16 @@ static int mdpy_probe(struct mdev_device *mdev)
 
        mdev_state->vconfig = kzalloc(MDPY_CONFIG_SPACE_SIZE, GFP_KERNEL);
        if (mdev_state->vconfig == NULL) {
-               kfree(mdev_state);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto err_state;
        }
 
        fbsize = roundup_pow_of_two(type->width * type->height * type->bytepp);
 
        mdev_state->memblk = vmalloc_user(fbsize);
        if (!mdev_state->memblk) {
-               kfree(mdev_state->vconfig);
-               kfree(mdev_state);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto err_vconfig;
        }
        dev_info(dev, "%s: %s (%dx%d)\n", __func__, type->name, type->width,
                 type->height);
@@ -260,13 +259,18 @@ static int mdpy_probe(struct mdev_device *mdev)
        mdpy_count++;
 
        ret = vfio_register_group_dev(&mdev_state->vdev);
-       if (ret) {
-               kfree(mdev_state->vconfig);
-               kfree(mdev_state);
-               return ret;
-       }
+       if (ret)
+               goto err_mem;
        dev_set_drvdata(&mdev->dev, mdev_state);
        return 0;
+err_mem:
+       vfree(mdev_state->memblk);
+err_vconfig:
+       kfree(mdev_state->vconfig);
+err_state:
+       vfio_uninit_group_dev(&mdev_state->vdev);
+       kfree(mdev_state);
+       return ret;
 }
 
 static void mdpy_remove(struct mdev_device *mdev)
@@ -278,6 +282,7 @@ static void mdpy_remove(struct mdev_device *mdev)
        vfio_unregister_group_dev(&mdev_state->vdev);
        vfree(mdev_state->memblk);
        kfree(mdev_state->vconfig);
+       vfio_uninit_group_dev(&mdev_state->vdev);
        kfree(mdev_state);
 
        mdpy_count--;
@@ -609,19 +614,6 @@ static long mdpy_ioctl(struct vfio_device *vdev, unsigned int cmd,
        return -ENOTTY;
 }
 
-static int mdpy_open(struct vfio_device *vdev)
-{
-       if (!try_module_get(THIS_MODULE))
-               return -ENODEV;
-
-       return 0;
-}
-
-static void mdpy_close(struct vfio_device *vdev)
-{
-       module_put(THIS_MODULE);
-}
-
 static ssize_t
 resolution_show(struct device *dev, struct device_attribute *attr,
                char *buf)
@@ -716,8 +708,6 @@ static struct attribute_group *mdev_type_groups[] = {
 };
 
 static const struct vfio_device_ops mdpy_dev_ops = {
-       .open = mdpy_open,
-       .release = mdpy_close,
        .read = mdpy_read,
        .write = mdpy_write,
        .ioctl = mdpy_ioctl,