Skip to content

Commit

Permalink
bpf: pfc: Add handling for 0 syscalls in the binary tree
Browse files Browse the repository at this point in the history
Handle the unlikely case where a user has chosen the
binary tree optimization but has zero syscalls in their
filter.

Fixes: #370
Fixes: a3732b3 ("bpf:pfc: Add optimization option to use a binary tree")
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Acked-by: Paul Moore <paul@paul-moore.com>
  • Loading branch information
drakenclimber committed Mar 18, 2022
1 parent 5731b3c commit 2de3b87
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/gen_bpf.c
Expand Up @@ -1348,6 +1348,9 @@ static int _get_bintree_levels(unsigned int syscall_cnt)
{
unsigned int i = 2, max_level = SYSCALLS_PER_NODE * 2;

if (syscall_cnt == 0)
return 0;

while (max_level < syscall_cnt) {
max_level <<= 1;
i++;
Expand Down
3 changes: 3 additions & 0 deletions src/gen_pfc.c
Expand Up @@ -275,6 +275,9 @@ static int _get_bintree_levels(unsigned int syscall_cnt,
/* Only use a binary tree if requested */
return 0;

if (syscall_cnt == 0)
return 0;

do {
max_level = SYSCALLS_PER_NODE << i;
i++;
Expand Down

0 comments on commit 2de3b87

Please sign in to comment.