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

bsg: make bsg_class a static const structure

Now that the driver core allows for struct class to be in read-only
memory, move the bsg_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: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: linux-scsi@vger.kernel.org
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-8-gregkh@linuxfoundation.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Ivan Orlov and committed by
Jens Axboe
72ef02b8 2eefd399

+11 -7
+11 -7
block/bsg.c
··· 39 39 #define BSG_MAX_DEVS 32768 40 40 41 41 static DEFINE_IDA(bsg_minor_ida); 42 - static struct class *bsg_class; 42 + static const struct class bsg_class; 43 43 static int bsg_major; 44 44 45 45 static unsigned int bsg_timeout(struct bsg_device *bd, struct sg_io_v4 *hdr) ··· 208 208 return ERR_PTR(ret); 209 209 } 210 210 bd->device.devt = MKDEV(bsg_major, ret); 211 - bd->device.class = bsg_class; 211 + bd->device.class = &bsg_class; 212 212 bd->device.parent = parent; 213 213 bd->device.release = bsg_device_release; 214 214 dev_set_name(&bd->device, "%s", name); ··· 242 242 return kasprintf(GFP_KERNEL, "bsg/%s", dev_name(dev)); 243 243 } 244 244 245 + static const struct class bsg_class = { 246 + .name = "bsg", 247 + .devnode = bsg_devnode, 248 + }; 249 + 245 250 static int __init bsg_init(void) 246 251 { 247 252 dev_t devid; 248 253 int ret; 249 254 250 - bsg_class = class_create("bsg"); 251 - if (IS_ERR(bsg_class)) 252 - return PTR_ERR(bsg_class); 253 - bsg_class->devnode = bsg_devnode; 255 + ret = class_register(&bsg_class); 256 + if (ret) 257 + return ret; 254 258 255 259 ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg"); 256 260 if (ret) ··· 266 262 return 0; 267 263 268 264 destroy_bsg_class: 269 - class_destroy(bsg_class); 265 + class_unregister(&bsg_class); 270 266 return ret; 271 267 } 272 268