Commit f6c086ef authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

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: default avatarJiri Slaby <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/2023102434-font-feast-98e3@gregkhSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 421359cb
...@@ -35,9 +35,12 @@ ...@@ -35,9 +35,12 @@
#define PHB_NOT_OH 2 #define PHB_NOT_OH 2
static DEFINE_MUTEX(phantom_mutex); static DEFINE_MUTEX(phantom_mutex);
static struct class *phantom_class;
static int phantom_major; static int phantom_major;
static const struct class phantom_class = {
.name = "phantom",
};
struct phantom_device { struct phantom_device {
unsigned int opened; unsigned int opened;
void __iomem *caddr; void __iomem *caddr;
...@@ -403,7 +406,7 @@ static int phantom_probe(struct pci_dev *pdev, ...@@ -403,7 +406,7 @@ static int phantom_probe(struct pci_dev *pdev,
goto err_irq; goto err_irq;
} }
if (IS_ERR(device_create(phantom_class, &pdev->dev, if (IS_ERR(device_create(&phantom_class, &pdev->dev,
MKDEV(phantom_major, minor), NULL, MKDEV(phantom_major, minor), NULL,
"phantom%u", minor))) "phantom%u", minor)))
dev_err(&pdev->dev, "can't create device\n"); dev_err(&pdev->dev, "can't create device\n");
...@@ -436,7 +439,7 @@ static void phantom_remove(struct pci_dev *pdev) ...@@ -436,7 +439,7 @@ static void phantom_remove(struct pci_dev *pdev)
struct phantom_device *pht = pci_get_drvdata(pdev); struct phantom_device *pht = pci_get_drvdata(pdev);
unsigned int minor = MINOR(pht->cdev.dev); unsigned int minor = MINOR(pht->cdev.dev);
device_destroy(phantom_class, MKDEV(phantom_major, minor)); device_destroy(&phantom_class, MKDEV(phantom_major, minor));
cdev_del(&pht->cdev); cdev_del(&pht->cdev);
...@@ -503,13 +506,12 @@ static int __init phantom_init(void) ...@@ -503,13 +506,12 @@ static int __init phantom_init(void)
int retval; int retval;
dev_t dev; dev_t dev;
phantom_class = class_create("phantom"); retval = class_register(&phantom_class);
if (IS_ERR(phantom_class)) { if (retval) {
retval = PTR_ERR(phantom_class);
printk(KERN_ERR "phantom: can't register phantom class\n"); printk(KERN_ERR "phantom: can't register phantom class\n");
goto err; goto err;
} }
retval = class_create_file(phantom_class, &class_attr_version.attr); retval = class_create_file(&phantom_class, &class_attr_version.attr);
if (retval) { if (retval) {
printk(KERN_ERR "phantom: can't create sysfs version file\n"); printk(KERN_ERR "phantom: can't create sysfs version file\n");
goto err_class; goto err_class;
...@@ -535,9 +537,9 @@ static int __init phantom_init(void) ...@@ -535,9 +537,9 @@ static int __init phantom_init(void)
err_unchr: err_unchr:
unregister_chrdev_region(dev, PHANTOM_MAX_MINORS); unregister_chrdev_region(dev, PHANTOM_MAX_MINORS);
err_attr: err_attr:
class_remove_file(phantom_class, &class_attr_version.attr); class_remove_file(&phantom_class, &class_attr_version.attr);
err_class: err_class:
class_destroy(phantom_class); class_unregister(&phantom_class);
err: err:
return retval; return retval;
} }
...@@ -548,8 +550,8 @@ static void __exit phantom_exit(void) ...@@ -548,8 +550,8 @@ static void __exit phantom_exit(void)
unregister_chrdev_region(MKDEV(phantom_major, 0), PHANTOM_MAX_MINORS); unregister_chrdev_region(MKDEV(phantom_major, 0), PHANTOM_MAX_MINORS);
class_remove_file(phantom_class, &class_attr_version.attr); class_remove_file(&phantom_class, &class_attr_version.attr);
class_destroy(phantom_class); class_unregister(&phantom_class);
pr_debug("phantom: module successfully removed\n"); pr_debug("phantom: module successfully removed\n");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment