BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: clean up ringbuf size adjustment implementation
@ 2022-05-10 18:51 Andrii Nakryiko
  2022-05-11 12:10 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Andrii Nakryiko @ 2022-05-10 18:51 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team, Nathan Chancellor

Drop unused iteration variable, move overflow prevention check into the
for loop.

Fixes: 0087a681fa8c ("libbpf: Automatically fix up BPF_MAP_TYPE_RINGBUF size, if necessary")
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/libbpf.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 15117b9a4d1e..eb4565a89eab 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -4951,7 +4951,7 @@ static bool is_pow_of_2(size_t x)
 static size_t adjust_ringbuf_sz(size_t sz)
 {
 	__u32 page_sz = sysconf(_SC_PAGE_SIZE);
-	__u32 i, mul;
+	__u32 mul;
 
 	/* if user forgot to set any size, make sure they see error */
 	if (sz == 0)
@@ -4967,9 +4967,7 @@ static size_t adjust_ringbuf_sz(size_t sz)
 	 * user-set size to satisfy both user size request and kernel
 	 * requirements and substitute correct max_entries for map creation.
 	 */
-	for (i = 0, mul = 1; ; i++, mul <<= 1) {
-		if (mul > UINT_MAX / page_sz) /* prevent __u32 overflow */
-			break;
+	for (mul = 1; mul <= UINT_MAX / page_sz; mul <<= 1) {
 		if (mul * page_sz > sz)
 			return mul * page_sz;
 	}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next] libbpf: clean up ringbuf size adjustment implementation
  2022-05-10 18:51 [PATCH bpf-next] libbpf: clean up ringbuf size adjustment implementation Andrii Nakryiko
@ 2022-05-11 12:10 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-05-11 12:10 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, ast, daniel, kernel-team, nathan

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Tue, 10 May 2022 11:51:59 -0700 you wrote:
> Drop unused iteration variable, move overflow prevention check into the
> for loop.
> 
> Fixes: 0087a681fa8c ("libbpf: Automatically fix up BPF_MAP_TYPE_RINGBUF size, if necessary")
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> 
> [...]

Here is the summary with links:
  - [bpf-next] libbpf: clean up ringbuf size adjustment implementation
    https://git.kernel.org/bpf/bpf-next/c/5eefe17c7ae4

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-11 12:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-10 18:51 [PATCH bpf-next] libbpf: clean up ringbuf size adjustment implementation Andrii Nakryiko
2022-05-11 12:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox