• Gustavo A. R. Silva's avatar
    dm stripe: use struct_size() in kmalloc() · 8adeac3b
    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 stripe_c {
            ...
            struct stripe stripe[0];
    };
    
    In this case alloc_context() and dm_array_too_big() are removed and
    replaced by the direct use of the struct_size() helper in kmalloc().
    
    Notice that open-coded form is prone to type mistakes.
    
    This code was detected with the help of Coccinelle.
    Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
    Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
    8adeac3b
dm-stripe.c 11.9 KB