Skip to content

Commit ac9f3ac

Browse files
rbmarlieremartinkpetersen
authored andcommitted
scsi: ch: Make ch_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 ch_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 a08f0eb commit ac9f3ac

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

drivers/scsi/ch.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ do { \
102102

103103
#define MAX_RETRIES 1
104104

105-
static struct class * ch_sysfs_class;
105+
static const struct class ch_sysfs_class = {
106+
.name = "scsi_changer",
107+
};
106108

107109
typedef struct {
108110
struct kref ref;
@@ -930,7 +932,7 @@ static int ch_probe(struct device *dev)
930932
mutex_init(&ch->lock);
931933
kref_init(&ch->ref);
932934
ch->device = sd;
933-
class_dev = device_create(ch_sysfs_class, dev,
935+
class_dev = device_create(&ch_sysfs_class, dev,
934936
MKDEV(SCSI_CHANGER_MAJOR, ch->minor), ch,
935937
"s%s", ch->name);
936938
if (IS_ERR(class_dev)) {
@@ -955,7 +957,7 @@ static int ch_probe(struct device *dev)
955957

956958
return 0;
957959
destroy_dev:
958-
device_destroy(ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR, ch->minor));
960+
device_destroy(&ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR, ch->minor));
959961
put_device:
960962
scsi_device_put(sd);
961963
remove_idr:
@@ -974,7 +976,7 @@ static int ch_remove(struct device *dev)
974976
dev_set_drvdata(dev, NULL);
975977
spin_unlock(&ch_index_lock);
976978

977-
device_destroy(ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR,ch->minor));
979+
device_destroy(&ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR, ch->minor));
978980
scsi_device_put(ch->device);
979981
kref_put(&ch->ref, ch_destroy);
980982
return 0;
@@ -1003,11 +1005,9 @@ static int __init init_ch_module(void)
10031005
int rc;
10041006

10051007
printk(KERN_INFO "SCSI Media Changer driver v" VERSION " \n");
1006-
ch_sysfs_class = class_create("scsi_changer");
1007-
if (IS_ERR(ch_sysfs_class)) {
1008-
rc = PTR_ERR(ch_sysfs_class);
1008+
rc = class_register(&ch_sysfs_class);
1009+
if (rc)
10091010
return rc;
1010-
}
10111011
rc = register_chrdev(SCSI_CHANGER_MAJOR,"ch",&changer_fops);
10121012
if (rc < 0) {
10131013
printk("Unable to get major %d for SCSI-Changer\n",
@@ -1022,15 +1022,15 @@ static int __init init_ch_module(void)
10221022
fail2:
10231023
unregister_chrdev(SCSI_CHANGER_MAJOR, "ch");
10241024
fail1:
1025-
class_destroy(ch_sysfs_class);
1025+
class_unregister(&ch_sysfs_class);
10261026
return rc;
10271027
}
10281028

10291029
static void __exit exit_ch_module(void)
10301030
{
10311031
scsi_unregister_driver(&ch_template.gendrv);
10321032
unregister_chrdev(SCSI_CHANGER_MAJOR, "ch");
1033-
class_destroy(ch_sysfs_class);
1033+
class_unregister(&ch_sysfs_class);
10341034
idr_destroy(&ch_index_idr);
10351035
}
10361036

0 commit comments

Comments
 (0)