slimbus: fix a potential NULL pointer dereference in of_qcom_slim_ngd_register
authorKangjie Lu <kjlu@umn.edu>
Sat, 13 Apr 2019 10:34:47 +0000 (11:34 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Apr 2019 20:23:06 +0000 (22:23 +0200)
In case platform_device_alloc fails, the fix returns an error
code to avoid the NULL pointer dereference.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/slimbus/qcom-ngd-ctrl.c

index 71f094c9ec6846a3fee3322b8f3976033479a937..f3585777324cf20e87a28d1dca15a941959eb136 100644 (file)
@@ -1342,6 +1342,10 @@ static int of_qcom_slim_ngd_register(struct device *parent,
                        return -ENOMEM;
 
                ngd->pdev = platform_device_alloc(QCOM_SLIM_NGD_DRV_NAME, id);
+               if (!ngd->pdev) {
+                       kfree(ngd);
+                       return -ENOMEM;
+               }
                ngd->id = id;
                ngd->pdev->dev.parent = parent;
                ngd->pdev->driver_override = QCOM_SLIM_NGD_DRV_NAME;