Skip to content

Commit f6c086e

Browse files
committed
misc: phantom: make phantom_class constant
Now that the driver core allows for struct class to be in read-only memory, we should make all 'class' structures declared at build time placing them into read-only memory, instead of having to be dynamically allocated at runtime. Cc: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Jiri Slaby <jirislaby@kernel.org> Link: https://lore.kernel.org/r/2023102434-font-feast-98e3@gregkh Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 421359c commit f6c086e

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

drivers/misc/phantom.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@
3535
#define PHB_NOT_OH 2
3636

3737
static DEFINE_MUTEX(phantom_mutex);
38-
static struct class *phantom_class;
3938
static int phantom_major;
4039

40+
static const struct class phantom_class = {
41+
.name = "phantom",
42+
};
43+
4144
struct phantom_device {
4245
unsigned int opened;
4346
void __iomem *caddr;
@@ -403,7 +406,7 @@ static int phantom_probe(struct pci_dev *pdev,
403406
goto err_irq;
404407
}
405408

406-
if (IS_ERR(device_create(phantom_class, &pdev->dev,
409+
if (IS_ERR(device_create(&phantom_class, &pdev->dev,
407410
MKDEV(phantom_major, minor), NULL,
408411
"phantom%u", minor)))
409412
dev_err(&pdev->dev, "can't create device\n");
@@ -436,7 +439,7 @@ static void phantom_remove(struct pci_dev *pdev)
436439
struct phantom_device *pht = pci_get_drvdata(pdev);
437440
unsigned int minor = MINOR(pht->cdev.dev);
438441

439-
device_destroy(phantom_class, MKDEV(phantom_major, minor));
442+
device_destroy(&phantom_class, MKDEV(phantom_major, minor));
440443

441444
cdev_del(&pht->cdev);
442445

@@ -503,13 +506,12 @@ static int __init phantom_init(void)
503506
int retval;
504507
dev_t dev;
505508

506-
phantom_class = class_create("phantom");
507-
if (IS_ERR(phantom_class)) {
508-
retval = PTR_ERR(phantom_class);
509+
retval = class_register(&phantom_class);
510+
if (retval) {
509511
printk(KERN_ERR "phantom: can't register phantom class\n");
510512
goto err;
511513
}
512-
retval = class_create_file(phantom_class, &class_attr_version.attr);
514+
retval = class_create_file(&phantom_class, &class_attr_version.attr);
513515
if (retval) {
514516
printk(KERN_ERR "phantom: can't create sysfs version file\n");
515517
goto err_class;
@@ -535,9 +537,9 @@ static int __init phantom_init(void)
535537
err_unchr:
536538
unregister_chrdev_region(dev, PHANTOM_MAX_MINORS);
537539
err_attr:
538-
class_remove_file(phantom_class, &class_attr_version.attr);
540+
class_remove_file(&phantom_class, &class_attr_version.attr);
539541
err_class:
540-
class_destroy(phantom_class);
542+
class_unregister(&phantom_class);
541543
err:
542544
return retval;
543545
}
@@ -548,8 +550,8 @@ static void __exit phantom_exit(void)
548550

549551
unregister_chrdev_region(MKDEV(phantom_major, 0), PHANTOM_MAX_MINORS);
550552

551-
class_remove_file(phantom_class, &class_attr_version.attr);
552-
class_destroy(phantom_class);
553+
class_remove_file(&phantom_class, &class_attr_version.attr);
554+
class_unregister(&phantom_class);
553555

554556
pr_debug("phantom: module successfully removed\n");
555557
}

0 commit comments

Comments
 (0)