Skip to content

Commit 2eefd39

Browse files
ivanorlov2206axboe
authored andcommitted
ublk: make ublk_chr_class a static const structure
Now that the driver core allows for struct class to be in read-only memory, move the ublk_chr_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: Ming Lei <ming.lei@redhat.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-7-gregkh@linuxfoundation.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 65d7a37 commit 2eefd39

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

drivers/block/ublk_drv.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ static inline void __ublk_complete_rq(struct request *req);
189189
static void ublk_complete_rq(struct kref *ref);
190190

191191
static dev_t ublk_chr_devt;
192-
static struct class *ublk_chr_class;
192+
static const struct class ublk_chr_class = {
193+
.name = "ublk-char",
194+
};
193195

194196
static DEFINE_IDR(ublk_index_idr);
195197
static DEFINE_SPINLOCK(ublk_idr_lock);
@@ -1755,7 +1757,7 @@ static int ublk_add_chdev(struct ublk_device *ub)
17551757

17561758
dev->parent = ublk_misc.this_device;
17571759
dev->devt = MKDEV(MAJOR(ublk_chr_devt), minor);
1758-
dev->class = ublk_chr_class;
1760+
dev->class = &ublk_chr_class;
17591761
dev->release = ublk_cdev_rel;
17601762
device_initialize(dev);
17611763

@@ -2581,11 +2583,10 @@ static int __init ublk_init(void)
25812583
if (ret)
25822584
goto unregister_mis;
25832585

2584-
ublk_chr_class = class_create("ublk-char");
2585-
if (IS_ERR(ublk_chr_class)) {
2586-
ret = PTR_ERR(ublk_chr_class);
2586+
ret = class_register(&ublk_chr_class);
2587+
if (ret)
25872588
goto free_chrdev_region;
2588-
}
2589+
25892590
return 0;
25902591

25912592
free_chrdev_region:
@@ -2603,7 +2604,7 @@ static void __exit ublk_exit(void)
26032604
idr_for_each_entry(&ublk_index_idr, ub, id)
26042605
ublk_remove(ub);
26052606

2606-
class_destroy(ublk_chr_class);
2607+
class_unregister(&ublk_chr_class);
26072608
misc_deregister(&ublk_misc);
26082609

26092610
idr_destroy(&ublk_index_idr);

0 commit comments

Comments
 (0)