summaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorHou Tao <houtao1@huawei.com>2023-01-18 16:46:30 +0800
committerAlexei Starovoitov <ast@kernel.org>2023-01-18 18:36:26 -0800
commit36024d023d139a0c8b552dc3b7f4dc7b4c139e8f (patch)
treed9b467655efdc282615f11275f5783dea4561c86 /kernel
parentb9fb10d131b8c84af9bb14e2078d5c63600c7dea (diff)
downloadlinux-36024d023d139a0c8b552dc3b7f4dc7b4c139e8f.tar.gz
linux-36024d023d139a0c8b552dc3b7f4dc7b4c139e8f.tar.bz2
linux-36024d023d139a0c8b552dc3b7f4dc7b4c139e8f.zip
bpf: Fix off-by-one error in bpf_mem_cache_idx()
According to the definition of sizes[NUM_CACHES], when the size passed to bpf_mem_cache_size() is 256, it should return 6 instead 7. Fixes: 7c8199e24fa0 ("bpf: Introduce any context BPF specific memory allocator.") Signed-off-by: Hou Tao <houtao1@huawei.com> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/r/20230118084630.3750680-1-houtao@huaweicloud.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/bpf/memalloc.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/kernel/bpf/memalloc.c b/kernel/bpf/memalloc.c
index ebcc3dd0fa19..1db156405b68 100644
--- a/kernel/bpf/memalloc.c
+++ b/kernel/bpf/memalloc.c
@@ -71,7 +71,7 @@ static int bpf_mem_cache_idx(size_t size)
if (size <= 192)
return size_index[(size - 1) / 8] - 1;
- return fls(size - 1) - 1;
+ return fls(size - 1) - 2;
}
#define NUM_CACHES 11