• Gustavo A. R. Silva's avatar
    leds: is31fl32xx: Use struct_size() helper · 1669ec78
    Gustavo A. R. Silva authored
    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: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
    Acked-by: default avatarPavel Machek <pavel@ucw.cz>
    Signed-off-by: default avatarJacek Anaszewski <jacek.anaszewski@gmail.com>
    1669ec78
leds-is31fl32xx.c 13.2 KB