Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1636972

Re: [PATCH] pinctrl: imx: Check for memory allocation failure

Path csiph.com!news.redatomik.org!aioe.org!bofh.it!news.nic.it!robomod
From Stafford Horne <shorne@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH] pinctrl: imx: Check for memory allocation failure
Date Sat, 06 May 2017 21:50:01 +0200
Message-ID <tEdSh-3MB-5@gated-at.bofh.it> (permalink)
References <tE3gd-5Fp-3@gated-at.bofh.it>
X-Original-To Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=dofmRXafUKXsM7eGtEaR80gc50QwzimJ4t9rLz0HPNM=; b=sropkBr/7SPWYY6ei7JwevFK+r1NUTrFB6WnWqlAHcujIKgn3e4bsEvbxsqAwDq5dn vSRBFSyjE6zS5uF4z1IynqXLh2EvNWFYCCaJz2Y/0N9eNM7UVx2cWKz5CsNmoaxIG2c1 tpjaJW3+pnPYuVhCRvZq0N16lWVFhUIDXEWk2qqV+OcM5o4aKQQNFLnhLwuRczKfpojF LBhh4UHAb2e6/jXsWq+Oei4uheoR5nVhuJnqv0CKbDEBwKx5jgwJg4cDWQzWwAmZnPzk 7N3K1wLRv21sYb2h/8D4J9403X9/ijVaUudNLgOj5I5atZQOqkDDPC/6OJfZZoiHhG+K Dl6Q==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=dofmRXafUKXsM7eGtEaR80gc50QwzimJ4t9rLz0HPNM=; b=FdIM8HlHiUvXglxiie2M5J/TxWyXeoA6OXfRLeNSJ3geRRmKYJJ7LRdkQ6m+8iUajj ktJEsfbCcJ6YB/G4aSOUumMMzmF1A5DbKv+hq4jIYVilkfFzhlpqoxTADxwbMO2boCwg fGybN7bHLItFlnjCTdyZzH38ycxw0VHn9XDKhAw0onk06iTgwRn+kiKFGBE88llHGg2a /9vlboEZ8C8covToyDZEzHf3yglNh8SKikgmC2d9OlKPpwkAmhNus9bgF5YRdHswSMXt JQcwB3DBTsEFBZdwfICs8Wt+rbXD62AeqOuV/GsAVSCo1vCprRpMdUc6I7/2aRZfvq4U Xdlg==
X-Gm-Message-State AN3rC/68z7zkwvgD2Q79VNVAc4uMiB3ms6wgHtZRe60N5Hm24v3Ws9vt pB0HVXbSoEGSlC97sRU=
X-Received by 10.84.217.215 with SMTP id d23mr41534921plj.114.1494099640317; Sat, 06 May 2017 12:40:40 -0700 (PDT)
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.8.0 (2017-02-23)
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 41
Organization linux.* mail to news gateway
X-Original-Cc linus.walleij@linaro.org, gary.bisson@boundarydevices.com, vladimir_zapolskiy@mentor.com, tony@atomide.com, vivien.didelot@savoirfairelinux.com, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
X-Original-Date Sun, 7 May 2017 04:40:38 +0900
X-Original-Message-ID <20170506194038.GI17317@lianli.shorne-pla.net>
X-Original-References <20170506082359.6736-1-christophe.jaillet@wanadoo.fr>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1636972

Show key headers only | View raw


Hi Christophe,

On Sat, May 06, 2017 at 10:23:59AM +0200, Christophe JAILLET wrote:
> If 'devm_kzalloc' fails, a NULL pointer will be dereferenced.
> Return -ENOMEM instead, as done for the other memory allocation just a
> few lines below.

This looks fine.

> BTW, change the 'devm_kzalloc' into a 'devm_kcalloc'.

Any reason for the devm_kcalloc change?  It looks like the next for loop
does set all of the group_name values.

-Stafford

> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/pinctrl/freescale/pinctrl-imx.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
> index 74bd90dfd7b1..90a946c028ff 100644
> --- a/drivers/pinctrl/freescale/pinctrl-imx.c
> +++ b/drivers/pinctrl/freescale/pinctrl-imx.c
> @@ -581,9 +581,10 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
>  		dev_err(info->dev, "no groups defined in %s\n", np->full_name);
>  		return -EINVAL;
>  	}
> -	func->group_names = devm_kzalloc(info->dev,
> -					 func->num_group_names *
> +	func->group_names = devm_kcalloc(info->dev, func->num_group_names,
>  					 sizeof(char *), GFP_KERNEL);
> +	if (!func->group_names)
> +		return -ENOMEM;
>  
>  	for_each_child_of_node(np, child) {
>  		func->group_names[i] = child->name;
> -- 
> 2.11.0
> 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] pinctrl: imx: Check for memory allocation failure Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-05-06 10:30 +0200
  Re: [PATCH] pinctrl: imx: Check for memory allocation failure Stafford Horne <shorne@gmail.com> - 2017-05-06 21:50 +0200
    Re: [PATCH] pinctrl: imx: Check for memory allocation failure Dan Carpenter <dan.carpenter@oracle.com> - 2017-05-09 09:30 +0200
      Re: [PATCH] pinctrl: imx: Check for memory allocation failure Stafford Horne <shorne@gmail.com> - 2017-05-09 14:40 +0200

csiph-web