summaryrefslogtreecommitdiff
path: root/drivers/vfio/mdev/mdev_sysfs.c
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@nvidia.com>2021-04-06 16:40:34 -0300
committerAlex Williamson <alex.williamson@redhat.com>2021-04-07 15:39:18 -0600
commit15fcc44be0c7afa2945b1896a96ac2ddf09f1fa7 (patch)
treee8ecae765402f6e86b8095d43bbdf111cf2fea50 /drivers/vfio/mdev/mdev_sysfs.c
parentfbea43239074e16c91048f5ce70378664efbdb99 (diff)
vfio/mdev: Add mdev/mtype_get_type_group_id()
This returns the index in the supported_type_groups array that is associated with the mdev_type attached to the struct mdev_device or its containing struct kobject. Each mdev_device can be spawned from exactly one mdev_type, which in turn originates from exactly one supported_type_group. Drivers are using weird string calculations to try and get back to this index, providing a direct access to the index removes a bunch of wonky driver code. mdev_type->group can be deleted as the group is obtained using the type_group_id. Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Cornelia Huck <cohuck@redhat.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Message-Id: <11-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'drivers/vfio/mdev/mdev_sysfs.c')
-rw-r--r--drivers/vfio/mdev/mdev_sysfs.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
index 8c169d12ba7d..712fbc78b12e 100644
--- a/drivers/vfio/mdev/mdev_sysfs.c
+++ b/drivers/vfio/mdev/mdev_sysfs.c
@@ -92,9 +92,11 @@ static struct kobj_type mdev_type_ktype = {
};
static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent,
- struct attribute_group *group)
+ unsigned int type_group_id)
{
struct mdev_type *type;
+ struct attribute_group *group =
+ parent->ops->supported_type_groups[type_group_id];
int ret;
if (!group->name) {
@@ -110,6 +112,7 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent,
type->parent = parent;
/* Pairs with the put in mdev_type_release() */
mdev_get_parent(parent);
+ type->type_group_id = type_group_id;
ret = kobject_init_and_add(&type->kobj, &mdev_type_ktype, NULL,
"%s-%s", dev_driver_string(parent->dev),
@@ -135,8 +138,6 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent,
ret = -ENOMEM;
goto attrs_failed;
}
-
- type->group = group;
return type;
attrs_failed:
@@ -151,8 +152,11 @@ attr_create_failed:
static void remove_mdev_supported_type(struct mdev_type *type)
{
+ struct attribute_group *group =
+ type->parent->ops->supported_type_groups[type->type_group_id];
+
sysfs_remove_files(&type->kobj,
- (const struct attribute **)type->group->attrs);
+ (const struct attribute **)group->attrs);
kobject_put(type->devices_kobj);
sysfs_remove_file(&type->kobj, &mdev_type_attr_create.attr);
kobject_del(&type->kobj);
@@ -166,8 +170,7 @@ static int add_mdev_supported_type_groups(struct mdev_parent *parent)
for (i = 0; parent->ops->supported_type_groups[i]; i++) {
struct mdev_type *type;
- type = add_mdev_supported_type(parent,
- parent->ops->supported_type_groups[i]);
+ type = add_mdev_supported_type(parent, i);
if (IS_ERR(type)) {
struct mdev_type *ltype, *tmp;