Skip to content

Commit e55ce9f

Browse files
ivanorlov2206gregkh
authored andcommitted
bsr: make bsr_class a static const structure
Now that the driver core allows for struct class to be in read-only memory, move the bsr_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time. Cc: Arnd Bergmann <arnd@arndb.de> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com> Link: https://lore.kernel.org/r/20230620143751.578239-10-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 02fa4bc commit e55ce9f

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

drivers/char/bsr.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ struct bsr_dev {
6161

6262
static unsigned total_bsr_devs;
6363
static LIST_HEAD(bsr_devs);
64-
static struct class *bsr_class;
6564
static int bsr_major;
6665

6766
enum {
@@ -108,6 +107,11 @@ static struct attribute *bsr_dev_attrs[] = {
108107
};
109108
ATTRIBUTE_GROUPS(bsr_dev);
110109

110+
static const struct class bsr_class = {
111+
.name = "bsr",
112+
.dev_groups = bsr_dev_groups,
113+
};
114+
111115
static int bsr_mmap(struct file *filp, struct vm_area_struct *vma)
112116
{
113117
unsigned long size = vma->vm_end - vma->vm_start;
@@ -244,7 +248,7 @@ static int bsr_add_node(struct device_node *bn)
244248
goto out_err;
245249
}
246250

247-
cur->bsr_device = device_create(bsr_class, NULL, cur->bsr_dev,
251+
cur->bsr_device = device_create(&bsr_class, NULL, cur->bsr_dev,
248252
cur, "%s", cur->bsr_name);
249253
if (IS_ERR(cur->bsr_device)) {
250254
printk(KERN_ERR "device_create failed for %s\n",
@@ -293,13 +297,9 @@ static int __init bsr_init(void)
293297
if (!np)
294298
goto out_err;
295299

296-
bsr_class = class_create("bsr");
297-
if (IS_ERR(bsr_class)) {
298-
printk(KERN_ERR "class_create() failed for bsr_class\n");
299-
ret = PTR_ERR(bsr_class);
300+
ret = class_register(&bsr_class);
301+
if (err)
300302
goto out_err_1;
301-
}
302-
bsr_class->dev_groups = bsr_dev_groups;
303303

304304
ret = alloc_chrdev_region(&bsr_dev, 0, BSR_MAX_DEVS, "bsr");
305305
bsr_major = MAJOR(bsr_dev);
@@ -320,7 +320,7 @@ static int __init bsr_init(void)
320320
unregister_chrdev_region(bsr_dev, BSR_MAX_DEVS);
321321

322322
out_err_2:
323-
class_destroy(bsr_class);
323+
class_unregister(&bsr_class);
324324

325325
out_err_1:
326326
of_node_put(np);
@@ -335,8 +335,7 @@ static void __exit bsr_exit(void)
335335

336336
bsr_cleanup_devs();
337337

338-
if (bsr_class)
339-
class_destroy(bsr_class);
338+
class_unregister(&bsr_class);
340339

341340
if (bsr_major)
342341
unregister_chrdev_region(MKDEV(bsr_major, 0), BSR_MAX_DEVS);

0 commit comments

Comments
 (0)