Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Ivan Orlov and committed by
Jens Axboe
2eefd399 65d7a37d

+8 -7
+8 -7
drivers/block/ublk_drv.c
··· 189 189 static void ublk_complete_rq(struct kref *ref); 190 190 191 191 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 + }; 193 195 194 196 static DEFINE_IDR(ublk_index_idr); 195 197 static DEFINE_SPINLOCK(ublk_idr_lock); ··· 1757 1755 1758 1756 dev->parent = ublk_misc.this_device; 1759 1757 dev->devt = MKDEV(MAJOR(ublk_chr_devt), minor); 1760 - dev->class = ublk_chr_class; 1758 + dev->class = &ublk_chr_class; 1761 1759 dev->release = ublk_cdev_rel; 1762 1760 device_initialize(dev); 1763 1761 ··· 2583 2581 if (ret) 2584 2582 goto unregister_mis; 2585 2583 2586 - ublk_chr_class = class_create("ublk-char"); 2587 - if (IS_ERR(ublk_chr_class)) { 2588 - ret = PTR_ERR(ublk_chr_class); 2584 + ret = class_register(&ublk_chr_class); 2585 + if (ret) 2589 2586 goto free_chrdev_region; 2590 - } 2587 + 2591 2588 return 0; 2592 2589 2593 2590 free_chrdev_region: ··· 2604 2603 idr_for_each_entry(&ublk_index_idr, ub, id) 2605 2604 ublk_remove(ub); 2606 2605 2607 - class_destroy(ublk_chr_class); 2606 + class_unregister(&ublk_chr_class); 2608 2607 misc_deregister(&ublk_misc); 2609 2608 2610 2609 idr_destroy(&ublk_index_idr);