mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									433e7d3177
								
							
						
					
					
						commit
						e90342e6d2
					
				
					 1 changed files with 3 additions and 4 deletions
				
			
		| 
						 | 
					@ -4255,10 +4255,9 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg,
 | 
				
			||||||
	new->size = size;
 | 
						new->size = size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Copy thresholds (if any) to new array */
 | 
						/* Copy thresholds (if any) to new array */
 | 
				
			||||||
	if (thresholds->primary) {
 | 
						if (thresholds->primary)
 | 
				
			||||||
		memcpy(new->entries, thresholds->primary->entries, (size - 1) *
 | 
							memcpy(new->entries, thresholds->primary->entries,
 | 
				
			||||||
				sizeof(struct mem_cgroup_threshold));
 | 
							       flex_array_size(new, entries, size - 1));
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Add new threshold */
 | 
						/* Add new threshold */
 | 
				
			||||||
	new->entries[size - 1].eventfd = eventfd;
 | 
						new->entries[size - 1].eventfd = eventfd;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue