Fixes: 14a324f6a67e ("bpf: Wire up freeing of referenced kptr")
PATCH 1/1 Fixes: 14a324f6a67e ("bpf: Wire up freeing of referenced kptr")
This patch fixes a warning generated by Sparse
"warning: Using plain integer as NULL pointer"
by replacing p with *p in the WRITE_ONCE() macro
This enables the pointer to be cleared on map value delete, hence clearing the warning.
--- kernel/bpf/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/syscall.c +1 -1
@@ -598,7 +598,7 @@ void bpf_map_free_kptrs(struct bpf_map *map, void *map_value)if (off_desc->type ==BPF_KPTR_UNREF ) {u64 *p = (u64 *)btf_id_ptr; -WRITE_ONCE (p,0 ); +WRITE_ONCE (*p,0 );continue ; } old_ptr =xchg (btf_id_ptr,0 );
Signature · 1 line
2.35.1
Kumar Kartikeya Dwivedi
maintainerQuoted 5 lines · Jules Irenge
This patch fixes a warning generated by Sparse
"warning: Using plain integer as NULL pointer"
Quoted 7 lines
by replacing p with *p in the
WRITE_ONCE()macroThis enables the pointer to be cleared on map value delete, hence clearing the warning.
Signed-off-by Jules Irenge <[email protected]>---
1. Always bump the version number when resending a patch
2. Fixes: ... tag needs to come before your SoB.
3. The headline can instead be [PATCH bpf-next vN] bpf: Fix resetting logic for unreferenced kptrs
where N is your version number.
4. Commit message needs more work. Apart from what you have specified about sparse, it can be:
During the process of fixing this warning, it was discovered that the current code erroneously writes to the pointer variable instead dereferencing and writing to the actual kptr. Hence, the sparse tool accidently helped tp uncover this problem. Fix this by doing WRITE_ONCE(*p, 0) instead of WRITE_ONCE(p, 0). Note that the effect of this bug is that unreferenced kptrs won't be cleared during check_and_free_fields. It is not a problem if the clearing is not done during map_free stage, as there is nothing to free for them.
5. There is no requirement to Cc linux-kernel ML for BPF patches.
Quoted 19 lines
kernel/bpf/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/syscall.c +1
-2@@ -598,7 +598,7 @@ void bpf_map_free_kptrs(struct bpf_map *map, void *map_value)if (off_desc->type ==BPF_KPTR_UNREF ) {u64 *p = (u64 *)btf_id_ptr; -WRITE_ONCE (p,0 ); +WRITE_ONCE (*p,0 );continue ; } old_ptr =xchg (btf_id_ptr,0 ); --2.35.1
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 10 lines · On Sun, 4 Sep 2022 11:28:15 +0100 you wrote:
This patch fixes a warning generated by Sparse
"warning: Using plain integer as NULL pointer"
by replacing p with *p in the
WRITE_ONCE()macroThis enables the pointer to be cleared on map value delete, hence clearing the warning.
[...]
Here is the summary with links:
- [bpf-next] Fixes: 14a324f6a67e ("bpf: Wire up freeing of referenced kptr")
https://git.kernel.org/bpf/bpf-next/c/9fad7fe5b298
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html