Skip to content

Commit 65d7a37

Browse files
ivanorlov2206axboe
authored andcommitted
aoe: make aoe_class a static const structure
Now that the driver core allows for struct class to be in read-only memory, move the aoe_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: Justin Sanders <justin@coraid.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: linux-block@vger.kernel.org Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/r/20230620180129.645646-6-gregkh@linuxfoundation.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 137380c commit 65d7a37

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

drivers/block/aoe/aoechr.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static int emsgs_head_idx, emsgs_tail_idx;
4949
static struct completion emsgs_comp;
5050
static spinlock_t emsgs_lock;
5151
static int nblocked_emsgs_readers;
52-
static struct class *aoe_class;
52+
5353
static struct aoe_chardev chardevs[] = {
5454
{ MINOR_ERR, "err" },
5555
{ MINOR_DISCOVER, "discover" },
@@ -58,6 +58,16 @@ static struct aoe_chardev chardevs[] = {
5858
{ MINOR_FLUSH, "flush" },
5959
};
6060

61+
static char *aoe_devnode(const struct device *dev, umode_t *mode)
62+
{
63+
return kasprintf(GFP_KERNEL, "etherd/%s", dev_name(dev));
64+
}
65+
66+
static const struct class aoe_class = {
67+
.name = "aoe",
68+
.devnode = aoe_devnode,
69+
};
70+
6171
static int
6272
discover(void)
6373
{
@@ -273,11 +283,6 @@ static const struct file_operations aoe_fops = {
273283
.llseek = noop_llseek,
274284
};
275285

276-
static char *aoe_devnode(const struct device *dev, umode_t *mode)
277-
{
278-
return kasprintf(GFP_KERNEL, "etherd/%s", dev_name(dev));
279-
}
280-
281286
int __init
282287
aoechr_init(void)
283288
{
@@ -290,15 +295,14 @@ aoechr_init(void)
290295
}
291296
init_completion(&emsgs_comp);
292297
spin_lock_init(&emsgs_lock);
293-
aoe_class = class_create("aoe");
294-
if (IS_ERR(aoe_class)) {
298+
n = class_register(&aoe_class);
299+
if (n) {
295300
unregister_chrdev(AOE_MAJOR, "aoechr");
296-
return PTR_ERR(aoe_class);
301+
return n;
297302
}
298-
aoe_class->devnode = aoe_devnode;
299303

300304
for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
301-
device_create(aoe_class, NULL,
305+
device_create(&aoe_class, NULL,
302306
MKDEV(AOE_MAJOR, chardevs[i].minor), NULL,
303307
chardevs[i].name);
304308

@@ -311,8 +315,8 @@ aoechr_exit(void)
311315
int i;
312316

313317
for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
314-
device_destroy(aoe_class, MKDEV(AOE_MAJOR, chardevs[i].minor));
315-
class_destroy(aoe_class);
318+
device_destroy(&aoe_class, MKDEV(AOE_MAJOR, chardevs[i].minor));
319+
class_unregister(&aoe_class);
316320
unregister_chrdev(AOE_MAJOR, "aoechr");
317321
}
318322

0 commit comments

Comments
 (0)