diff options
author | Gustavo A. R. Silva <gustavo@embeddedor.com> | 2019-04-03 10:51:10 -0700 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2019-04-03 16:10:40 -0700 |
commit | ecdf3a965826d8d900a747f0650acb172191dc9b (patch) | |
tree | b39ab4b9bc9212a38f7901e09a959e2806baf98d /include | |
parent | 6d3a41ab0c37320068e28e1f9b45e4304bb30db0 (diff) |
Input: evdev - use struct_size() in kzalloc() and vzalloc()
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:
instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
Notice that, in this case, variable size is not necessary, hence
it is removed.
This code was detected with the help of Coccinelle.
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'include')
0 files changed, 0 insertions, 0 deletions