Skip to content

Commit eee4b2b

Browse files
twilfredol1k
authored andcommitted
PCI/CMA: Fixup init race
It appears when `device_initcall()` is used to invoke `pci_cma_keyring_init()`, there exists a race between pci_cma_keyring_init() and pci_cma_init(). Running through QEMU pci_cma_init() is always called first and thus eventually leads to a NULL ptr dereference as spdm_create() is called before pci_cma_keyring is initialized. This fix ammends that. Signed-off-by: Wilfred Mallawa <[email protected]>
1 parent 1669cd1 commit eee4b2b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/pci/cma.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ void pci_cma_init(struct pci_dev *pdev)
5959
if (!doe)
6060
return;
6161

62+
if (!pci_cma_keyring) {
63+
pr_err("Keyring not initialized");
64+
return;
65+
}
66+
6267
pdev->spdm_state = spdm_create(&pdev->dev, pci_doe_transport, doe,
6368
PCI_DOE_MAX_PAYLOAD, pci_cma_keyring,
6469
pci_cma_validate);
@@ -143,9 +148,11 @@ __init static int pci_cma_keyring_init(void)
143148
KEY_USR_WRITE | KEY_USR_SEARCH,
144149
KEY_ALLOC_NOT_IN_QUOTA |
145150
KEY_ALLOC_SET_KEEP, NULL, NULL);
146-
if (IS_ERR(pci_cma_keyring))
151+
if (IS_ERR(pci_cma_keyring)) {
147152
pr_err("Could not allocate keyring\n");
153+
return PTR_ERR(pci_cma_keyring);
154+
}
148155

149156
return 0;
150157
}
151-
device_initcall(pci_cma_keyring_init);
158+
subsys_initcall(pci_cma_keyring_init);

0 commit comments

Comments
 (0)