Skip to content

Commit 5dea176

Browse files
nvme: fabrics: make nvmf_class constant
JIRA: https://issues.redhat.com/browse/RHEL-25547 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 nvmf_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: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Keith Busch <kbusch@kernel.org> (cherry picked from commit 3c2bcfd) Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
1 parent 3c79b59 commit 5dea176

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

drivers/nvme/host/fabrics.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,10 @@ nvmf_create_ctrl(struct device *dev, const char *buf)
12941294
return ERR_PTR(ret);
12951295
}
12961296

1297-
static struct class *nvmf_class;
1297+
static const struct class nvmf_class = {
1298+
.name = "nvme-fabrics",
1299+
};
1300+
12981301
static struct device *nvmf_device;
12991302
static DEFINE_MUTEX(nvmf_dev_mutex);
13001303

@@ -1414,15 +1417,14 @@ static int __init nvmf_init(void)
14141417
if (!nvmf_default_host)
14151418
return -ENOMEM;
14161419

1417-
nvmf_class = class_create("nvme-fabrics");
1418-
if (IS_ERR(nvmf_class)) {
1420+
ret = class_register(&nvmf_class);
1421+
if (ret) {
14191422
pr_err("couldn't register class nvme-fabrics\n");
1420-
ret = PTR_ERR(nvmf_class);
14211423
goto out_free_host;
14221424
}
14231425

14241426
nvmf_device =
1425-
device_create(nvmf_class, NULL, MKDEV(0, 0), NULL, "ctl");
1427+
device_create(&nvmf_class, NULL, MKDEV(0, 0), NULL, "ctl");
14261428
if (IS_ERR(nvmf_device)) {
14271429
pr_err("couldn't create nvme-fabrics device!\n");
14281430
ret = PTR_ERR(nvmf_device);
@@ -1438,9 +1440,9 @@ static int __init nvmf_init(void)
14381440
return 0;
14391441

14401442
out_destroy_device:
1441-
device_destroy(nvmf_class, MKDEV(0, 0));
1443+
device_destroy(&nvmf_class, MKDEV(0, 0));
14421444
out_destroy_class:
1443-
class_destroy(nvmf_class);
1445+
class_unregister(&nvmf_class);
14441446
out_free_host:
14451447
nvmf_host_put(nvmf_default_host);
14461448
return ret;
@@ -1449,8 +1451,8 @@ static int __init nvmf_init(void)
14491451
static void __exit nvmf_exit(void)
14501452
{
14511453
misc_deregister(&nvmf_misc);
1452-
device_destroy(nvmf_class, MKDEV(0, 0));
1453-
class_destroy(nvmf_class);
1454+
device_destroy(&nvmf_class, MKDEV(0, 0));
1455+
class_unregister(&nvmf_class);
14541456
nvmf_host_put(nvmf_default_host);
14551457

14561458
BUILD_BUG_ON(sizeof(struct nvmf_common_command) != 64);

0 commit comments

Comments
 (0)