Skip to contentSkip to conversation

pci: endpoint: fix a potential NULL pointer dereference

PATCH In review Kangjie Lu 2 participants 2 messages Mar 15, 2019 – Apr 12, 2019

Subsystems (2)
lore
Share & tools
lore

Kangjie Lu

author
#0 lore raw

PATCH 1/1 pci: endpoint: fix a potential NULL pointer dereference

In case alloc_workqueue, the fix returns -ENOMEM to avoid potential NULL pointer dereferences.

---
 drivers/pci/endpoint/functions/pci-epf-test.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/endpoint/functions/pci-epf-test.c +4 -0
index 3e86fa3c7da3..dc610eb1543a 100644
@@ -570,6 +570,10 @@ static int __init pci_epf_test_init(void)
 
 	kpcitest_workqueue = alloc_workqueue("kpcitest",
 					     WQ_MEM_RECLAIM | WQ_HIGHPRI, 0);
+	if (unlikely(!kpcitest_workqueue)) {
+		pr_err("Failed to allocate the kpcitest work queue\n");
+		return -ENOMEM;
+	}
 	ret = pci_epf_register_driver(&test_driver);
 	if (ret) {
 		pr_err("Failed to register pci epf test driver --> %d\n", ret);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 13 lines · Kangjie Lu

In case alloc_workqueue, the fix returns -ENOMEM to avoid potential NULL pointer dereferences.

---
 drivers/pci/endpoint/functions/pci-epf-test.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/endpoint/functions/pci-epf-test.c +0 -0
index 3e86fa3c7da3..dc610eb1543a 100644

drivers/pci/endpoint/functions/pci-epf-test.c static int __init pci_epf_test_init(void) · line 579

Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-test.c +4 -0
@@ -570,6 +570,10 @@ static int __init pci_epf_test_init(void)
 
 	kpcitest_workqueue = alloc_workqueue("kpcitest",
 					     WQ_MEM_RECLAIM | WQ_HIGHPRI, 0);
+	if (unlikely(!kpcitest_workqueue)) {
+		pr_err("Failed to allocate the kpcitest work queue\n");
+		return -ENOMEM;
+	}
 	ret = pci_epf_register_driver(&test_driver);
 	if (ret) {
 		pr_err("Failed to register pci epf test driver --> %d\n", ret);

Updated the code slighty and pushed out to pci/misc, thanks.

Lorenzo