diff options
author | Gustavo A. R. Silva | 2019-03-06 00:44:05 +0100 |
---|---|---|
committer | Linus Torvalds | 2019-03-06 06:07:15 +0100 |
commit | 67b8046f42f81aecfca97b50ec3b398bb0ee8e97 (patch) | |
tree | f9cc7e7e6d93b287c5df71c5d717ea0c1d451e37 /mm/filemap.c | |
parent | mm: remove extra drain pages on pcp list (diff) | |
download | kernel-qcow2-linux-67b8046f42f81aecfca97b50ec3b398bb0ee8e97.tar.gz kernel-qcow2-linux-67b8046f42f81aecfca97b50ec3b398bb0ee8e97.tar.xz kernel-qcow2-linux-67b8046f42f81aecfca97b50ec3b398bb0ee8e97.zip |
mm/memcontrol.c: use struct_size() in kmalloc()
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 = kmalloc(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 = kmalloc(struct_size(instance, entry, count), GFP_KERNEL);
This code was detected with the help of Coccinelle.
Link: http://lkml.kernel.org/r/20190104183726.GA6374@embeddedor
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/filemap.c')
0 files changed, 0 insertions, 0 deletions