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

scsi: sg: Make sg_sysfs_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 sg_sysfs_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-1-b9096b990e27@marliere.netSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent db06ae7c
...@@ -1424,7 +1424,9 @@ static const struct file_operations sg_fops = { ...@@ -1424,7 +1424,9 @@ static const struct file_operations sg_fops = {
.llseek = no_llseek, .llseek = no_llseek,
}; };
static struct class *sg_sysfs_class; static const struct class sg_sysfs_class = {
.name = "scsi_generic"
};
static int sg_sysfs_valid = 0; static int sg_sysfs_valid = 0;
...@@ -1526,7 +1528,7 @@ sg_add_device(struct device *cl_dev) ...@@ -1526,7 +1528,7 @@ sg_add_device(struct device *cl_dev)
if (sg_sysfs_valid) { if (sg_sysfs_valid) {
struct device *sg_class_member; struct device *sg_class_member;
sg_class_member = device_create(sg_sysfs_class, cl_dev->parent, sg_class_member = device_create(&sg_sysfs_class, cl_dev->parent,
MKDEV(SCSI_GENERIC_MAJOR, MKDEV(SCSI_GENERIC_MAJOR,
sdp->index), sdp->index),
sdp, "%s", sdp->name); sdp, "%s", sdp->name);
...@@ -1616,7 +1618,7 @@ sg_remove_device(struct device *cl_dev) ...@@ -1616,7 +1618,7 @@ sg_remove_device(struct device *cl_dev)
read_unlock_irqrestore(&sdp->sfd_lock, iflags); read_unlock_irqrestore(&sdp->sfd_lock, iflags);
sysfs_remove_link(&scsidp->sdev_gendev.kobj, "generic"); sysfs_remove_link(&scsidp->sdev_gendev.kobj, "generic");
device_destroy(sg_sysfs_class, MKDEV(SCSI_GENERIC_MAJOR, sdp->index)); device_destroy(&sg_sysfs_class, MKDEV(SCSI_GENERIC_MAJOR, sdp->index));
cdev_del(sdp->cdev); cdev_del(sdp->cdev);
sdp->cdev = NULL; sdp->cdev = NULL;
...@@ -1687,11 +1689,9 @@ init_sg(void) ...@@ -1687,11 +1689,9 @@ init_sg(void)
SG_MAX_DEVS, "sg"); SG_MAX_DEVS, "sg");
if (rc) if (rc)
return rc; return rc;
sg_sysfs_class = class_create("scsi_generic"); rc = class_register(&sg_sysfs_class);
if ( IS_ERR(sg_sysfs_class) ) { if (rc)
rc = PTR_ERR(sg_sysfs_class);
goto err_out; goto err_out;
}
sg_sysfs_valid = 1; sg_sysfs_valid = 1;
rc = scsi_register_interface(&sg_interface); rc = scsi_register_interface(&sg_interface);
if (0 == rc) { if (0 == rc) {
...@@ -1700,7 +1700,7 @@ init_sg(void) ...@@ -1700,7 +1700,7 @@ init_sg(void)
#endif /* CONFIG_SCSI_PROC_FS */ #endif /* CONFIG_SCSI_PROC_FS */
return 0; return 0;
} }
class_destroy(sg_sysfs_class); class_unregister(&sg_sysfs_class);
register_sg_sysctls(); register_sg_sysctls();
err_out: err_out:
unregister_chrdev_region(MKDEV(SCSI_GENERIC_MAJOR, 0), SG_MAX_DEVS); unregister_chrdev_region(MKDEV(SCSI_GENERIC_MAJOR, 0), SG_MAX_DEVS);
...@@ -1715,7 +1715,7 @@ exit_sg(void) ...@@ -1715,7 +1715,7 @@ exit_sg(void)
remove_proc_subtree("scsi/sg", NULL); remove_proc_subtree("scsi/sg", NULL);
#endif /* CONFIG_SCSI_PROC_FS */ #endif /* CONFIG_SCSI_PROC_FS */
scsi_unregister_interface(&sg_interface); scsi_unregister_interface(&sg_interface);
class_destroy(sg_sysfs_class); class_unregister(&sg_sysfs_class);
sg_sysfs_valid = 0; sg_sysfs_valid = 0;
unregister_chrdev_region(MKDEV(SCSI_GENERIC_MAJOR, 0), unregister_chrdev_region(MKDEV(SCSI_GENERIC_MAJOR, 0),
SG_MAX_DEVS); SG_MAX_DEVS);
......
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