From: Alexei Starovoitov Date: Thu, 6 Jul 2023 03:34:35 +0000 (-0700) Subject: bpf: Simplify code of destroy_mem_alloc() with kmemdup(). X-Git-Tag: v6.6.17~4098^2~405^2~6^2~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a80672d7e10edab757e771a1864ea2e1b9a31ac9;p=platform%2Fkernel%2Flinux-rpi.git bpf: Simplify code of destroy_mem_alloc() with kmemdup(). Use kmemdup() to simplify the code. Signed-off-by: Alexei Starovoitov Signed-off-by: Daniel Borkmann Acked-by: Hou Tao Link: https://lore.kernel.org/bpf/20230706033447.54696-3-alexei.starovoitov@gmail.com --- diff --git a/kernel/bpf/memalloc.c b/kernel/bpf/memalloc.c index cc5b8ad..b001121 100644 --- a/kernel/bpf/memalloc.c +++ b/kernel/bpf/memalloc.c @@ -499,7 +499,7 @@ static void destroy_mem_alloc(struct bpf_mem_alloc *ma, int rcu_in_progress) return; } - copy = kmalloc(sizeof(*ma), GFP_KERNEL); + copy = kmemdup(ma, sizeof(*ma), GFP_KERNEL); if (!copy) { /* Slow path with inline barrier-s */ 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 */ - copy->cache = ma->cache; - ma->cache = NULL; - copy->caches = ma->caches; - ma->caches = NULL; + memset(ma, 0, sizeof(*ma)); INIT_WORK(©->work, free_mem_alloc_deferred); queue_work(system_unbound_wq, ©->work); }