]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commit
iwlwifi: mvm: d3: use struct_size() in kzalloc()
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Fri, 24 Aug 2018 01:15:40 +0000 (20:15 -0500)
committerKalle Valo <kvalo@codeaurora.org>
Thu, 20 Dec 2018 07:10:26 +0000 (09:10 +0200)
commit83ea00d6873fd7a6b7e94cf40f6dd0007593fb1e
tree41887f7c1bccbd6b764fbaea6792f2fac840b955
parentb71a9c35f214dbd9e9e33d36219bd0383f861677
iwlwifi: mvm: d3: 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 issue was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/intel/iwlwifi/mvm/d3.c