Skip to content

Commit 5bd812a

Browse files
gregkhopsiff
authored andcommitted
PCI: switchtec: Make switchtec_class constant
[Upstream commit 8a74e4e] 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> Signed-off-by: WangYuli <wangyl5933@chinaunicom.cn>
1 parent 62b93f9 commit 5bd812a

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

drivers/ntb/hw/mscc/ntb_hw_switchtec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ static struct class_interface switchtec_interface = {
15741574

15751575
static int __init switchtec_ntb_init(void)
15761576
{
1577-
switchtec_interface.class = switchtec_class;
1577+
switchtec_interface.class = &switchtec_class;
15781578
return class_interface_register(&switchtec_interface);
15791579
}
15801580
module_init(switchtec_ntb_init);

drivers/pci/switch/switchtec.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ MODULE_PARM_DESC(nirqs, "number of interrupts to allocate (more may be useful fo
3737
static dev_t switchtec_devt;
3838
static DEFINE_IDA(switchtec_minor_ida);
3939

40-
struct class *switchtec_class;
40+
const struct class switchtec_class = {
41+
.name = "switchtec",
42+
};
4143
EXPORT_SYMBOL_GPL(switchtec_class);
4244

4345
enum mrpc_state {
@@ -1362,7 +1364,7 @@ static struct switchtec_dev *stdev_create(struct pci_dev *pdev)
13621364

13631365
dev = &stdev->dev;
13641366
device_initialize(dev);
1365-
dev->class = switchtec_class;
1367+
dev->class = &switchtec_class;
13661368
dev->parent = &pdev->dev;
13671369
dev->groups = switchtec_device_groups;
13681370
dev->release = stdev_release;
@@ -1876,11 +1878,9 @@ static int __init switchtec_init(void)
18761878
if (rc)
18771879
return rc;
18781880

1879-
switchtec_class = class_create("switchtec");
1880-
if (IS_ERR(switchtec_class)) {
1881-
rc = PTR_ERR(switchtec_class);
1881+
rc = class_register(&switchtec_class);
1882+
if (rc)
18821883
goto err_create_class;
1883-
}
18841884

18851885
rc = pci_register_driver(&switchtec_pci_driver);
18861886
if (rc)
@@ -1891,7 +1891,7 @@ static int __init switchtec_init(void)
18911891
return 0;
18921892

18931893
err_pci_register:
1894-
class_destroy(switchtec_class);
1894+
class_unregister(&switchtec_class);
18951895

18961896
err_create_class:
18971897
unregister_chrdev_region(switchtec_devt, max_devices);
@@ -1903,7 +1903,7 @@ module_init(switchtec_init);
19031903
static void __exit switchtec_exit(void)
19041904
{
19051905
pci_unregister_driver(&switchtec_pci_driver);
1906-
class_destroy(switchtec_class);
1906+
class_unregister(&switchtec_class);
19071907
unregister_chrdev_region(switchtec_devt, max_devices);
19081908
ida_destroy(&switchtec_minor_ida);
19091909

include/linux/switchtec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,6 @@ static inline struct switchtec_dev *to_stdev(struct device *dev)
521521
return container_of(dev, struct switchtec_dev, dev);
522522
}
523523

524-
extern struct class *switchtec_class;
524+
extern const struct class switchtec_class;
525525

526526
#endif

0 commit comments

Comments
 (0)