Skip to content

Commit 9ee202e

Browse files
ivanorlov2206gregkh
authored andcommitted
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>
1 parent 936cb49 commit 9ee202e

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

drivers/char/xillybus/xillybus_class.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ MODULE_LICENSE("GPL v2");
2323

2424
static DEFINE_MUTEX(unit_mutex);
2525
static LIST_HEAD(unit_list);
26-
static struct class *xillybus_class;
26+
static const struct class xillybus_class = {
27+
.name = "xillybus",
28+
};
2729

2830
#define UNITNAMELEN 16
2931

@@ -121,7 +123,7 @@ int xillybus_init_chrdev(struct device *dev,
121123
len -= namelen + 1;
122124
idt += namelen + 1;
123125

124-
device = device_create(xillybus_class,
126+
device = device_create(&xillybus_class,
125127
NULL,
126128
MKDEV(unit->major,
127129
i + unit->lowest_minor),
@@ -152,7 +154,7 @@ int xillybus_init_chrdev(struct device *dev,
152154

153155
unroll_device_create:
154156
for (i--; i >= 0; i--)
155-
device_destroy(xillybus_class, MKDEV(unit->major,
157+
device_destroy(&xillybus_class, MKDEV(unit->major,
156158
i + unit->lowest_minor));
157159

158160
cdev_del(unit->cdev);
@@ -193,7 +195,7 @@ void xillybus_cleanup_chrdev(void *private_data,
193195
for (minor = unit->lowest_minor;
194196
minor < (unit->lowest_minor + unit->num_nodes);
195197
minor++)
196-
device_destroy(xillybus_class, MKDEV(unit->major, minor));
198+
device_destroy(&xillybus_class, MKDEV(unit->major, minor));
197199

198200
cdev_del(unit->cdev);
199201

@@ -242,19 +244,12 @@ EXPORT_SYMBOL(xillybus_find_inode);
242244

243245
static int __init xillybus_class_init(void)
244246
{
245-
xillybus_class = class_create("xillybus");
246-
247-
if (IS_ERR(xillybus_class)) {
248-
pr_warn("Failed to register xillybus class\n");
249-
250-
return PTR_ERR(xillybus_class);
251-
}
252-
return 0;
247+
return class_register(&xillybus_class);
253248
}
254249

255250
static void __exit xillybus_class_exit(void)
256251
{
257-
class_destroy(xillybus_class);
252+
class_unregister(&xillybus_class);
258253
}
259254

260255
module_init(xillybus_class_init);

0 commit comments

Comments
 (0)