* [PATCH] bpf: Use isdigit() in bpf_bprintf_prepare()
@ 2026-11-21 0:53 Thorsten Blum
2026-12-01 5:19 ` Alexei Starovoitov
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-11-21 0:53 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
Ihor Solodrai
Cc: Thorsten Blum, bpf
Use isdigit() to replace the open-coded implementation.
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
kernel/bpf/helpers.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index 6788489a2608..7292a15ffbb2 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -927,7 +927,7 @@ int bpf_bprintf_prepare(const char *fmt, u32 fmt_size, const u64 *raw_args,
i++;
if (fmt[i] >= '1' && fmt[i] <= '9') {
i++;
- while (fmt[i] >= '0' && fmt[i] <= '9')
+ while (isdigit(fmt[i]))
i++;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] bpf: Use isdigit() in bpf_bprintf_prepare()
2026-11-21 0:53 [PATCH] bpf: Use isdigit() in bpf_bprintf_prepare() Thorsten Blum
@ 2026-12-01 5:19 ` Alexei Starovoitov
0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2026-12-01 5:19 UTC (permalink / raw)
To: Thorsten Blum, Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman,
Kumar Kartikeya Dwivedi, Martin KaFai Lau, Song Liu,
Yonghong Song, Jiri Olsa, Emil Tsalapatis, Ihor Solodrai
Cc: bpf
On Fri, Nov 20, 2026 at 04:53 PM Thorsten Blum <blum@kernel.org> wrote:
> if (fmt[i] >= '1' && fmt[i] <= '9') {
> i++;
> - while (fmt[i] >= '0' && fmt[i] <= '9')
> + while (isdigit(fmt[i]))
> i++;
> }
The '1'..'9' check stays open-coded.
The loop in front of it skips every '0', so fmt[i] is not '0' here.
One isdigit() loop covers both. No need for the 'if'.
helpers.o builds with it, the snprintf test was not run:
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index 937a0d7..6bf36a4 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -928,11 +928,8 @@ int bpf_bprintf_prepare(const char *fmt, u32 fmt_size, const u64 *raw_args,
while (fmt[i] == '0' || fmt[i] == '+' || fmt[i] == '-' ||
fmt[i] == ' ')
i++;
- if (fmt[i] >= '1' && fmt[i] <= '9') {
+ while (isdigit(fmt[i]))
i++;
- while (fmt[i] >= '0' && fmt[i] <= '9')
- i++;
- }
if (fmt[i] == 'p') {
sizeof_cur_arg = sizeof(long);
Pls tag the respin as [PATCH bpf-next v2].
pw-bot: cr
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-01 5:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 0:53 [PATCH] bpf: Use isdigit() in bpf_bprintf_prepare() Thorsten Blum
2026-12-01 5:19 ` Alexei Starovoitov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox