}
EXPORT_SYMBOL(mdev_parent_dev);
+/*
+ * Return the index in supported_type_groups that this mdev_device was created
+ * from.
+ */
+unsigned int mdev_get_type_group_id(struct mdev_device *mdev)
+{
+ return mdev->type->type_group_id;
+}
+EXPORT_SYMBOL(mdev_get_type_group_id);
+
+/*
+ * Used in mdev_type_attribute sysfs functions to return the index in the
+ * supported_type_groups that the sysfs is called from.
+ */
+unsigned int mtype_get_type_group_id(struct kobject *mtype_kobj)
+{
+ return container_of(mtype_kobj, struct mdev_type, kobj)->type_group_id;
+}
+EXPORT_SYMBOL(mtype_get_type_group_id);
+
/* Should be called holding parent_list_lock */
static struct mdev_parent *__find_parent_device(struct device *dev)
{
};
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) {
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),
ret = -ENOMEM;
goto attrs_failed;
}
-
- type->group = group;
return type;
attrs_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);
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;
return mdev->iommu_device;
}
+unsigned int mdev_get_type_group_id(struct mdev_device *mdev);
+unsigned int mtype_get_type_group_id(struct kobject *mtype_kobj);
+
/**
* struct mdev_parent_ops - Structure to be registered for each parent device to
* register the device to mdev module.