Skip to content

Commit 12fbd67

Browse files
rbmarlierekuba-moo
authored andcommitted
isdn: capi: make capi_class constant
Since commit 43a7206 ("driver core: class: make class_register() take a const *"), the driver core allows for struct class to be in read-only memory, so move the capi_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time. Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://lore.kernel.org/r/20240305-class_cleanup-isdn-v1-2-6f0edca75b61@marliere.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 479b4bc commit 12fbd67

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

drivers/isdn/capi/capi.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ MODULE_LICENSE("GPL");
4949
/* -------- driver information -------------------------------------- */
5050

5151
static DEFINE_MUTEX(capi_mutex);
52-
static struct class *capi_class;
52+
static const struct class capi_class = {
53+
.name = "capi",
54+
};
5355
static int capi_major = 68; /* allocated */
5456

5557
module_param_named(major, capi_major, uint, 0);
@@ -1393,18 +1395,19 @@ static int __init capi_init(void)
13931395
kcapi_exit();
13941396
return major_ret;
13951397
}
1396-
capi_class = class_create("capi");
1397-
if (IS_ERR(capi_class)) {
1398+
1399+
ret = class_register(&capi_class);
1400+
if (ret) {
13981401
unregister_chrdev(capi_major, "capi20");
13991402
kcapi_exit();
1400-
return PTR_ERR(capi_class);
1403+
return ret;
14011404
}
14021405

1403-
device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi20");
1406+
device_create(&capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi20");
14041407

14051408
if (capinc_tty_init() < 0) {
1406-
device_destroy(capi_class, MKDEV(capi_major, 0));
1407-
class_destroy(capi_class);
1409+
device_destroy(&capi_class, MKDEV(capi_major, 0));
1410+
class_unregister(&capi_class);
14081411
unregister_chrdev(capi_major, "capi20");
14091412
kcapi_exit();
14101413
return -ENOMEM;
@@ -1427,8 +1430,8 @@ static void __exit capi_exit(void)
14271430
{
14281431
proc_exit();
14291432

1430-
device_destroy(capi_class, MKDEV(capi_major, 0));
1431-
class_destroy(capi_class);
1433+
device_destroy(&capi_class, MKDEV(capi_major, 0));
1434+
class_unregister(&capi_class);
14321435
unregister_chrdev(capi_major, "capi20");
14331436

14341437
capinc_tty_exit();

0 commit comments

Comments
 (0)