Skip to content

Commit 03377a6

Browse files
gregkhkwilczynski
authored andcommitted
PCI: endpoint: Make pci_epc_class struct 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/linux-pci/2024061011-citable-herbicide-1095@gregkh Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]>
1 parent 473b2cf commit 03377a6

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

drivers/pci/endpoint/pci-epc-core.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#include <linux/pci-epf.h>
1515
#include <linux/pci-ep-cfs.h>
1616

17-
static struct class *pci_epc_class;
17+
static const struct class pci_epc_class = {
18+
.name = "pci_epc",
19+
};
1820

1921
static void devm_pci_epc_release(struct device *dev, void *res)
2022
{
@@ -60,7 +62,7 @@ struct pci_epc *pci_epc_get(const char *epc_name)
6062
struct device *dev;
6163
struct class_dev_iter iter;
6264

63-
class_dev_iter_init(&iter, pci_epc_class, NULL, NULL);
65+
class_dev_iter_init(&iter, &pci_epc_class, NULL, NULL);
6466
while ((dev = class_dev_iter_next(&iter))) {
6567
if (strcmp(epc_name, dev_name(dev)))
6668
continue;
@@ -893,7 +895,7 @@ __pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
893895
INIT_LIST_HEAD(&epc->pci_epf);
894896

895897
device_initialize(&epc->dev);
896-
epc->dev.class = pci_epc_class;
898+
epc->dev.class = &pci_epc_class;
897899
epc->dev.parent = dev;
898900
epc->dev.release = pci_epc_release;
899901
epc->ops = ops;
@@ -953,20 +955,13 @@ EXPORT_SYMBOL_GPL(__devm_pci_epc_create);
953955

954956
static int __init pci_epc_init(void)
955957
{
956-
pci_epc_class = class_create("pci_epc");
957-
if (IS_ERR(pci_epc_class)) {
958-
pr_err("failed to create pci epc class --> %ld\n",
959-
PTR_ERR(pci_epc_class));
960-
return PTR_ERR(pci_epc_class);
961-
}
962-
963-
return 0;
958+
return class_register(&pci_epc_class);
964959
}
965960
module_init(pci_epc_init);
966961

967962
static void __exit pci_epc_exit(void)
968963
{
969-
class_destroy(pci_epc_class);
964+
class_unregister(&pci_epc_class);
970965
}
971966
module_exit(pci_epc_exit);
972967

0 commit comments

Comments
 (0)