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 @@
#include "rnbd-clt.h"
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;
enum {
......@@ -646,11 +648,11 @@ int rnbd_clt_create_sysfs_files(void)
{
int err;
rnbd_dev_class = class_create("rnbd-client");
if (IS_ERR(rnbd_dev_class))
return PTR_ERR(rnbd_dev_class);
err = class_register(&rnbd_dev_class);
if (err)
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,
default_attr_groups, "ctl");
if (IS_ERR(rnbd_dev)) {
......@@ -666,9 +668,9 @@ int rnbd_clt_create_sysfs_files(void)
return 0;
dev_destroy:
device_destroy(rnbd_dev_class, MKDEV(0, 0));
device_destroy(&rnbd_dev_class, MKDEV(0, 0));
cls_destroy:
class_destroy(rnbd_dev_class);
class_unregister(&rnbd_dev_class);
return err;
}
......@@ -678,6 +680,6 @@ void rnbd_clt_destroy_sysfs_files(void)
sysfs_remove_group(&rnbd_dev->kobj, &default_attr_group);
kobject_del(rnbd_devs_kobj);
kobject_put(rnbd_devs_kobj);
device_destroy(rnbd_dev_class, MKDEV(0, 0));
class_destroy(rnbd_dev_class);
device_destroy(&rnbd_dev_class, MKDEV(0, 0));
class_unregister(&rnbd_dev_class);
}
......@@ -19,7 +19,9 @@
#include "rnbd-srv.h"
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 void rnbd_srv_dev_release(struct kobject *kobj)
......@@ -213,11 +215,11 @@ int rnbd_srv_create_sysfs_files(void)
{
int err;
rnbd_dev_class = class_create("rnbd-server");
if (IS_ERR(rnbd_dev_class))
return PTR_ERR(rnbd_dev_class);
err = class_register(&rnbd_dev_class);
if (err)
return err;
rnbd_dev = device_create(rnbd_dev_class, NULL,
rnbd_dev = device_create(&rnbd_dev_class, NULL,
MKDEV(0, 0), NULL, "ctl");
if (IS_ERR(rnbd_dev)) {
err = PTR_ERR(rnbd_dev);
......@@ -232,9 +234,9 @@ int rnbd_srv_create_sysfs_files(void)
return 0;
dev_destroy:
device_destroy(rnbd_dev_class, MKDEV(0, 0));
device_destroy(&rnbd_dev_class, MKDEV(0, 0));
cls_destroy:
class_destroy(rnbd_dev_class);
class_unregister(&rnbd_dev_class);
return err;
}
......@@ -243,6 +245,6 @@ void rnbd_srv_destroy_sysfs_files(void)
{
kobject_del(rnbd_devs_kobj);
kobject_put(rnbd_devs_kobj);
device_destroy(rnbd_dev_class, MKDEV(0, 0));
class_destroy(rnbd_dev_class);
device_destroy(&rnbd_dev_class, MKDEV(0, 0));
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