From: Gustavo A. R. Silva Date: Thu, 6 Jul 2017 22:25:50 +0000 (-0500) Subject: mtd: spear_smi: add NULL check on devm_kzalloc() return value X-Git-Tag: v4.14-rc1~73^2~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=90cc62f3431b558ea10b0248e3ba85f656bf61f5;p=platform%2Fkernel%2Flinux-exynos.git mtd: spear_smi: add NULL check on devm_kzalloc() return value Check return value from call to devm_kzalloc() in order to prevent a NULL pointer dereference. This issue was detected using Coccinelle and the following semantic patch: @@ expression x; identifier fld; @@ * x = devm_kzalloc(...); ... when != x == NULL x->fld Signed-off-by: Gustavo A. R. Silva Signed-off-by: Boris Brezillon --- diff --git a/drivers/mtd/devices/spear_smi.c b/drivers/mtd/devices/spear_smi.c index dd50698..ddf4789 100644 --- a/drivers/mtd/devices/spear_smi.c +++ b/drivers/mtd/devices/spear_smi.c @@ -775,6 +775,8 @@ static int spear_smi_probe_config_dt(struct platform_device *pdev, pdata->board_flash_info = devm_kzalloc(&pdev->dev, sizeof(*pdata->board_flash_info), GFP_KERNEL); + if (!pdata->board_flash_info) + return -ENOMEM; /* Fill structs for each subnode (flash device) */ while ((pp = of_get_next_child(np, pp))) {