crypto: qat - use struct_size() helper
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Thu, 6 Jun 2019 14:57:13 +0000 (09:57 -0500)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 13 Jun 2019 06:31:41 +0000 (14:31 +0800)
commit1793d1aba1941573ba9ebf75dfbb11a8c2b943b1
treef5fb556a4e5e654b39d79781c788494b069e4ca2
parent0b211338cf73eb7dd9a1c26721ce43076918373f
crypto: qat - 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 qat_alg_buf_list {
...
        struct qat_alg_buf bufers[];
} __packed __aligned(64);

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 form:

sizeof(struct qat_alg_buf_list) + ((1 + n) * sizeof(struct qat_alg_buf))

with:

struct_size(bufl, bufers, n + 1)

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/qat/qat_common/qat_algs.c