Commit ee8dda6a authored by Ricardo B. Marliere's avatar Ricardo B. Marliere Committed by Martin K. Petersen

scsi: pmcraid: Make pmcraid_class constant

Since commit 43a7206b ("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 pmcraid_class structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at boot time.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Suggested-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarRicardo B. Marliere <ricardo@marliere.net>
Link: https://lore.kernel.org/r/20240302-class_cleanup-scsi-v1-2-b9096b990e27@marliere.netSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent f1fb4176
...@@ -61,7 +61,9 @@ static atomic_t pmcraid_adapter_count = ATOMIC_INIT(0); ...@@ -61,7 +61,9 @@ static atomic_t pmcraid_adapter_count = ATOMIC_INIT(0);
* pmcraid_minor - minor number(s) to use * pmcraid_minor - minor number(s) to use
*/ */
static unsigned int pmcraid_major; static unsigned int pmcraid_major;
static struct class *pmcraid_class; static const struct class pmcraid_class = {
.name = PMCRAID_DEVFILE,
};
static DECLARE_BITMAP(pmcraid_minor, PMCRAID_MAX_ADAPTERS); static DECLARE_BITMAP(pmcraid_minor, PMCRAID_MAX_ADAPTERS);
/* /*
...@@ -4723,7 +4725,7 @@ static int pmcraid_setup_chrdev(struct pmcraid_instance *pinstance) ...@@ -4723,7 +4725,7 @@ static int pmcraid_setup_chrdev(struct pmcraid_instance *pinstance)
if (error) if (error)
pmcraid_release_minor(minor); pmcraid_release_minor(minor);
else else
device_create(pmcraid_class, NULL, MKDEV(pmcraid_major, minor), device_create(&pmcraid_class, NULL, MKDEV(pmcraid_major, minor),
NULL, "%s%u", PMCRAID_DEVFILE, minor); NULL, "%s%u", PMCRAID_DEVFILE, minor);
return error; return error;
} }
...@@ -4739,7 +4741,7 @@ static int pmcraid_setup_chrdev(struct pmcraid_instance *pinstance) ...@@ -4739,7 +4741,7 @@ static int pmcraid_setup_chrdev(struct pmcraid_instance *pinstance)
static void pmcraid_release_chrdev(struct pmcraid_instance *pinstance) static void pmcraid_release_chrdev(struct pmcraid_instance *pinstance)
{ {
pmcraid_release_minor(MINOR(pinstance->cdev.dev)); pmcraid_release_minor(MINOR(pinstance->cdev.dev));
device_destroy(pmcraid_class, device_destroy(&pmcraid_class,
MKDEV(pmcraid_major, MINOR(pinstance->cdev.dev))); MKDEV(pmcraid_major, MINOR(pinstance->cdev.dev)));
cdev_del(&pinstance->cdev); cdev_del(&pinstance->cdev);
} }
...@@ -5390,10 +5392,10 @@ static int __init pmcraid_init(void) ...@@ -5390,10 +5392,10 @@ static int __init pmcraid_init(void)
} }
pmcraid_major = MAJOR(dev); pmcraid_major = MAJOR(dev);
pmcraid_class = class_create(PMCRAID_DEVFILE);
if (IS_ERR(pmcraid_class)) { error = class_register(&pmcraid_class);
error = PTR_ERR(pmcraid_class);
if (error) {
pmcraid_err("failed to register with sysfs, error = %x\n", pmcraid_err("failed to register with sysfs, error = %x\n",
error); error);
goto out_unreg_chrdev; goto out_unreg_chrdev;
...@@ -5402,7 +5404,7 @@ static int __init pmcraid_init(void) ...@@ -5402,7 +5404,7 @@ static int __init pmcraid_init(void)
error = pmcraid_netlink_init(); error = pmcraid_netlink_init();
if (error) { if (error) {
class_destroy(pmcraid_class); class_unregister(&pmcraid_class);
goto out_unreg_chrdev; goto out_unreg_chrdev;
} }
...@@ -5413,7 +5415,7 @@ static int __init pmcraid_init(void) ...@@ -5413,7 +5415,7 @@ static int __init pmcraid_init(void)
pmcraid_err("failed to register pmcraid driver, error = %x\n", pmcraid_err("failed to register pmcraid driver, error = %x\n",
error); error);
class_destroy(pmcraid_class); class_unregister(&pmcraid_class);
pmcraid_netlink_release(); pmcraid_netlink_release();
out_unreg_chrdev: out_unreg_chrdev:
...@@ -5432,7 +5434,7 @@ static void __exit pmcraid_exit(void) ...@@ -5432,7 +5434,7 @@ static void __exit pmcraid_exit(void)
unregister_chrdev_region(MKDEV(pmcraid_major, 0), unregister_chrdev_region(MKDEV(pmcraid_major, 0),
PMCRAID_MAX_ADAPTERS); PMCRAID_MAX_ADAPTERS);
pci_unregister_driver(&pmcraid_driver); pci_unregister_driver(&pmcraid_driver);
class_destroy(pmcraid_class); class_unregister(&pmcraid_class);
} }
module_init(pmcraid_init); module_init(pmcraid_init);
......
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