Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751492AbdGQUtt convert rfc822-to-8bit (ORCPT ); Mon, 17 Jul 2017 16:49:49 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:35221 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751317AbdGQUtr (ORCPT ); Mon, 17 Jul 2017 16:49:47 -0400 Date: Mon, 17 Jul 2017 22:49:35 +0200 From: Boris Brezillon To: "Gustavo A. R. Silva" Cc: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Cyrille Pitchen , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mtd: spear_smi: add NULL check on devm_kzalloc() return value Message-ID: <20170717224935.4dd40ba0@bbrezillon> In-Reply-To: <20170706222550.GA30998@embeddedgus> References: <20170706222550.GA30998@embeddedgus> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1180 Lines: 38 Le Thu, 6 Jul 2017 17:25:50 -0500, "Gustavo A. R. Silva" a écrit : > 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 Acked-by: Boris Brezillon > --- > drivers/mtd/devices/spear_smi.c | 2 ++ > 1 file changed, 2 insertions(+) > > 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))) {