diff options
author | Max Gurtovoy <mgurtovoy@nvidia.com> | 2021-05-18 22:21:32 +0300 |
---|---|---|
committer | Alex Williamson <alex.williamson@redhat.com> | 2021-06-15 23:12:15 +0300 |
commit | 9dcf01d95721261844d8c07c142efc143f7d38e3 (patch) | |
tree | 779e6b75b40ed6b96acf52fff59111ee09c37119 /drivers/vfio/vfio.c | |
parent | 009c9aa5be652675a06d5211e1640e02bbb1c33d (diff) | |
download | linux-9dcf01d95721261844d8c07c142efc143f7d38e3.tar.xz |
vfio: centralize module refcount in subsystem layer
Remove code duplication and move module refcounting to the subsystem
module.
Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Link: https://lore.kernel.org/r/20210518192133.59195-2-mgurtovoy@nvidia.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'drivers/vfio/vfio.c')
-rw-r--r-- | drivers/vfio/vfio.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 5e631c359ef2..02cc51ce6891 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1369,8 +1369,14 @@ static int vfio_group_get_device_fd(struct vfio_group *group, char *buf) if (IS_ERR(device)) return PTR_ERR(device); + if (!try_module_get(device->dev->driver->owner)) { + vfio_device_put(device); + return -ENODEV; + } + ret = device->ops->open(device); if (ret) { + module_put(device->dev->driver->owner); vfio_device_put(device); return ret; } @@ -1382,6 +1388,7 @@ static int vfio_group_get_device_fd(struct vfio_group *group, char *buf) ret = get_unused_fd_flags(O_CLOEXEC); if (ret < 0) { device->ops->release(device); + module_put(device->dev->driver->owner); vfio_device_put(device); return ret; } @@ -1392,6 +1399,7 @@ static int vfio_group_get_device_fd(struct vfio_group *group, char *buf) put_unused_fd(ret); ret = PTR_ERR(filep); device->ops->release(device); + module_put(device->dev->driver->owner); vfio_device_put(device); return ret; } @@ -1550,6 +1558,8 @@ static int vfio_device_fops_release(struct inode *inode, struct file *filep) device->ops->release(device); + module_put(device->dev->driver->owner); + vfio_group_try_dissolve_container(device->group); vfio_device_put(device); |