Skip to content

Commit 7671284

Browse files
ivanorlov2206gregkh
authored andcommitted
/dev/mem: make mem_class a static const structure
Now that the driver core allows for struct class to be in read-only memory, move the mem_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at load 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-13-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 03bcd4d commit 7671284

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

drivers/char/mem.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,20 +753,23 @@ static char *mem_devnode(const struct device *dev, umode_t *mode)
753753
return NULL;
754754
}
755755

756-
static struct class *mem_class;
756+
static const struct class mem_class = {
757+
.name = "mem",
758+
.devnode = mem_devnode,
759+
};
757760

758761
static int __init chr_dev_init(void)
759762
{
763+
int retval;
760764
int minor;
761765

762766
if (register_chrdev(MEM_MAJOR, "mem", &memory_fops))
763767
printk("unable to get major %d for memory devs\n", MEM_MAJOR);
764768

765-
mem_class = class_create("mem");
766-
if (IS_ERR(mem_class))
767-
return PTR_ERR(mem_class);
769+
retval = class_register(&mem_class);
770+
if (retval)
771+
return retval;
768772

769-
mem_class->devnode = mem_devnode;
770773
for (minor = 1; minor < ARRAY_SIZE(devlist); minor++) {
771774
if (!devlist[minor].name)
772775
continue;
@@ -777,7 +780,7 @@ static int __init chr_dev_init(void)
777780
if ((minor == DEVPORT_MINOR) && !arch_has_dev_port())
778781
continue;
779782

780-
device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
783+
device_create(&mem_class, NULL, MKDEV(MEM_MAJOR, minor),
781784
NULL, devlist[minor].name);
782785
}
783786

0 commit comments

Comments
 (0)