lkml.org 
[lkml]   [2019]   [Sep]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] leds: is31fl32xx: Use struct_size() helper
On Fri 2019-08-30 13:14:48, 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@embeddedor.com>

Acked-by: Pavel Machek <pavel@ucw.cz>
Pavel

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2019-09-01 12:27    [W:0.036 / U:3.804 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site