summaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorGustavo A. R. Silva <gustavoars@kernel.org>2020-10-13 16:52:36 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2020-10-13 18:38:30 -0700
commite90342e6d26ab6d1c38c8f5804492d76e3e9b4e9 (patch)
treea6ea984e58348fa5e45ba533338929aa06115d59 /mm
parent433e7d3177544c8cf0b6375abd310b0ef023fe9d (diff)
downloadlinux-e90342e6d26ab6d1c38c8f5804492d76e3e9b4e9.tar.bz2
mm: memcontrol: use flex_array_size() helper in memcpy()
Make use of the flex_array_size() helper to calculate the size of a flexible array member within an enclosing structure. This helper offers defense-in-depth against potential integer overflows, while at the same time makes it explicitly clear that we are dealing with a flexible array member. Also, remove unnecessary braces. Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Link: https://lkml.kernel.org/r/ddd60dae2d9aea1ccdd2be66634815c93696125e.1596214831.git.gustavoars@kernel.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/memcontrol.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index d8bdbe1e8ff8..e3565ec02401 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4255,10 +4255,9 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg,
new->size = size;
/* Copy thresholds (if any) to new array */
- if (thresholds->primary) {
- memcpy(new->entries, thresholds->primary->entries, (size - 1) *
- sizeof(struct mem_cgroup_threshold));
- }
+ if (thresholds->primary)
+ memcpy(new->entries, thresholds->primary->entries,
+ flex_array_size(new, entries, size - 1));
/* Add new threshold */
new->entries[size - 1].eventfd = eventfd;