Skip to content

Commit f1fb417

Browse files
rbmarlieremartinkpetersen
authored andcommitted
scsi: sg: Make sg_sysfs_class constant
Since commit 43a7206 ("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 <[email protected]> Suggested-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Ricardo B. Marliere <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent db06ae7 commit f1fb417

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drivers/scsi/sg.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,9 @@ static const struct file_operations sg_fops = {
14241424
.llseek = no_llseek,
14251425
};
14261426

1427-
static struct class *sg_sysfs_class;
1427+
static const struct class sg_sysfs_class = {
1428+
.name = "scsi_generic"
1429+
};
14281430

14291431
static int sg_sysfs_valid = 0;
14301432

@@ -1526,7 +1528,7 @@ sg_add_device(struct device *cl_dev)
15261528
if (sg_sysfs_valid) {
15271529
struct device *sg_class_member;
15281530

1529-
sg_class_member = device_create(sg_sysfs_class, cl_dev->parent,
1531+
sg_class_member = device_create(&sg_sysfs_class, cl_dev->parent,
15301532
MKDEV(SCSI_GENERIC_MAJOR,
15311533
sdp->index),
15321534
sdp, "%s", sdp->name);
@@ -1616,7 +1618,7 @@ sg_remove_device(struct device *cl_dev)
16161618
read_unlock_irqrestore(&sdp->sfd_lock, iflags);
16171619

16181620
sysfs_remove_link(&scsidp->sdev_gendev.kobj, "generic");
1619-
device_destroy(sg_sysfs_class, MKDEV(SCSI_GENERIC_MAJOR, sdp->index));
1621+
device_destroy(&sg_sysfs_class, MKDEV(SCSI_GENERIC_MAJOR, sdp->index));
16201622
cdev_del(sdp->cdev);
16211623
sdp->cdev = NULL;
16221624

@@ -1687,11 +1689,9 @@ init_sg(void)
16871689
SG_MAX_DEVS, "sg");
16881690
if (rc)
16891691
return rc;
1690-
sg_sysfs_class = class_create("scsi_generic");
1691-
if ( IS_ERR(sg_sysfs_class) ) {
1692-
rc = PTR_ERR(sg_sysfs_class);
1692+
rc = class_register(&sg_sysfs_class);
1693+
if (rc)
16931694
goto err_out;
1694-
}
16951695
sg_sysfs_valid = 1;
16961696
rc = scsi_register_interface(&sg_interface);
16971697
if (0 == rc) {
@@ -1700,7 +1700,7 @@ init_sg(void)
17001700
#endif /* CONFIG_SCSI_PROC_FS */
17011701
return 0;
17021702
}
1703-
class_destroy(sg_sysfs_class);
1703+
class_unregister(&sg_sysfs_class);
17041704
register_sg_sysctls();
17051705
err_out:
17061706
unregister_chrdev_region(MKDEV(SCSI_GENERIC_MAJOR, 0), SG_MAX_DEVS);
@@ -1715,7 +1715,7 @@ exit_sg(void)
17151715
remove_proc_subtree("scsi/sg", NULL);
17161716
#endif /* CONFIG_SCSI_PROC_FS */
17171717
scsi_unregister_interface(&sg_interface);
1718-
class_destroy(sg_sysfs_class);
1718+
class_unregister(&sg_sysfs_class);
17191719
sg_sysfs_valid = 0;
17201720
unregister_chrdev_region(MKDEV(SCSI_GENERIC_MAJOR, 0),
17211721
SG_MAX_DEVS);

0 commit comments

Comments
 (0)