]> git.proxmox.com Git - mirror_ovs.git/commit
datapath: meter: Use struct_size() in kzalloc()
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Wed, 27 Mar 2019 17:14:00 +0000 (10:14 -0700)
committerBen Pfaff <blp@ovn.org>
Tue, 16 Apr 2019 20:58:19 +0000 (13:58 -0700)
commitf72469405eec9505cf99b1fa599ed0cf0fc595b0
treedcd757eb39b0b4c0b93fe43da4ab02c1150db28d
parent30572df86b50bcb2fb24583169118625c3911d22
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>
acinclude.m4
datapath/linux/Modules.mk
datapath/linux/compat/include/linux/mm.h [new file with mode: 0644]
datapath/linux/compat/include/linux/overflow.h [new file with mode: 0644]
datapath/meter.c