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

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>

authored by

Ivan Orlov and committed by
Jens Axboe
65d7a37d 137380c0

+17 -13
+17 -13
drivers/block/aoe/aoechr.c
··· 49 49 static struct completion emsgs_comp; 50 50 static spinlock_t emsgs_lock; 51 51 static int nblocked_emsgs_readers; 52 - static struct class *aoe_class; 52 + 53 53 static struct aoe_chardev chardevs[] = { 54 54 { MINOR_ERR, "err" }, 55 55 { MINOR_DISCOVER, "discover" }, 56 56 { MINOR_INTERFACES, "interfaces" }, 57 57 { MINOR_REVALIDATE, "revalidate" }, 58 58 { MINOR_FLUSH, "flush" }, 59 + }; 60 + 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, 59 69 }; 60 70 61 71 static int ··· 283 273 .llseek = noop_llseek, 284 274 }; 285 275 286 - static char *aoe_devnode(const struct device *dev, umode_t *mode) 287 - { 288 - return kasprintf(GFP_KERNEL, "etherd/%s", dev_name(dev)); 289 - } 290 - 291 276 int __init 292 277 aoechr_init(void) 293 278 { ··· 295 290 } 296 291 init_completion(&emsgs_comp); 297 292 spin_lock_init(&emsgs_lock); 298 - aoe_class = class_create("aoe"); 299 - if (IS_ERR(aoe_class)) { 293 + n = class_register(&aoe_class); 294 + if (n) { 300 295 unregister_chrdev(AOE_MAJOR, "aoechr"); 301 - return PTR_ERR(aoe_class); 296 + return n; 302 297 } 303 - aoe_class->devnode = aoe_devnode; 304 298 305 299 for (i = 0; i < ARRAY_SIZE(chardevs); ++i) 306 - device_create(aoe_class, NULL, 300 + device_create(&aoe_class, NULL, 307 301 MKDEV(AOE_MAJOR, chardevs[i].minor), NULL, 308 302 chardevs[i].name); 309 303 ··· 315 311 int i; 316 312 317 313 for (i = 0; i < ARRAY_SIZE(chardevs); ++i) 318 - device_destroy(aoe_class, MKDEV(AOE_MAJOR, chardevs[i].minor)); 319 - class_destroy(aoe_class); 314 + device_destroy(&aoe_class, MKDEV(AOE_MAJOR, chardevs[i].minor)); 315 + class_unregister(&aoe_class); 320 316 unregister_chrdev(AOE_MAJOR, "aoechr"); 321 317 } 322 318