Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

char: xillybus: make xillybus_class a static const structure

Now that the driver core allows for struct class to be in read-only
memory, move the xillybus_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: Eli Billauer <eli.billauer@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Acked-by: Eli Billauer <eli.billauer@gmail.com>
Link: https://lore.kernel.org/r/20230620143751.578239-18-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ivan Orlov and committed by
Greg Kroah-Hartman
9ee202e6 936cb492

+8 -13
+8 -13
drivers/char/xillybus/xillybus_class.c
··· 23 23 24 24 static DEFINE_MUTEX(unit_mutex); 25 25 static LIST_HEAD(unit_list); 26 - static struct class *xillybus_class; 26 + static const struct class xillybus_class = { 27 + .name = "xillybus", 28 + }; 27 29 28 30 #define UNITNAMELEN 16 29 31 ··· 123 121 len -= namelen + 1; 124 122 idt += namelen + 1; 125 123 126 - device = device_create(xillybus_class, 124 + device = device_create(&xillybus_class, 127 125 NULL, 128 126 MKDEV(unit->major, 129 127 i + unit->lowest_minor), ··· 154 152 155 153 unroll_device_create: 156 154 for (i--; i >= 0; i--) 157 - device_destroy(xillybus_class, MKDEV(unit->major, 155 + device_destroy(&xillybus_class, MKDEV(unit->major, 158 156 i + unit->lowest_minor)); 159 157 160 158 cdev_del(unit->cdev); ··· 195 193 for (minor = unit->lowest_minor; 196 194 minor < (unit->lowest_minor + unit->num_nodes); 197 195 minor++) 198 - device_destroy(xillybus_class, MKDEV(unit->major, minor)); 196 + device_destroy(&xillybus_class, MKDEV(unit->major, minor)); 199 197 200 198 cdev_del(unit->cdev); 201 199 ··· 244 242 245 243 static int __init xillybus_class_init(void) 246 244 { 247 - xillybus_class = class_create("xillybus"); 248 - 249 - if (IS_ERR(xillybus_class)) { 250 - pr_warn("Failed to register xillybus class\n"); 251 - 252 - return PTR_ERR(xillybus_class); 253 - } 254 - return 0; 245 + return class_register(&xillybus_class); 255 246 } 256 247 257 248 static void __exit xillybus_class_exit(void) 258 249 { 259 - class_destroy(xillybus_class); 250 + class_unregister(&xillybus_class); 260 251 } 261 252 262 253 module_init(xillybus_class_init);