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

net: wwan: hwsim: make wwan_hwsim_class constant

Since commit 43a7206b0963 ("driver core: class: make class_register() take
a const *"), the driver core allows for struct class to be in read-only
memory, so move the wwan_hwsim_class structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at boot time.

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
Acked-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
Link: https://lore.kernel.org/r/20240302-class_cleanup-net-next-v1-4-8fa378595b93@marliere.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Ricardo B. Marliere and committed by
Jakub Kicinski
d9567f21 2ad2018a

+8 -8
+8 -8
drivers/net/wwan/wwan_hwsim.c
··· 25 25 module_param_named(devices, wwan_hwsim_devsnum, int, 0444); 26 26 MODULE_PARM_DESC(devices, "Number of simulated devices"); 27 27 28 - static struct class *wwan_hwsim_class; 28 + static const struct class wwan_hwsim_class = { 29 + .name = "wwan_hwsim", 30 + }; 29 31 30 32 static struct dentry *wwan_hwsim_debugfs_topdir; 31 33 static struct dentry *wwan_hwsim_debugfs_devcreate; ··· 279 277 spin_unlock(&wwan_hwsim_devs_lock); 280 278 281 279 dev->dev.release = wwan_hwsim_dev_release; 282 - dev->dev.class = wwan_hwsim_class; 280 + dev->dev.class = &wwan_hwsim_class; 283 281 dev_set_name(&dev->dev, "hwsim%u", dev->id); 284 282 285 283 spin_lock_init(&dev->ports_lock); ··· 513 511 if (!wwan_wq) 514 512 return -ENOMEM; 515 513 516 - wwan_hwsim_class = class_create("wwan_hwsim"); 517 - if (IS_ERR(wwan_hwsim_class)) { 518 - err = PTR_ERR(wwan_hwsim_class); 514 + err = class_register(&wwan_hwsim_class); 515 + if (err) 519 516 goto err_wq_destroy; 520 - } 521 517 522 518 wwan_hwsim_debugfs_topdir = debugfs_create_dir("wwan_hwsim", NULL); 523 519 wwan_hwsim_debugfs_devcreate = ··· 534 534 wwan_hwsim_free_devs(); 535 535 flush_workqueue(wwan_wq); /* Wait deletion works completion */ 536 536 debugfs_remove(wwan_hwsim_debugfs_topdir); 537 - class_destroy(wwan_hwsim_class); 537 + class_unregister(&wwan_hwsim_class); 538 538 err_wq_destroy: 539 539 destroy_workqueue(wwan_wq); 540 540 ··· 547 547 wwan_hwsim_free_devs(); 548 548 flush_workqueue(wwan_wq); /* Wait deletion works completion */ 549 549 debugfs_remove(wwan_hwsim_debugfs_topdir); 550 - class_destroy(wwan_hwsim_class); 550 + class_unregister(&wwan_hwsim_class); 551 551 destroy_workqueue(wwan_wq); 552 552 } 553 553