dm stripe: use struct_size() in kmalloc()
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Wed, 2 Oct 2019 19:03:41 +0000 (14:03 -0500)
committerMike Snitzer <snitzer@redhat.com>
Tue, 5 Nov 2019 19:09:59 +0000 (14:09 -0500)
commit8adeac3be03d400f9c2391d52f85cd27bd188800
treea6ed57219cb85a0474c904a93022c9001a2ed992
parent53be73a5d75f477e52c9275ed7aa9307a8b73e5c
dm stripe: use struct_size() in kmalloc()

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: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-stripe.c
include/linux/device-mapper.h