Commit 3c2bcfd5 authored by Ricardo B. Marliere's avatar Ricardo B. Marliere Committed by Keith Busch

nvme: fabrics: make nvmf_class constant

Since commit 43a7206b ("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: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarRicardo B. Marliere <ricardo@marliere.net>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
parent ab21f3d9
...@@ -1318,7 +1318,10 @@ nvmf_create_ctrl(struct device *dev, const char *buf) ...@@ -1318,7 +1318,10 @@ nvmf_create_ctrl(struct device *dev, const char *buf)
return ERR_PTR(ret); return ERR_PTR(ret);
} }
static struct class *nvmf_class; static const struct class nvmf_class = {
.name = "nvme-fabrics",
};
static struct device *nvmf_device; static struct device *nvmf_device;
static DEFINE_MUTEX(nvmf_dev_mutex); static DEFINE_MUTEX(nvmf_dev_mutex);
...@@ -1438,15 +1441,14 @@ static int __init nvmf_init(void) ...@@ -1438,15 +1441,14 @@ static int __init nvmf_init(void)
if (!nvmf_default_host) if (!nvmf_default_host)
return -ENOMEM; return -ENOMEM;
nvmf_class = class_create("nvme-fabrics"); ret = class_register(&nvmf_class);
if (IS_ERR(nvmf_class)) { if (ret) {
pr_err("couldn't register class nvme-fabrics\n"); pr_err("couldn't register class nvme-fabrics\n");
ret = PTR_ERR(nvmf_class);
goto out_free_host; goto out_free_host;
} }
nvmf_device = nvmf_device =
device_create(nvmf_class, NULL, MKDEV(0, 0), NULL, "ctl"); device_create(&nvmf_class, NULL, MKDEV(0, 0), NULL, "ctl");
if (IS_ERR(nvmf_device)) { if (IS_ERR(nvmf_device)) {
pr_err("couldn't create nvme-fabrics device!\n"); pr_err("couldn't create nvme-fabrics device!\n");
ret = PTR_ERR(nvmf_device); ret = PTR_ERR(nvmf_device);
...@@ -1462,9 +1464,9 @@ static int __init nvmf_init(void) ...@@ -1462,9 +1464,9 @@ static int __init nvmf_init(void)
return 0; return 0;
out_destroy_device: out_destroy_device:
device_destroy(nvmf_class, MKDEV(0, 0)); device_destroy(&nvmf_class, MKDEV(0, 0));
out_destroy_class: out_destroy_class:
class_destroy(nvmf_class); class_unregister(&nvmf_class);
out_free_host: out_free_host:
nvmf_host_put(nvmf_default_host); nvmf_host_put(nvmf_default_host);
return ret; return ret;
...@@ -1473,8 +1475,8 @@ static int __init nvmf_init(void) ...@@ -1473,8 +1475,8 @@ static int __init nvmf_init(void)
static void __exit nvmf_exit(void) static void __exit nvmf_exit(void)
{ {
misc_deregister(&nvmf_misc); misc_deregister(&nvmf_misc);
device_destroy(nvmf_class, MKDEV(0, 0)); device_destroy(&nvmf_class, MKDEV(0, 0));
class_destroy(nvmf_class); class_unregister(&nvmf_class);
nvmf_host_put(nvmf_default_host); nvmf_host_put(nvmf_default_host);
BUILD_BUG_ON(sizeof(struct nvmf_common_command) != 64); BUILD_BUG_ON(sizeof(struct nvmf_common_command) != 64);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment