mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-08 21:22:09 -04:00
cxgb3/l2t: Use struct_size() in kvzalloc()
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 = kvzalloc(size, GFP_KERNEL);
Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:
instance = kvzalloc(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: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
7649773293
commit
db4863fdb8
1 changed files with 2 additions and 2 deletions
|
|
@ -443,9 +443,9 @@ found:
|
|||
struct l2t_data *t3_init_l2t(unsigned int l2t_capacity)
|
||||
{
|
||||
struct l2t_data *d;
|
||||
int i, size = sizeof(*d) + l2t_capacity * sizeof(struct l2t_entry);
|
||||
int i;
|
||||
|
||||
d = kvzalloc(size, GFP_KERNEL);
|
||||
d = kvzalloc(struct_size(d, l2tab, l2t_capacity), GFP_KERNEL);
|
||||
if (!d)
|
||||
return NULL;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue