diff mbox series

pci: endpoint: fix a potential NULL pointer dereference

Message ID 20190315050711.8652-1-kjlu@umn.edu
State Accepted
Delegated to: Lorenzo Pieralisi
Headers show
Series pci: endpoint: fix a potential NULL pointer dereference | expand

Commit Message

Kangjie Lu March 15, 2019, 5:07 a.m. UTC
In case alloc_workqueue, the fix returns -ENOMEM to avoid
potential NULL pointer dereferences.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Lorenzo Pieralisi April 12, 2019, 2:41 p.m. UTC | #1
On Fri, Mar 15, 2019 at 12:07:10AM -0500, Kangjie Lu wrote:
> In case alloc_workqueue, the fix returns -ENOMEM to avoid
> potential NULL pointer dereferences.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
>  drivers/pci/endpoint/functions/pci-epf-test.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
> index 3e86fa3c7da3..dc610eb1543a 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-test.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-test.c
> @@ -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
diff mbox series

Patch

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index 3e86fa3c7da3..dc610eb1543a 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -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);