Skip to content

Commit c5d3c8c

Browse files
WillLesterpaulmckrcu
authored andcommitted
locktorture: Replace strncmp() with str_has_prefix()
The strncmp() function is error-prone because it is easy to get the length wrong, especially if the string is subject to change, especially given the need to account for the terminating nul byte. This commit therefore substitutes the newly introduced str_has_prefix(), which does not require a separately specified length. Signed-off-by: Chuhong Yuan <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent ac5f636 commit c5d3c8c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

kernel/locking/locktorture.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -889,16 +889,16 @@ static int __init lock_torture_init(void)
889889
cxt.nrealwriters_stress = 2 * num_online_cpus();
890890

891891
#ifdef CONFIG_DEBUG_MUTEXES
892-
if (strncmp(torture_type, "mutex", 5) == 0)
892+
if (str_has_prefix(torture_type, "mutex"))
893893
cxt.debug_lock = true;
894894
#endif
895895
#ifdef CONFIG_DEBUG_RT_MUTEXES
896-
if (strncmp(torture_type, "rtmutex", 7) == 0)
896+
if (str_has_prefix(torture_type, "rtmutex"))
897897
cxt.debug_lock = true;
898898
#endif
899899
#ifdef CONFIG_DEBUG_SPINLOCK
900-
if ((strncmp(torture_type, "spin", 4) == 0) ||
901-
(strncmp(torture_type, "rw_lock", 7) == 0))
900+
if ((str_has_prefix(torture_type, "spin")) ||
901+
(str_has_prefix(torture_type, "rw_lock")))
902902
cxt.debug_lock = true;
903903
#endif
904904

0 commit comments

Comments
 (0)