Skip to content

Commit 98ab58a

Browse files
ivanorlov2206gregkh
authored andcommitted
ppdev: make ppdev_class a static const structure
Now that the driver core allows for struct class to be in read-only memory, move the ppdev_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: Sudip Mukherjee <sudipm.mukherjee@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> Link: https://lore.kernel.org/r/20230620143751.578239-15-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent eafd52e commit 98ab58a

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

drivers/char/ppdev.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,9 @@ static __poll_t pp_poll(struct file *file, poll_table *wait)
773773
return mask;
774774
}
775775

776-
static struct class *ppdev_class;
776+
static const struct class ppdev_class = {
777+
.name = CHRDEV,
778+
};
777779

778780
static const struct file_operations pp_fops = {
779781
.owner = THIS_MODULE,
@@ -794,7 +796,7 @@ static void pp_attach(struct parport *port)
794796
if (devices[port->number])
795797
return;
796798

797-
ret = device_create(ppdev_class, port->dev,
799+
ret = device_create(&ppdev_class, port->dev,
798800
MKDEV(PP_MAJOR, port->number), NULL,
799801
"parport%d", port->number);
800802
if (IS_ERR(ret)) {
@@ -810,7 +812,7 @@ static void pp_detach(struct parport *port)
810812
if (!devices[port->number])
811813
return;
812814

813-
device_destroy(ppdev_class, MKDEV(PP_MAJOR, port->number));
815+
device_destroy(&ppdev_class, MKDEV(PP_MAJOR, port->number));
814816
devices[port->number] = NULL;
815817
}
816818

@@ -841,11 +843,10 @@ static int __init ppdev_init(void)
841843
pr_warn(CHRDEV ": unable to get major %d\n", PP_MAJOR);
842844
return -EIO;
843845
}
844-
ppdev_class = class_create(CHRDEV);
845-
if (IS_ERR(ppdev_class)) {
846-
err = PTR_ERR(ppdev_class);
846+
err = class_register(&ppdev_class);
847+
if (err)
847848
goto out_chrdev;
848-
}
849+
849850
err = parport_register_driver(&pp_driver);
850851
if (err < 0) {
851852
pr_warn(CHRDEV ": unable to register with parport\n");
@@ -856,7 +857,7 @@ static int __init ppdev_init(void)
856857
goto out;
857858

858859
out_class:
859-
class_destroy(ppdev_class);
860+
class_unregister(&ppdev_class);
860861
out_chrdev:
861862
unregister_chrdev(PP_MAJOR, CHRDEV);
862863
out:
@@ -867,7 +868,7 @@ static void __exit ppdev_cleanup(void)
867868
{
868869
/* Clean up all parport stuff */
869870
parport_unregister_driver(&pp_driver);
870-
class_destroy(ppdev_class);
871+
class_unregister(&ppdev_class);
871872
unregister_chrdev(PP_MAJOR, CHRDEV);
872873
}
873874

0 commit comments

Comments
 (0)