Skip to content

Commit 3c2bcfd

Browse files
rbmarlierekeithbusch
authored andcommitted
nvme: fabrics: make nvmf_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 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>
1 parent ab21f3d commit 3c2bcfd

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
@@ -1318,7 +1318,10 @@ nvmf_create_ctrl(struct device *dev, const char *buf)
13181318
return ERR_PTR(ret);
13191319
}
13201320

1321-
static struct class *nvmf_class;
1321+
static const struct class nvmf_class = {
1322+
.name = "nvme-fabrics",
1323+
};
1324+
13221325
static struct device *nvmf_device;
13231326
static DEFINE_MUTEX(nvmf_dev_mutex);
13241327

@@ -1438,15 +1441,14 @@ static int __init nvmf_init(void)
14381441
if (!nvmf_default_host)
14391442
return -ENOMEM;
14401443

1441-
nvmf_class = class_create("nvme-fabrics");
1442-
if (IS_ERR(nvmf_class)) {
1444+
ret = class_register(&nvmf_class);
1445+
if (ret) {
14431446
pr_err("couldn't register class nvme-fabrics\n");
1444-
ret = PTR_ERR(nvmf_class);
14451447
goto out_free_host;
14461448
}
14471449

14481450
nvmf_device =
1449-
device_create(nvmf_class, NULL, MKDEV(0, 0), NULL, "ctl");
1451+
device_create(&nvmf_class, NULL, MKDEV(0, 0), NULL, "ctl");
14501452
if (IS_ERR(nvmf_device)) {
14511453
pr_err("couldn't create nvme-fabrics device!\n");
14521454
ret = PTR_ERR(nvmf_device);
@@ -1462,9 +1464,9 @@ static int __init nvmf_init(void)
14621464
return 0;
14631465

14641466
out_destroy_device:
1465-
device_destroy(nvmf_class, MKDEV(0, 0));
1467+
device_destroy(&nvmf_class, MKDEV(0, 0));
14661468
out_destroy_class:
1467-
class_destroy(nvmf_class);
1469+
class_unregister(&nvmf_class);
14681470
out_free_host:
14691471
nvmf_host_put(nvmf_default_host);
14701472
return ret;
@@ -1473,8 +1475,8 @@ static int __init nvmf_init(void)
14731475
static void __exit nvmf_exit(void)
14741476
{
14751477
misc_deregister(&nvmf_misc);
1476-
device_destroy(nvmf_class, MKDEV(0, 0));
1477-
class_destroy(nvmf_class);
1478+
device_destroy(&nvmf_class, MKDEV(0, 0));
1479+
class_unregister(&nvmf_class);
14781480
nvmf_host_put(nvmf_default_host);
14791481

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

0 commit comments

Comments
 (0)