vfio/mdev: Remove mdev_parent_ops dev_attr_groups

This is only used by one sample to print a fixed string that is pointless.

In general, having a device driver attach sysfs attributes to the parent
is horrific. This should never happen, and always leads to some kind of
liftime bug as it become very difficult for the sysfs attribute to go back
to any data owned by the device driver.

Remove the general mechanism to create this abuse.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Zhi Wang <zhi.a.wang@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20220411141403.86980-32-hch@lst.de
Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com>
Reviewed-by: Zhi Wang <zhi.a.wang@intel.com>
This commit is contained in:
Jason Gunthorpe 2022-04-11 16:14:00 +02:00 committed by Zhi Wang
parent 6c7f98b334
commit e6486939d8
3 changed files with 3 additions and 41 deletions

View File

@ -197,7 +197,6 @@ void parent_remove_sysfs_files(struct mdev_parent *parent)
remove_mdev_supported_type(type); remove_mdev_supported_type(type);
} }
sysfs_remove_groups(&parent->dev->kobj, parent->ops->dev_attr_groups);
kset_unregister(parent->mdev_types_kset); kset_unregister(parent->mdev_types_kset);
} }
@ -213,17 +212,10 @@ int parent_create_sysfs_files(struct mdev_parent *parent)
INIT_LIST_HEAD(&parent->type_list); INIT_LIST_HEAD(&parent->type_list);
ret = sysfs_create_groups(&parent->dev->kobj,
parent->ops->dev_attr_groups);
if (ret)
goto create_err;
ret = add_mdev_supported_type_groups(parent); ret = add_mdev_supported_type_groups(parent);
if (ret) if (ret)
sysfs_remove_groups(&parent->dev->kobj, goto create_err;
parent->ops->dev_attr_groups); return 0;
else
return ret;
create_err: create_err:
kset_unregister(parent->mdev_types_kset); kset_unregister(parent->mdev_types_kset);

View File

@ -36,7 +36,6 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype);
* *
* @owner: The module owner. * @owner: The module owner.
* @device_driver: Which device driver to probe() on newly created devices * @device_driver: Which device driver to probe() on newly created devices
* @dev_attr_groups: Attributes of the parent device.
* @mdev_attr_groups: Attributes of the mediated device. * @mdev_attr_groups: Attributes of the mediated device.
* @supported_type_groups: Attributes to define supported types. It is mandatory * @supported_type_groups: Attributes to define supported types. It is mandatory
* to provide supported types. * to provide supported types.
@ -47,7 +46,6 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype);
struct mdev_parent_ops { struct mdev_parent_ops {
struct module *owner; struct module *owner;
struct mdev_driver *device_driver; struct mdev_driver *device_driver;
const struct attribute_group **dev_attr_groups;
const struct attribute_group **mdev_attr_groups; const struct attribute_group **mdev_attr_groups;
struct attribute_group **supported_type_groups; struct attribute_group **supported_type_groups;
}; };

View File

@ -1207,38 +1207,11 @@ static long mtty_ioctl(struct vfio_device *vdev, unsigned int cmd,
return -ENOTTY; return -ENOTTY;
} }
static ssize_t
sample_mtty_dev_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
return sprintf(buf, "This is phy device\n");
}
static DEVICE_ATTR_RO(sample_mtty_dev);
static struct attribute *mtty_dev_attrs[] = {
&dev_attr_sample_mtty_dev.attr,
NULL,
};
static const struct attribute_group mtty_dev_group = {
.name = "mtty_dev",
.attrs = mtty_dev_attrs,
};
static const struct attribute_group *mtty_dev_groups[] = {
&mtty_dev_group,
NULL,
};
static ssize_t static ssize_t
sample_mdev_dev_show(struct device *dev, struct device_attribute *attr, sample_mdev_dev_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
if (mdev_from_dev(dev)) return sprintf(buf, "This is MDEV %s\n", dev_name(dev));
return sprintf(buf, "This is MDEV %s\n", dev_name(dev));
return sprintf(buf, "\n");
} }
static DEVICE_ATTR_RO(sample_mdev_dev); static DEVICE_ATTR_RO(sample_mdev_dev);
@ -1333,7 +1306,6 @@ static struct mdev_driver mtty_driver = {
static const struct mdev_parent_ops mdev_fops = { static const struct mdev_parent_ops mdev_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.device_driver = &mtty_driver, .device_driver = &mtty_driver,
.dev_attr_groups = mtty_dev_groups,
.supported_type_groups = mdev_type_groups, .supported_type_groups = mdev_type_groups,
}; };