]> asedeno.scripts.mit.edu Git - linux.git/commit
staging: ralink-gdma: Use struct_size() in kzalloc()
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Wed, 3 Apr 2019 20:50:43 +0000 (15:50 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 16 Apr 2019 11:44:30 +0000 (13:44 +0200)
commite291fa1237a74dc4692995a4a598d4818a747191
treed6a33a3c506686347065ba134e6bc659d2161b23
parent3b706841c29f1cf2f8f3484713288aa2c375677b
staging: ralink-gdma: Use struct_size() in kzalloc()

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 foo {
    int stuff;
    struct boo entry[];
};

size = sizeof(struct foo) + count * sizeof(struct boo);
instance = kzalloc(size, GFP_KERNEL)

Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:

size = struct_size(instance, entry, count);

or

instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL)

Based on the above, replace gdma_dma_alloc_desc() with kzalloc() and
use the new struct_size() helper.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/ralink-gdma/ralink-gdma.c