[PATCH 1/1] [kernel/{bpf/bpf_iter.c,debug/gdbstub.c,debug/kdb/{kdb_io.c,kdb_main.c,kdb_support.c},trace/{trace_events.c,trace_kprobe.c}}] Use `size_t` for `strlen` responses in trivial scope

From: Samuel Marks
Date: Thu Oct 28 2021 - 19:08:20 EST


---
kernel/bpf/bpf_iter.c | 2 +-
kernel/debug/gdbstub.c | 2 +-
kernel/debug/kdb/kdb_io.c | 2 +-
kernel/debug/kdb/kdb_main.c | 2 +-
kernel/debug/kdb/kdb_support.c | 3 ++-
kernel/trace/trace_events.c | 2 +-
kernel/trace/trace_kprobe.c | 4 ++--
7 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c
index b2ee45064..4d57f6332 100644
--- a/kernel/bpf/bpf_iter.c
+++ b/kernel/bpf/bpf_iter.c
@@ -332,7 +332,7 @@ bool bpf_iter_prog_supported(struct bpf_prog *prog)
u32 prog_btf_id = prog->aux->attach_btf_id;
const char *prefix = BPF_ITER_FUNC_PREFIX;
struct bpf_iter_target_info *tinfo;
- int prefix_len = strlen(prefix);
+ size_t prefix_len = strlen(prefix);
bool supported = false;

if (strncmp(attach_fname, prefix, prefix_len))
diff --git a/kernel/debug/gdbstub.c b/kernel/debug/gdbstub.c
index 9d34d2364..ec48e7d88 100644
--- a/kernel/debug/gdbstub.c
+++ b/kernel/debug/gdbstub.c
@@ -770,7 +770,7 @@ static void gdb_cmd_query(struct kgdb_state *ks)
#ifdef CONFIG_KGDB_KDB
case 'R':
if (strncmp(remcom_in_buffer, "qRcmd,", 6) == 0) {
- int len = strlen(remcom_in_buffer + 6);
+ size_t len = strlen(remcom_in_buffer + 6);

if ((len % 2) != 0) {
strcpy(remcom_out_buffer, "E01");
diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
index 6735ac36b..a7e8aa967 100644
--- a/kernel/debug/kdb/kdb_io.c
+++ b/kernel/debug/kdb/kdb_io.c
@@ -38,7 +38,7 @@ static int kgdb_transition_check(char *buffer)
KDB_STATE_SET(KGDB_TRANS);
kdb_printf("%s", buffer);
} else {
- int slen = strlen(buffer);
+ const size_t slen = strlen(buffer);
if (slen > 3 && buffer[slen - 3] == '#') {
kdb_gdb_state_pass(buffer);
strcpy(buffer, "kgdb");
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index fa6deda89..c72d8cf31 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -197,7 +197,7 @@ static inline bool kdb_check_flags(kdb_cmdflags_t
flags, int permissions,
char *kdbgetenv(const char *match)
{
char **ep = __env;
- int matchlen = strlen(match);
+ const size_t matchlen = strlen(match);
int i;

for (i = 0; i < __nenv; i++) {
diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c
index 7507d9a8d..54ece45e9 100644
--- a/kernel/debug/kdb/kdb_support.c
+++ b/kernel/debug/kdb/kdb_support.c
@@ -126,7 +126,8 @@ static char ks_namebuf[KSYM_NAME_LEN+1],
ks_namebuf_prev[KSYM_NAME_LEN+1];
int kallsyms_symbol_complete(char *prefix_name, int max_len)
{
loff_t pos = 0;
- int prefix_len = strlen(prefix_name), prev_len = 0;
+ const size_t prefix_len = strlen(prefix_name)
+ int prev_len = 0;
int i, number = 0;
const char *name;

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 830b3b994..0e1b90d4a 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -2561,7 +2561,7 @@ static void update_event_printk(struct
trace_event_call *call,
{
char *ptr;
int quote = 0;
- int len = strlen(map->eval_string);
+ const size_t len = strlen(map->eval_string);

for (ptr = call->print_fmt; *ptr; ptr++) {
if (*ptr == '\\') {
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 3a64ba4bb..39fa5d1df 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -101,9 +101,9 @@ static nokprobe_inline bool
trace_kprobe_has_gone(struct trace_kprobe *tk)
}

static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk,
- struct module *mod)
+ struct module *mod)
{
- int len = strlen(module_name(mod));
+ const size_t len = strlen(module_name(mod));
const char *name = trace_kprobe_symbol(tk);

return strncmp(module_name(mod), name, len) == 0 && name[len] == ':';
--
2.33.1