summaryrefslogtreecommitdiff
path: root/drivers/char
diff options
context:
space:
mode:
authorIvan Orlov <ivan.orlov0322@gmail.com>2023-06-20 17:37:55 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-06-23 11:27:13 +0300
commit7671284b6c77df93b7dad8be40fe354dd4243a5d (patch)
treeebb6c6d0a732b4e84de85f838fe3442a3af1cebd /drivers/char
parent03bcd4d8e9e6da7521b1bdff4116bfed9050cfa9 (diff)
downloadlinux-7671284b6c77df93b7dad8be40fe354dd4243a5d.tar.xz
/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>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/mem.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index f494d31f2b98..2f944522f18f 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -753,20 +753,23 @@ static char *mem_devnode(const struct device *dev, umode_t *mode)
return NULL;
}
-static struct class *mem_class;
+static const struct class mem_class = {
+ .name = "mem",
+ .devnode = mem_devnode,
+};
static int __init chr_dev_init(void)
{
+ int retval;
int minor;
if (register_chrdev(MEM_MAJOR, "mem", &memory_fops))
printk("unable to get major %d for memory devs\n", MEM_MAJOR);
- mem_class = class_create("mem");
- if (IS_ERR(mem_class))
- return PTR_ERR(mem_class);
+ retval = class_register(&mem_class);
+ if (retval)
+ return retval;
- mem_class->devnode = mem_devnode;
for (minor = 1; minor < ARRAY_SIZE(devlist); minor++) {
if (!devlist[minor].name)
continue;
@@ -777,7 +780,7 @@ static int __init chr_dev_init(void)
if ((minor == DEVPORT_MINOR) && !arch_has_dev_port())
continue;
- device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
+ device_create(&mem_class, NULL, MKDEV(MEM_MAJOR, minor),
NULL, devlist[minor].name);
}