Patchwork slimbus: fix a NULL pointer dereference in of_qcom_slim_ngd_register

login
register
mail settings
Submitter Kangjie Lu
Date March 15, 2019, 6:20 a.m.
Message ID <20190315062048.16642-1-kjlu@umn.edu>
Download mbox | patch
Permalink /patch/749327/
State New
Headers show

Comments

Kangjie Lu - March 15, 2019, 6:20 a.m.
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>
---
 drivers/slimbus/qcom-ngd-ctrl.c | 4 ++++
 1 file changed, 4 insertions(+)
Srinivas Kandagatla - March 20, 2019, 2:52 p.m.
On 15/03/2019 06:20, Kangjie Lu wrote:
> 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>
> ---
>   drivers/slimbus/qcom-ngd-ctrl.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
Thanks Applied.

--srini

Patch

diff --git a/drivers/slimbus/qcom-ngd-ctrl.c b/drivers/slimbus/qcom-ngd-ctrl.c
index 71f094c9ec68..f3585777324c 100644
--- a/drivers/slimbus/qcom-ngd-ctrl.c
+++ b/drivers/slimbus/qcom-ngd-ctrl.c
@@ -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;