libbpf: fix perf_buffer__free() API for sparse allocs
Subsystems (4)
PATCH 1/1 libbpf: fix perf_buffer__free() API for sparse allocs
In case the cpu_bufs are sparsely allocated they are not all free'ed. These changes will fix this.
--- tools/lib/bpf/libbpf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +4 -1
@@ -8137,9 +8137,12 @@ void perf_buffer__free(struct perf_buffer *pb)if (!pb)return ;if (pb->cpu_bufs) { -for (i =0 ; i < pb->cpu_cnt && pb->cpu_bufs[i]; i++) { +for (i =0 ; i < pb->cpu_cnt; i++) {struct perf_cpu_buf *cpu_buf = pb->cpu_bufs[i]; +if (!cpu_buf) +continue ; +bpf_map_delete_elem (pb->map_fd, &cpu_buf->map_key);perf_buffer__free_cpu_buf (pb, cpu_buf); }
Quoted 6 lines · Eelco Chaudron
In case the
cpu_bufsare sparsely allocated they are not all free'ed. These changes will fix this.Signed-off-by Eelco Chaudron <[email protected]>---
Thanks a lot!
You forgot:
Quoted 22 lines
tools/lib/bpf/libbpf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/lib/bpf/libbpf.c +4
-1@@ -8137,9 +8137,12 @@ void perf_buffer__free(struct perf_buffer *pb)if (!pb)return ;if (pb->cpu_bufs) { -for (i =0 ; i < pb->cpu_cnt && pb->cpu_bufs[i]; i++) { +for (i =0 ; i < pb->cpu_cnt; i++) {struct perf_cpu_buf *cpu_buf = pb->cpu_bufs[i]; +if (!cpu_buf) +continue ; +bpf_map_delete_elem (pb->map_fd, &cpu_buf->map_key);perf_buffer__free_cpu_buf (pb, cpu_buf); }
Quoted 5 lines · Andrii Nakryiko
Quoted 4 lines · Eelco Chaudron
In case the
cpu_bufsare sparsely allocated they are not all free'ed. These changes will fix this.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Eelco Chaudron <[email protected]>---
Thanks a lot!
You forgot:
Fixes fb84b8224655 ("libbpf: add perf buffer API")
Thanks, I forgot that :( Daniel do you want me to send a v2, or will you add it when you apply it?
Quoted 27 lines
Acked-by Andrii Nakryiko <[email protected]>Quoted 25 lines
tools/lib/bpf/libbpf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/lib/bpf/libbpf.c +4
-1@@ -8137,9 +8137,12 @@ void perf_buffer__free(struct perf_buffer *pb)if (!pb)return ;if (pb->cpu_bufs) { -for (i =0 ; i < pb->cpu_cnt && pb->cpu_bufs[i]; i++) { +for (i =0 ; i < pb->cpu_cnt; i++) {struct perf_cpu_buf *cpu_buf = pb->cpu_bufs[i]; +if (!cpu_buf) +continue ; + bpf_map_delete_elem(pb->map_fd,&cpu_buf->map_key); perf_buffer__free_cpu_buf(pb, cpu_buf); }
Daniel Borkmann
maintainerQuoted 10 lines · Eelco Chaudron
Quoted 9 lines · Andrii Nakryiko
Quoted 6 lines · Eelco Chaudron
In case the
cpu_bufsare sparsely allocated they are not all free'ed. These changes will fix this.Signed-off-by Eelco Chaudron <[email protected]>---
Quoted 8 lines
Quoted 5 lines
Thanks a lot!
You forgot:
Fixes fb84b8224655 ("libbpf: add perf buffer API")Thanks, I forgot that :( Daniel do you want me to send a v2, or will you add it when you apply it?
No worries, added it. Applied to bpf-next, thanks!