Gustavo A. R. Silva 402096cb5b dmaengine: stm32-dma: Use struct_size() helper
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 stm32_dma_desc {
	...
        struct stm32_dma_sg_req sg_req[];
};

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 struct stm32_dma_desc *stm32_dma_alloc_desc(u32 num_sgs)
{
       return kzalloc(sizeof(struct stm32_dma_desc) +
                      sizeof(struct stm32_dma_sg_req) * num_sgs, GFP_NOWAIT);
}

with:

kzalloc(struct_size(desc, sg_req, num_sgs), GFP_NOWAIT)

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Link: https://lore.kernel.org/r/20190830161423.GA3483@embeddedor
Signed-off-by: Vinod Koul <vkoul@kernel.org>
2019-09-04 10:25:08 +05:30
..
2019-07-09 10:59:26 -07:00
2019-07-18 11:05:25 -07:00
2019-07-19 17:13:56 -07:00
2019-07-18 09:49:30 +02:00
2019-07-18 09:49:30 +02:00
2019-07-19 17:13:56 -07:00
2019-07-19 12:29:43 -07:00
2019-07-15 09:42:32 -07:00
2019-07-19 17:13:56 -07:00
2019-07-20 10:04:58 -07:00
2019-07-09 08:59:39 -07:00
2019-07-13 16:08:36 -07:00
2019-07-20 09:34:55 -07:00
2019-07-11 18:11:21 -07:00
2019-07-11 15:14:01 -07:00
2019-07-15 20:18:40 -07:00
2019-07-11 18:11:21 -07:00
2019-07-15 21:20:52 -07:00
2019-07-15 20:44:49 -07:00
2019-07-15 09:20:27 -03:00
2019-07-09 08:57:45 -07:00
2019-07-15 20:18:40 -07:00
2019-07-17 11:44:41 -07:00
2019-07-19 17:13:56 -07:00
2019-07-17 10:03:50 -07:00
2019-07-20 10:04:58 -07:00
2019-07-20 10:04:58 -07:00
2019-07-19 17:19:24 -07:00
2019-07-05 08:15:08 +02:00
2019-07-16 12:21:41 -07:00
2019-07-11 15:14:01 -07:00
2019-07-19 17:05:08 -07:00
2019-07-17 11:23:13 -07:00
2019-07-16 09:25:04 -07:00
2019-07-19 11:41:26 -07:00