Commit 137380c0 authored by Ivan Orlov's avatar Ivan Orlov Committed by Jens Axboe

block/rnbd: make all 'class' structures const

Now that the driver core allows for struct class to be in read-only
memory, making all 'class' structures to be declared at build time
placing them into read-only memory, instead of having to be dynamically
allocated at load time.

Cc: "Md. Haris Iqbal" <haris.iqbal@ionos.com>
Cc: Jack Wang <jinpu.wang@ionos.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org
Suggested-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarIvan Orlov <ivan.orlov0322@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: default avatarJack Wang <jinpu.wang@ionos.com>
Link: https://lore.kernel.org/r/20230620180129.645646-5-gregkh@linuxfoundation.orgSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 56e71bdf
...@@ -24,7 +24,9 @@ ...@@ -24,7 +24,9 @@
#include "rnbd-clt.h" #include "rnbd-clt.h"
static struct device *rnbd_dev; static struct device *rnbd_dev;
static struct class *rnbd_dev_class; static const struct class rnbd_dev_class = {
.name = "rnbd_client",
};
static struct kobject *rnbd_devs_kobj; static struct kobject *rnbd_devs_kobj;
enum { enum {
...@@ -646,11 +648,11 @@ int rnbd_clt_create_sysfs_files(void) ...@@ -646,11 +648,11 @@ int rnbd_clt_create_sysfs_files(void)
{ {
int err; int err;
rnbd_dev_class = class_create("rnbd-client"); err = class_register(&rnbd_dev_class);
if (IS_ERR(rnbd_dev_class)) if (err)
return PTR_ERR(rnbd_dev_class); return err;
rnbd_dev = device_create_with_groups(rnbd_dev_class, NULL, rnbd_dev = device_create_with_groups(&rnbd_dev_class, NULL,
MKDEV(0, 0), NULL, MKDEV(0, 0), NULL,
default_attr_groups, "ctl"); default_attr_groups, "ctl");
if (IS_ERR(rnbd_dev)) { if (IS_ERR(rnbd_dev)) {
...@@ -666,9 +668,9 @@ int rnbd_clt_create_sysfs_files(void) ...@@ -666,9 +668,9 @@ int rnbd_clt_create_sysfs_files(void)
return 0; return 0;
dev_destroy: dev_destroy:
device_destroy(rnbd_dev_class, MKDEV(0, 0)); device_destroy(&rnbd_dev_class, MKDEV(0, 0));
cls_destroy: cls_destroy:
class_destroy(rnbd_dev_class); class_unregister(&rnbd_dev_class);
return err; return err;
} }
...@@ -678,6 +680,6 @@ void rnbd_clt_destroy_sysfs_files(void) ...@@ -678,6 +680,6 @@ void rnbd_clt_destroy_sysfs_files(void)
sysfs_remove_group(&rnbd_dev->kobj, &default_attr_group); sysfs_remove_group(&rnbd_dev->kobj, &default_attr_group);
kobject_del(rnbd_devs_kobj); kobject_del(rnbd_devs_kobj);
kobject_put(rnbd_devs_kobj); kobject_put(rnbd_devs_kobj);
device_destroy(rnbd_dev_class, MKDEV(0, 0)); device_destroy(&rnbd_dev_class, MKDEV(0, 0));
class_destroy(rnbd_dev_class); class_unregister(&rnbd_dev_class);
} }
...@@ -19,7 +19,9 @@ ...@@ -19,7 +19,9 @@
#include "rnbd-srv.h" #include "rnbd-srv.h"
static struct device *rnbd_dev; static struct device *rnbd_dev;
static struct class *rnbd_dev_class; static const struct class rnbd_dev_class = {
.name = "rnbd-server",
};
static struct kobject *rnbd_devs_kobj; static struct kobject *rnbd_devs_kobj;
static void rnbd_srv_dev_release(struct kobject *kobj) static void rnbd_srv_dev_release(struct kobject *kobj)
...@@ -213,12 +215,12 @@ int rnbd_srv_create_sysfs_files(void) ...@@ -213,12 +215,12 @@ int rnbd_srv_create_sysfs_files(void)
{ {
int err; int err;
rnbd_dev_class = class_create("rnbd-server"); err = class_register(&rnbd_dev_class);
if (IS_ERR(rnbd_dev_class)) if (err)
return PTR_ERR(rnbd_dev_class); return err;
rnbd_dev = device_create(rnbd_dev_class, NULL, rnbd_dev = device_create(&rnbd_dev_class, NULL,
MKDEV(0, 0), NULL, "ctl"); MKDEV(0, 0), NULL, "ctl");
if (IS_ERR(rnbd_dev)) { if (IS_ERR(rnbd_dev)) {
err = PTR_ERR(rnbd_dev); err = PTR_ERR(rnbd_dev);
goto cls_destroy; goto cls_destroy;
...@@ -232,9 +234,9 @@ int rnbd_srv_create_sysfs_files(void) ...@@ -232,9 +234,9 @@ int rnbd_srv_create_sysfs_files(void)
return 0; return 0;
dev_destroy: dev_destroy:
device_destroy(rnbd_dev_class, MKDEV(0, 0)); device_destroy(&rnbd_dev_class, MKDEV(0, 0));
cls_destroy: cls_destroy:
class_destroy(rnbd_dev_class); class_unregister(&rnbd_dev_class);
return err; return err;
} }
...@@ -243,6 +245,6 @@ void rnbd_srv_destroy_sysfs_files(void) ...@@ -243,6 +245,6 @@ void rnbd_srv_destroy_sysfs_files(void)
{ {
kobject_del(rnbd_devs_kobj); kobject_del(rnbd_devs_kobj);
kobject_put(rnbd_devs_kobj); kobject_put(rnbd_devs_kobj);
device_destroy(rnbd_dev_class, MKDEV(0, 0)); device_destroy(&rnbd_dev_class, MKDEV(0, 0));
class_destroy(rnbd_dev_class); class_unregister(&rnbd_dev_class);
} }
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