Skip to content

Commit 484f0a0

Browse files
gregkhmstsirkin
authored andcommitted
vduse: make vduse_class constant
Now that the driver core allows for struct class to be in read-only memory, we should make all 'class' structures declared at build time placing them into read-only memory, instead of having to be dynamically allocated at runtime. Cc: "Michael S. Tsirkin" <mst@redhat.com> Cc: Jason Wang <jasowang@redhat.com> Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com> Cc: Xie Yongji <xieyongji@bytedance.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Message-Id: <2023100643-tricolor-citizen-6c2d@gregkh> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Xie Yongji <xieyongji@bytedance.com> Acked-by: Jason Wang <jasowang@redhat.com>
1 parent 5ff1f51 commit 484f0a0

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

drivers/vdpa/vdpa_user/vduse_dev.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ static DEFINE_MUTEX(vduse_lock);
134134
static DEFINE_IDR(vduse_idr);
135135

136136
static dev_t vduse_major;
137-
static struct class *vduse_class;
138137
static struct cdev vduse_ctrl_cdev;
139138
static struct cdev vduse_cdev;
140139
static struct workqueue_struct *vduse_irq_wq;
@@ -1528,6 +1527,16 @@ static const struct kobj_type vq_type = {
15281527
.default_groups = vq_groups,
15291528
};
15301529

1530+
static char *vduse_devnode(const struct device *dev, umode_t *mode)
1531+
{
1532+
return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev));
1533+
}
1534+
1535+
static const struct class vduse_class = {
1536+
.name = "vduse",
1537+
.devnode = vduse_devnode,
1538+
};
1539+
15311540
static void vduse_dev_deinit_vqs(struct vduse_dev *dev)
15321541
{
15331542
int i;
@@ -1638,7 +1647,7 @@ static int vduse_destroy_dev(char *name)
16381647
mutex_unlock(&dev->lock);
16391648

16401649
vduse_dev_reset(dev);
1641-
device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
1650+
device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
16421651
idr_remove(&vduse_idr, dev->minor);
16431652
kvfree(dev->config);
16441653
vduse_dev_deinit_vqs(dev);
@@ -1805,7 +1814,7 @@ static int vduse_create_dev(struct vduse_dev_config *config,
18051814

18061815
dev->minor = ret;
18071816
dev->msg_timeout = VDUSE_MSG_DEFAULT_TIMEOUT;
1808-
dev->dev = device_create_with_groups(vduse_class, NULL,
1817+
dev->dev = device_create_with_groups(&vduse_class, NULL,
18091818
MKDEV(MAJOR(vduse_major), dev->minor),
18101819
dev, vduse_dev_groups, "%s", config->name);
18111820
if (IS_ERR(dev->dev)) {
@@ -1821,7 +1830,7 @@ static int vduse_create_dev(struct vduse_dev_config *config,
18211830

18221831
return 0;
18231832
err_vqs:
1824-
device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
1833+
device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor));
18251834
err_dev:
18261835
idr_remove(&vduse_idr, dev->minor);
18271836
err_idr:
@@ -1934,11 +1943,6 @@ static const struct file_operations vduse_ctrl_fops = {
19341943
.llseek = noop_llseek,
19351944
};
19361945

1937-
static char *vduse_devnode(const struct device *dev, umode_t *mode)
1938-
{
1939-
return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev));
1940-
}
1941-
19421946
struct vduse_mgmt_dev {
19431947
struct vdpa_mgmt_dev mgmt_dev;
19441948
struct device dev;
@@ -2082,11 +2086,9 @@ static int vduse_init(void)
20822086
int ret;
20832087
struct device *dev;
20842088

2085-
vduse_class = class_create("vduse");
2086-
if (IS_ERR(vduse_class))
2087-
return PTR_ERR(vduse_class);
2088-
2089-
vduse_class->devnode = vduse_devnode;
2089+
ret = class_register(&vduse_class);
2090+
if (ret)
2091+
return ret;
20902092

20912093
ret = alloc_chrdev_region(&vduse_major, 0, VDUSE_DEV_MAX, "vduse");
20922094
if (ret)
@@ -2099,7 +2101,7 @@ static int vduse_init(void)
20992101
if (ret)
21002102
goto err_ctrl_cdev;
21012103

2102-
dev = device_create(vduse_class, NULL, vduse_major, NULL, "control");
2104+
dev = device_create(&vduse_class, NULL, vduse_major, NULL, "control");
21032105
if (IS_ERR(dev)) {
21042106
ret = PTR_ERR(dev);
21052107
goto err_device;
@@ -2141,13 +2143,13 @@ static int vduse_init(void)
21412143
err_wq:
21422144
cdev_del(&vduse_cdev);
21432145
err_cdev:
2144-
device_destroy(vduse_class, vduse_major);
2146+
device_destroy(&vduse_class, vduse_major);
21452147
err_device:
21462148
cdev_del(&vduse_ctrl_cdev);
21472149
err_ctrl_cdev:
21482150
unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX);
21492151
err_chardev_region:
2150-
class_destroy(vduse_class);
2152+
class_unregister(&vduse_class);
21512153
return ret;
21522154
}
21532155
module_init(vduse_init);
@@ -2159,10 +2161,10 @@ static void vduse_exit(void)
21592161
destroy_workqueue(vduse_irq_bound_wq);
21602162
destroy_workqueue(vduse_irq_wq);
21612163
cdev_del(&vduse_cdev);
2162-
device_destroy(vduse_class, vduse_major);
2164+
device_destroy(&vduse_class, vduse_major);
21632165
cdev_del(&vduse_ctrl_cdev);
21642166
unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX);
2165-
class_destroy(vduse_class);
2167+
class_unregister(&vduse_class);
21662168
}
21672169
module_exit(vduse_exit);
21682170

0 commit comments

Comments
 (0)