Skip to content

Commit 03bcd4d

Browse files
ivanorlov2206gregkh
authored andcommitted
char: lp: make lp_class a static const structure
Now that the driver core allows for struct class to be in read-only memory, move the lp_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-12-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent bd31ef8 commit 03bcd4d

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

drivers/char/lp.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ static struct lp_struct lp_table[LP_NO];
145145
static int port_num[LP_NO];
146146

147147
static unsigned int lp_count = 0;
148-
static struct class *lp_class;
148+
static const struct class lp_class = {
149+
.name = "printer",
150+
};
149151

150152
#ifdef CONFIG_LP_CONSOLE
151153
static struct parport *console_registered;
@@ -932,7 +934,7 @@ static int lp_register(int nr, struct parport *port)
932934
if (reset)
933935
lp_reset(nr);
934936

935-
device_create(lp_class, port->dev, MKDEV(LP_MAJOR, nr), NULL,
937+
device_create(&lp_class, port->dev, MKDEV(LP_MAJOR, nr), NULL,
936938
"lp%d", nr);
937939

938940
printk(KERN_INFO "lp%d: using %s (%s).\n", nr, port->name,
@@ -1004,7 +1006,7 @@ static void lp_detach(struct parport *port)
10041006
if (port_num[n] == port->number) {
10051007
port_num[n] = -1;
10061008
lp_count--;
1007-
device_destroy(lp_class, MKDEV(LP_MAJOR, n));
1009+
device_destroy(&lp_class, MKDEV(LP_MAJOR, n));
10081010
parport_unregister_device(lp_table[n].dev);
10091011
}
10101012
}
@@ -1049,11 +1051,9 @@ static int __init lp_init(void)
10491051
return -EIO;
10501052
}
10511053

1052-
lp_class = class_create("printer");
1053-
if (IS_ERR(lp_class)) {
1054-
err = PTR_ERR(lp_class);
1054+
err = class_register(&lp_class);
1055+
if (err)
10551056
goto out_reg;
1056-
}
10571057

10581058
if (parport_register_driver(&lp_driver)) {
10591059
printk(KERN_ERR "lp: unable to register with parport\n");
@@ -1072,7 +1072,7 @@ static int __init lp_init(void)
10721072
return 0;
10731073

10741074
out_class:
1075-
class_destroy(lp_class);
1075+
class_unregister(&lp_class);
10761076
out_reg:
10771077
unregister_chrdev(LP_MAJOR, "lp");
10781078
return err;
@@ -1115,7 +1115,7 @@ static void lp_cleanup_module(void)
11151115
#endif
11161116

11171117
unregister_chrdev(LP_MAJOR, "lp");
1118-
class_destroy(lp_class);
1118+
class_unregister(&lp_class);
11191119
}
11201120

11211121
__setup("lp=", lp_setup);

0 commit comments

Comments
 (0)