]> asedeno.scripts.mit.edu Git - linux.git/commit
qtnfmac: replace qtnf_cmd_acl_data_size() with struct_size()
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Wed, 3 Apr 2019 17:02:36 +0000 (12:02 -0500)
committerKalle Valo <kvalo@codeaurora.org>
Thu, 4 Apr 2019 16:38:36 +0000 (19:38 +0300)
commit95336d4cb588860283047e01050ae41993e0147d
treec926ac9bcd1f72c6851b15ea9ef3a31bef02df9e
parent38bb0baea310fc4b5897ec47b1546bc989b33663
qtnfmac: replace qtnf_cmd_acl_data_size() with struct_size()

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 qtnf_cmd_acl_data_size() with the
new struct_size() helper.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: Sergey Matyukevich <sergey.matyukevich.os@quantenna.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/quantenna/qtnfmac/commands.c