Skip to content

Commit a80672d

Browse files
Alexei Starovoitovborkmann
authored andcommitted
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
1 parent 12c8d0f commit a80672d

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

kernel/bpf/memalloc.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -499,18 +499,15 @@ static void destroy_mem_alloc(struct bpf_mem_alloc *ma, int rcu_in_progress)
499499
return;
500500
}
501501

502-
copy = kmalloc(sizeof(*ma), GFP_KERNEL);
502+
copy = kmemdup(ma, sizeof(*ma), GFP_KERNEL);
503503
if (!copy) {
504504
/* Slow path with inline barrier-s */
505505
free_mem_alloc(ma);
506506
return;
507507
}
508508

509509
/* Defer barriers into worker to let the rest of map memory to be freed */
510-
copy->cache = ma->cache;
511-
ma->cache = NULL;
512-
copy->caches = ma->caches;
513-
ma->caches = NULL;
510+
memset(ma, 0, sizeof(*ma));
514511
INIT_WORK(&copy->work, free_mem_alloc_deferred);
515512
queue_work(system_unbound_wq, &copy->work);
516513
}

0 commit comments

Comments
 (0)