Skip to content

Commit a4e74fa

Browse files
melverpaulmckrcu
authored andcommitted
kcsan: Simplify constant string handling
Simplify checking prefixes and length calculation of constant strings. For the former, the kernel provides str_has_prefix(), and the latter we should just use strlen("..") because GCC and Clang have optimizations that optimize these into constants. No functional change intended. Signed-off-by: Marco Elver <elver@google.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent 69b2c81 commit a4e74fa

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

kernel/kcsan/debugfs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,16 @@ debugfs_write(struct file *file, const char __user *buf, size_t count, loff_t *o
300300
WRITE_ONCE(kcsan_enabled, true);
301301
} else if (!strcmp(arg, "off")) {
302302
WRITE_ONCE(kcsan_enabled, false);
303-
} else if (!strncmp(arg, "microbench=", sizeof("microbench=") - 1)) {
303+
} else if (str_has_prefix(arg, "microbench=")) {
304304
unsigned long iters;
305305

306-
if (kstrtoul(&arg[sizeof("microbench=") - 1], 0, &iters))
306+
if (kstrtoul(&arg[strlen("microbench=")], 0, &iters))
307307
return -EINVAL;
308308
microbenchmark(iters);
309-
} else if (!strncmp(arg, "test=", sizeof("test=") - 1)) {
309+
} else if (str_has_prefix(arg, "test=")) {
310310
unsigned long iters;
311311

312-
if (kstrtoul(&arg[sizeof("test=") - 1], 0, &iters))
312+
if (kstrtoul(&arg[strlen("test=")], 0, &iters))
313313
return -EINVAL;
314314
test_thread(iters);
315315
} else if (!strcmp(arg, "whitelist")) {

kernel/kcsan/report.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ static int get_stack_skipnr(const unsigned long stack_entries[], int num_entries
279279

280280
cur = strnstr(buf, "kcsan_", len);
281281
if (cur) {
282-
cur += sizeof("kcsan_") - 1;
283-
if (strncmp(cur, "test", sizeof("test") - 1))
282+
cur += strlen("kcsan_");
283+
if (!str_has_prefix(cur, "test"))
284284
continue; /* KCSAN runtime function. */
285285
/* KCSAN related test. */
286286
}

0 commit comments

Comments
 (0)