mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	bpf: Simplify code of destroy_mem_alloc() with kmemdup().
Use kmemdup() to simplify the code. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Hou Tao <houtao1@huawei.com> Link: https://lore.kernel.org/bpf/20230706033447.54696-3-alexei.starovoitov@gmail.com
This commit is contained in:
		
							parent
							
								
									12c8d0f4c8
								
							
						
					
					
						commit
						a80672d7e1
					
				
					 1 changed files with 2 additions and 5 deletions
				
			
		| 
						 | 
					@ -499,7 +499,7 @@ static void destroy_mem_alloc(struct bpf_mem_alloc *ma, int rcu_in_progress)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	copy = kmalloc(sizeof(*ma), GFP_KERNEL);
 | 
						copy = kmemdup(ma, sizeof(*ma), GFP_KERNEL);
 | 
				
			||||||
	if (!copy) {
 | 
						if (!copy) {
 | 
				
			||||||
		/* Slow path with inline barrier-s */
 | 
							/* Slow path with inline barrier-s */
 | 
				
			||||||
		free_mem_alloc(ma);
 | 
							free_mem_alloc(ma);
 | 
				
			||||||
| 
						 | 
					@ -507,10 +507,7 @@ static void destroy_mem_alloc(struct bpf_mem_alloc *ma, int rcu_in_progress)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Defer barriers into worker to let the rest of map memory to be freed */
 | 
						/* Defer barriers into worker to let the rest of map memory to be freed */
 | 
				
			||||||
	copy->cache = ma->cache;
 | 
						memset(ma, 0, sizeof(*ma));
 | 
				
			||||||
	ma->cache = NULL;
 | 
					 | 
				
			||||||
	copy->caches = ma->caches;
 | 
					 | 
				
			||||||
	ma->caches = NULL;
 | 
					 | 
				
			||||||
	INIT_WORK(©->work, free_mem_alloc_deferred);
 | 
						INIT_WORK(©->work, free_mem_alloc_deferred);
 | 
				
			||||||
	queue_work(system_unbound_wq, ©->work);
 | 
						queue_work(system_unbound_wq, ©->work);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue