datapath: meter: Use struct_size() in kzalloc()
Upstream commit:
commit
c5c3899de09e307e3a0999ab8d620ab0ede05aa1
Author: Gustavo A. R. Silva <gustavo@embeddedor.com>
Date: Tue Jan 15 15:19:17 2019 -0600
openvswitch: meter: 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;
struct boo entry[];
};
instance = kzalloc(sizeof(struct foo) + count * sizeof(struct boo), 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 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>
Use of struct_size() needed some compat layer adjustments to make use
of this new macro. This patch pulls in some of the needed support
from the linux mm.h and overflow.h header files. This new header
file support is also necessary for the following patch that converts
to use of kvmalloc().
Cc: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Greg Rose <gvrose8192@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>