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

From Stafford Horne <shorne@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH] pinctrl: imx: Check for memory allocation failure
Date 2017-05-06 21:50 +0200
Message-ID <tEdSh-3MB-5@gated-at.bofh.it> (permalink)
References <tE3gd-5Fp-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | 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