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

net: ppp: make ppp_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 ppp_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>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20240302-class_cleanup-net-next-v1-3-8fa378595b93@marliere.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Ricardo B. Marliere and committed by
Jakub Kicinski
2ad2018a 63767a76

+9 -9
+9 -9
drivers/net/ppp/ppp_generic.c
··· 295 295 296 296 static const struct net_device_ops ppp_netdev_ops; 297 297 298 - static struct class *ppp_class; 298 + static const struct class ppp_class = { 299 + .name = "ppp", 300 + }; 299 301 300 302 /* per net-namespace data */ 301 303 static inline struct ppp_net *ppp_pernet(struct net *net) ··· 1396 1394 goto out_net; 1397 1395 } 1398 1396 1399 - ppp_class = class_create("ppp"); 1400 - if (IS_ERR(ppp_class)) { 1401 - err = PTR_ERR(ppp_class); 1397 + err = class_register(&ppp_class); 1398 + if (err) 1402 1399 goto out_chrdev; 1403 - } 1404 1400 1405 1401 err = rtnl_link_register(&ppp_link_ops); 1406 1402 if (err) { ··· 1407 1407 } 1408 1408 1409 1409 /* not a big deal if we fail here :-) */ 1410 - device_create(ppp_class, NULL, MKDEV(PPP_MAJOR, 0), NULL, "ppp"); 1410 + device_create(&ppp_class, NULL, MKDEV(PPP_MAJOR, 0), NULL, "ppp"); 1411 1411 1412 1412 return 0; 1413 1413 1414 1414 out_class: 1415 - class_destroy(ppp_class); 1415 + class_unregister(&ppp_class); 1416 1416 out_chrdev: 1417 1417 unregister_chrdev(PPP_MAJOR, "ppp"); 1418 1418 out_net: ··· 3549 3549 pr_err("PPP: removing module but units remain!\n"); 3550 3550 rtnl_link_unregister(&ppp_link_ops); 3551 3551 unregister_chrdev(PPP_MAJOR, "ppp"); 3552 - device_destroy(ppp_class, MKDEV(PPP_MAJOR, 0)); 3553 - class_destroy(ppp_class); 3552 + device_destroy(&ppp_class, MKDEV(PPP_MAJOR, 0)); 3553 + class_unregister(&ppp_class); 3554 3554 unregister_pernet_device(&ppp_net_ops); 3555 3555 } 3556 3556