Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753047AbdHQM6G convert rfc822-to-8bit (ORCPT ); Thu, 17 Aug 2017 08:58:06 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:34213 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752516AbdHQM6E (ORCPT ); Thu, 17 Aug 2017 08:58:04 -0400 Date: Thu, 17 Aug 2017 14:57:51 +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: <20170817145751.2715eba4@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: 1159 Lines: 42 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 > Applied to l2-mtd/master. Thanks, Boris > Signed-off-by: Gustavo A. R. Silva > --- > 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))) {