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

PCI: switchtec: Make switchtec_class constant

Now that the driver core allows for struct class to be in read-only memory,
we should make all 'class' structures declared at build time placing them
into read-only memory, instead of having to be dynamically allocated at
runtime.

Link: https://lore.kernel.org/r/2024061053-online-unwound-b173@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-By: Logan Gunthorpe <logang@deltatee.com>
Cc: Kurt Schwemmer <kurt.schwemmer@microsemi.com>
Cc: Jon Mason <jdmason@kudzu.us>
Cc: Allen Hubbe <allenbh@gmail.com>

authored by

Greg Kroah-Hartman and committed by
Bjorn Helgaas
8a74e4ea 1613e604

+10 -10
+1 -1
drivers/ntb/hw/mscc/ntb_hw_switchtec.c
··· 1565 1565 1566 1566 static int __init switchtec_ntb_init(void) 1567 1567 { 1568 - switchtec_interface.class = switchtec_class; 1568 + switchtec_interface.class = &switchtec_class; 1569 1569 return class_interface_register(&switchtec_interface); 1570 1570 } 1571 1571 module_init(switchtec_ntb_init);
+8 -8
drivers/pci/switch/switchtec.c
··· 37 37 static dev_t switchtec_devt; 38 38 static DEFINE_IDA(switchtec_minor_ida); 39 39 40 - struct class *switchtec_class; 40 + const struct class switchtec_class = { 41 + .name = "switchtec", 42 + }; 41 43 EXPORT_SYMBOL_GPL(switchtec_class); 42 44 43 45 enum mrpc_state { ··· 1365 1363 1366 1364 dev = &stdev->dev; 1367 1365 device_initialize(dev); 1368 - dev->class = switchtec_class; 1366 + dev->class = &switchtec_class; 1369 1367 dev->parent = &pdev->dev; 1370 1368 dev->groups = switchtec_device_groups; 1371 1369 dev->release = stdev_release; ··· 1853 1851 if (rc) 1854 1852 return rc; 1855 1853 1856 - switchtec_class = class_create("switchtec"); 1857 - if (IS_ERR(switchtec_class)) { 1858 - rc = PTR_ERR(switchtec_class); 1854 + rc = class_register(&switchtec_class); 1855 + if (rc) 1859 1856 goto err_create_class; 1860 - } 1861 1857 1862 1858 rc = pci_register_driver(&switchtec_pci_driver); 1863 1859 if (rc) ··· 1866 1866 return 0; 1867 1867 1868 1868 err_pci_register: 1869 - class_destroy(switchtec_class); 1869 + class_unregister(&switchtec_class); 1870 1870 1871 1871 err_create_class: 1872 1872 unregister_chrdev_region(switchtec_devt, max_devices); ··· 1878 1878 static void __exit switchtec_exit(void) 1879 1879 { 1880 1880 pci_unregister_driver(&switchtec_pci_driver); 1881 - class_destroy(switchtec_class); 1881 + class_unregister(&switchtec_class); 1882 1882 unregister_chrdev_region(switchtec_devt, max_devices); 1883 1883 ida_destroy(&switchtec_minor_ida); 1884 1884
+1 -1
include/linux/switchtec.h
··· 521 521 return container_of(dev, struct switchtec_dev, dev); 522 522 } 523 523 524 - extern struct class *switchtec_class; 524 + extern const struct class switchtec_class; 525 525 526 526 #endif