Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit 33212fa

Browse files
jgunthorpezhiwang1
authored andcommitted
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 <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Zhi Wang <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected] Reviewed-by: Kirti Wankhede <[email protected]> Reviewed-by: Zhi Wang <[email protected]>
1 parent c797bb4 commit 33212fa

File tree

3 files changed

+3
-41
lines changed

3 files changed

+3
-41
lines changed

drivers/vfio/mdev/mdev_sysfs.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ void parent_remove_sysfs_files(struct mdev_parent *parent)
197197
remove_mdev_supported_type(type);
198198
}
199199

200-
sysfs_remove_groups(&parent->dev->kobj, parent->ops->dev_attr_groups);
201200
kset_unregister(parent->mdev_types_kset);
202201
}
203202

@@ -213,17 +212,10 @@ int parent_create_sysfs_files(struct mdev_parent *parent)
213212

214213
INIT_LIST_HEAD(&parent->type_list);
215214

216-
ret = sysfs_create_groups(&parent->dev->kobj,
217-
parent->ops->dev_attr_groups);
218-
if (ret)
219-
goto create_err;
220-
221215
ret = add_mdev_supported_type_groups(parent);
222216
if (ret)
223-
sysfs_remove_groups(&parent->dev->kobj,
224-
parent->ops->dev_attr_groups);
225-
else
226-
return ret;
217+
goto create_err;
218+
return 0;
227219

228220
create_err:
229221
kset_unregister(parent->mdev_types_kset);

include/linux/mdev.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype);
3636
*
3737
* @owner: The module owner.
3838
* @device_driver: Which device driver to probe() on newly created devices
39-
* @dev_attr_groups: Attributes of the parent device.
4039
* @mdev_attr_groups: Attributes of the mediated device.
4140
* @supported_type_groups: Attributes to define supported types. It is mandatory
4241
* to provide supported types.
@@ -47,7 +46,6 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype);
4746
struct mdev_parent_ops {
4847
struct module *owner;
4948
struct mdev_driver *device_driver;
50-
const struct attribute_group **dev_attr_groups;
5149
const struct attribute_group **mdev_attr_groups;
5250
struct attribute_group **supported_type_groups;
5351
};

samples/vfio-mdev/mtty.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,38 +1207,11 @@ static long mtty_ioctl(struct vfio_device *vdev, unsigned int cmd,
12071207
return -ENOTTY;
12081208
}
12091209

1210-
static ssize_t
1211-
sample_mtty_dev_show(struct device *dev, struct device_attribute *attr,
1212-
char *buf)
1213-
{
1214-
return sprintf(buf, "This is phy device\n");
1215-
}
1216-
1217-
static DEVICE_ATTR_RO(sample_mtty_dev);
1218-
1219-
static struct attribute *mtty_dev_attrs[] = {
1220-
&dev_attr_sample_mtty_dev.attr,
1221-
NULL,
1222-
};
1223-
1224-
static const struct attribute_group mtty_dev_group = {
1225-
.name = "mtty_dev",
1226-
.attrs = mtty_dev_attrs,
1227-
};
1228-
1229-
static const struct attribute_group *mtty_dev_groups[] = {
1230-
&mtty_dev_group,
1231-
NULL,
1232-
};
1233-
12341210
static ssize_t
12351211
sample_mdev_dev_show(struct device *dev, struct device_attribute *attr,
12361212
char *buf)
12371213
{
1238-
if (mdev_from_dev(dev))
1239-
return sprintf(buf, "This is MDEV %s\n", dev_name(dev));
1240-
1241-
return sprintf(buf, "\n");
1214+
return sprintf(buf, "This is MDEV %s\n", dev_name(dev));
12421215
}
12431216

12441217
static DEVICE_ATTR_RO(sample_mdev_dev);
@@ -1333,7 +1306,6 @@ static struct mdev_driver mtty_driver = {
13331306
static const struct mdev_parent_ops mdev_fops = {
13341307
.owner = THIS_MODULE,
13351308
.device_driver = &mtty_driver,
1336-
.dev_attr_groups = mtty_dev_groups,
13371309
.supported_type_groups = mdev_type_groups,
13381310
};
13391311

0 commit comments

Comments
 (0)