public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.ibm.com>
To: Chuhong Yuan <hslester96@gmail.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
	Josh Triplett <josh@joshtriplett.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 03/10] locking/locktorture: Replace strncmp with str_has_prefix
Date: Fri, 2 Aug 2019 16:05:01 -0700	[thread overview]
Message-ID: <20190802230501.GS28441@linux.ibm.com> (raw)
In-Reply-To: <20190802014656.8789-1-hslester96@gmail.com>

On Fri, Aug 02, 2019 at 09:46:56AM +0800, Chuhong Yuan wrote:
> strncmp(str, const, len) is error-prone because len
> is easy to have typo.
> The example is the hard-coded len has counting error
> or sizeof(const) forgets - 1.
> So we prefer using newly introduced str_has_prefix
> to substitute such strncmp.
> 
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>

Queued, thank you!  I updated the commit log as follows.  Please let
me know if I messed anything up.

							Thanx, Paul

------------------------------------------------------------------------

commit e2be525371b2f6790f6c1ab712c3d273fb1f2bea
Author: Chuhong Yuan <hslester96@gmail.com>
Date:   Fri Aug 2 09:46:56 2019 +0800

    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 <hslester96@gmail.com>
    Signed-off-by: Paul E. McKenney <paulmck@linux.ibm.com>

diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index c513031cd7e3..8dd900247205 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -889,16 +889,16 @@ static int __init lock_torture_init(void)
 		cxt.nrealwriters_stress = 2 * num_online_cpus();
 
 #ifdef CONFIG_DEBUG_MUTEXES
-	if (strncmp(torture_type, "mutex", 5) == 0)
+	if (str_has_prefix(torture_type, "mutex"))
 		cxt.debug_lock = true;
 #endif
 #ifdef CONFIG_DEBUG_RT_MUTEXES
-	if (strncmp(torture_type, "rtmutex", 7) == 0)
+	if (str_has_prefix(torture_type, "rtmutex"))
 		cxt.debug_lock = true;
 #endif
 #ifdef CONFIG_DEBUG_SPINLOCK
-	if ((strncmp(torture_type, "spin", 4) == 0) ||
-	    (strncmp(torture_type, "rw_lock", 7) == 0))
+	if ((str_has_prefix(torture_type, "spin")) ||
+	    (str_has_prefix(torture_type, "rw_lock")))
 		cxt.debug_lock = true;
 #endif
 

      reply	other threads:[~2019-08-02 23:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-02  1:46 [PATCH v2 03/10] locking/locktorture: Replace strncmp with str_has_prefix Chuhong Yuan
2019-08-02 23:05 ` Paul E. McKenney [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190802230501.GS28441@linux.ibm.com \
    --to=paulmck@linux.ibm.com \
    --cc=dave@stgolabs.net \
    --cc=hslester96@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox