Skip to content

Commit a08f0eb

Browse files
rbmarlieremartinkpetersen
authored andcommitted
scsi: cxlflash: Make cxlflash_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 cxlflash_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 ee8dda6 commit a08f0eb

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

drivers/scsi/cxlflash/main.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ MODULE_AUTHOR("Manoj N. Kumar <[email protected]>");
2828
MODULE_AUTHOR("Matthew R. Ochs <[email protected]>");
2929
MODULE_LICENSE("GPL");
3030

31-
static struct class *cxlflash_class;
31+
static char *cxlflash_devnode(const struct device *dev, umode_t *mode);
32+
static const struct class cxlflash_class = {
33+
.name = "cxlflash",
34+
.devnode = cxlflash_devnode,
35+
};
36+
3237
static u32 cxlflash_major;
3338
static DECLARE_BITMAP(cxlflash_minor, CXLFLASH_MAX_ADAPTERS);
3439

@@ -3602,7 +3607,7 @@ static int init_chrdev(struct cxlflash_cfg *cfg)
36023607
goto err1;
36033608
}
36043609

3605-
char_dev = device_create(cxlflash_class, NULL, devno,
3610+
char_dev = device_create(&cxlflash_class, NULL, devno,
36063611
NULL, "cxlflash%d", minor);
36073612
if (IS_ERR(char_dev)) {
36083613
rc = PTR_ERR(char_dev);
@@ -3880,14 +3885,12 @@ static int cxlflash_class_init(void)
38803885

38813886
cxlflash_major = MAJOR(devno);
38823887

3883-
cxlflash_class = class_create("cxlflash");
3884-
if (IS_ERR(cxlflash_class)) {
3885-
rc = PTR_ERR(cxlflash_class);
3888+
rc = class_register(&cxlflash_class);
3889+
if (rc) {
38863890
pr_err("%s: class_create failed rc=%d\n", __func__, rc);
38873891
goto err;
38883892
}
38893893

3890-
cxlflash_class->devnode = cxlflash_devnode;
38913894
out:
38923895
pr_debug("%s: returning rc=%d\n", __func__, rc);
38933896
return rc;
@@ -3903,7 +3906,7 @@ static void cxlflash_class_exit(void)
39033906
{
39043907
dev_t devno = MKDEV(cxlflash_major, 0);
39053908

3906-
class_destroy(cxlflash_class);
3909+
class_unregister(&cxlflash_class);
39073910
unregister_chrdev_region(devno, CXLFLASH_MAX_ADAPTERS);
39083911
}
39093912

0 commit comments

Comments
 (0)