]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commit
dmaengine: bcm2835: Use struct_size() in kzalloc()
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Fri, 4 Jan 2019 18:30:34 +0000 (12:30 -0600)
committerVinod Koul <vkoul@kernel.org>
Mon, 7 Jan 2019 12:35:17 +0000 (18:05 +0530)
commit5fde600537db4c61621783ae9d1c18f35e5e342c
tree6513143d708c36448932922c667a2a69387e8b96
parentde2c45314d9bb8839f226dcf989b2582591921f5
dmaengine: bcm2835: 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;
    void *entry[];
};

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

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

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

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/bcm2835-dma.c