Skip to contentSkip to conversation

bpf: Call kfree(obj) only once in free_one()

PATCH Applied Markus Elfring 3 participants 3 messages Sep 26, 2024 – Sep 27, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: Call kfree(obj) only once in free_one()

From: Markus Elfring <[email protected]>
Date: Thu, 26 Sep 2024 13:30:42 +0200

A kfree() call is always used at the end of this function implementation. Thus specify such a function call only once instead of duplicating it in a previous if branch.

This issue was detected by using the Coccinelle software.

---
 kernel/bpf/memalloc.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
kernel/bpf/memalloc.c +1 -4
index b3858a76e0b3..1a1b4458114c 100644
@@ -252,11 +252,8 @@ static void alloc_bulk(struct bpf_mem_cache *c, int cnt, int node, bool atomic)
 
 static void free_one(void *obj, bool percpu)
 {
-	if (percpu) {
+	if (percpu)
 		free_percpu(((void __percpu **)obj)[1]);
-		kfree(obj);
-		return;
-	}
 
 	kfree(obj);
 }

--
2.46.1

maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 26 Sep 2024 13:30:42 +0200

A kfree() call is always used at the end of this function implementation. Thus specify such a function call only once instead of duplicating it in a previous if branch.

This issue was detected by using the Coccinelle software.

---

[...]

#2 lore raw
In reply to Markus Elfring
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 8 lines · On Thu, 26 Sep 2024 13:45:18 +0200 you wrote:

From: Markus Elfring <[email protected]>
Date: Thu, 26 Sep 2024 13:30:42 +0200

A kfree() call is always used at the end of this function implementation. Thus specify such a function call only once instead of duplicating it in a previous if branch.

[...]

Here is the summary with links:
- bpf: Call kfree(obj) only once in free_one()

    https://git.kernel.org/bpf/bpf-next/c/b295d70db5e1

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html