lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <68cc0bb5-0d76-67b2-6d96-d46c0fd09551@gmail.com>
Date:   Fri, 30 Aug 2019 22:29:39 +0200
From:   Jacek Anaszewski <jacek.anaszewski@...il.com>
To:     "Gustavo A. R. Silva" <gustavo@...eddedor.com>,
        Pavel Machek <pavel@....cz>, Dan Murphy <dmurphy@...com>
Cc:     linux-leds@...r.kernel.org, linux-kernel@...r.kernel.org,
        Kees Cook <keescook@...omium.org>
Subject: Re: [PATCH] leds: is31fl32xx: Use struct_size() helper

Hi Gustavo,

Thank you for the patch.

On 8/30/19 8:14 PM, Gustavo A. R. Silva wrote:
> One of the more common cases of allocation size calculations is finding
> the size of a structure that has a zero-sized array at the end, along
> with memory for some number of elements for that array. For example:
> 
> struct is31fl32xx_priv {
> 	...
>         struct is31fl32xx_led_data leds[0];
> };
> 
> Make use of the struct_size() helper instead of an open-coded version
> in order to avoid any potential type mistakes.
> 
> So, replace the following function:
> 
> static inline size_t sizeof_is31fl32xx_priv(int num_leds)
> {
>        return sizeof(struct is31fl32xx_priv) +
>                      (sizeof(struct is31fl32xx_led_data) * num_leds);
> }
> 
> with:
> 
> struct_size(priv, leds, count)
> 
> This code was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@...eddedor.com>
> ---
>  drivers/leds/leds-is31fl32xx.c | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)
> 
> diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c
> index 6fbab70dfb04..6f29b8943913 100644
> --- a/drivers/leds/leds-is31fl32xx.c
> +++ b/drivers/leds/leds-is31fl32xx.c
> @@ -324,12 +324,6 @@ static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv)
>  	return 0;
>  }
>  
> -static inline size_t sizeof_is31fl32xx_priv(int num_leds)
> -{
> -	return sizeof(struct is31fl32xx_priv) +
> -		      (sizeof(struct is31fl32xx_led_data) * num_leds);
> -}
> -
>  static int is31fl32xx_parse_child_dt(const struct device *dev,
>  				     const struct device_node *child,
>  				     struct is31fl32xx_led_data *led_data)
> @@ -450,7 +444,7 @@ static int is31fl32xx_probe(struct i2c_client *client,
>  	if (!count)
>  		return -EINVAL;
>  
> -	priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count),
> +	priv = devm_kzalloc(dev, struct_size(priv, leds, count),
>  			    GFP_KERNEL);
>  	if (!priv)
>  		return -ENOMEM;
> 

Applied.

-- 
Best regards,
Jacek Anaszewski

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ