提交 0dd1b7fc 编写于 作者: J Jason Gunthorpe 提交者: Alex Williamson

vfio/mtty: Delete mdev_devices_list

Dan points out that an error case left things on this list. It is also
missing locking in available_instances_show().

Further study shows the list isn't needed at all, just store the total
ports in use in an atomic and delete the whole thing.
Reported-by: NDan Carpenter <dan.carpenter@oracle.com>
Fixes: 09177ac9 ("vfio/mtty: Convert to use vfio_register_group_dev()")
Signed-off-by: NJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/0-v1-0bc56b362ca7+62-mtty_used_ports_jgg@nvidia.comReviewed-by: NCornelia Huck <cohuck@redhat.com>
Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
上级 742b4c0d
...@@ -144,8 +144,7 @@ struct mdev_state { ...@@ -144,8 +144,7 @@ struct mdev_state {
int nr_ports; int nr_ports;
}; };
static struct mutex mdev_list_lock; static atomic_t mdev_used_ports;
static struct list_head mdev_devices_list;
static const struct file_operations vd_fops = { static const struct file_operations vd_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
...@@ -733,15 +732,13 @@ static int mtty_probe(struct mdev_device *mdev) ...@@ -733,15 +732,13 @@ static int mtty_probe(struct mdev_device *mdev)
mtty_create_config_space(mdev_state); mtty_create_config_space(mdev_state);
mutex_lock(&mdev_list_lock);
list_add(&mdev_state->next, &mdev_devices_list);
mutex_unlock(&mdev_list_lock);
ret = vfio_register_group_dev(&mdev_state->vdev); ret = vfio_register_group_dev(&mdev_state->vdev);
if (ret) { if (ret) {
kfree(mdev_state); kfree(mdev_state);
return ret; return ret;
} }
atomic_add(mdev_state->nr_ports, &mdev_used_ports);
dev_set_drvdata(&mdev->dev, mdev_state); dev_set_drvdata(&mdev->dev, mdev_state);
return 0; return 0;
} }
...@@ -750,10 +747,8 @@ static void mtty_remove(struct mdev_device *mdev) ...@@ -750,10 +747,8 @@ static void mtty_remove(struct mdev_device *mdev)
{ {
struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev); struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev);
atomic_sub(mdev_state->nr_ports, &mdev_used_ports);
vfio_unregister_group_dev(&mdev_state->vdev); vfio_unregister_group_dev(&mdev_state->vdev);
mutex_lock(&mdev_list_lock);
list_del(&mdev_state->next);
mutex_unlock(&mdev_list_lock);
kfree(mdev_state->vconfig); kfree(mdev_state->vconfig);
kfree(mdev_state); kfree(mdev_state);
...@@ -1274,14 +1269,10 @@ static ssize_t available_instances_show(struct mdev_type *mtype, ...@@ -1274,14 +1269,10 @@ static ssize_t available_instances_show(struct mdev_type *mtype,
struct mdev_type_attribute *attr, struct mdev_type_attribute *attr,
char *buf) char *buf)
{ {
struct mdev_state *mds;
unsigned int ports = mtype_get_type_group_id(mtype) + 1; unsigned int ports = mtype_get_type_group_id(mtype) + 1;
int used = 0;
list_for_each_entry(mds, &mdev_devices_list, next) return sprintf(buf, "%d\n",
used += mds->nr_ports; (MAX_MTTYS - atomic_read(&mdev_used_ports)) / ports);
return sprintf(buf, "%d\n", (MAX_MTTYS - used)/ports);
} }
static MDEV_TYPE_ATTR_RO(available_instances); static MDEV_TYPE_ATTR_RO(available_instances);
...@@ -1395,9 +1386,6 @@ static int __init mtty_dev_init(void) ...@@ -1395,9 +1386,6 @@ static int __init mtty_dev_init(void)
ret = mdev_register_device(&mtty_dev.dev, &mdev_fops); ret = mdev_register_device(&mtty_dev.dev, &mdev_fops);
if (ret) if (ret)
goto err_device; goto err_device;
mutex_init(&mdev_list_lock);
INIT_LIST_HEAD(&mdev_devices_list);
return 0; return 0;
err_device: err_device:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册