From: Chuhong Yuan <hslester96@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Petr Mladek <pmladek@suse.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
linux-kernel@vger.kernel.org, Chuhong Yuan <hslester96@gmail.com>
Subject: [PATCH 08/12] printk: Replace strncmp with str_has_prefix
Date: Mon, 29 Jul 2019 23:15:05 +0800 [thread overview]
Message-ID: <20190729151505.9660-1-hslester96@gmail.com> (raw)
strncmp(str, const, len) is error-prone.
We had better use newly introduced
str_has_prefix() instead of it.
Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
---
kernel/printk/braille.c | 4 ++--
kernel/printk/printk.c | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/kernel/printk/braille.c b/kernel/printk/braille.c
index 1d21ebacfdb8..64f0fb8ef27d 100644
--- a/kernel/printk/braille.c
+++ b/kernel/printk/braille.c
@@ -11,10 +11,10 @@
int _braille_console_setup(char **str, char **brl_options)
{
- if (!strncmp(*str, "brl,", 4)) {
+ if (str_has_prefix(*str, "brl,")) {
*brl_options = "";
*str += 4;
- } else if (!strncmp(*str, "brl=", 4)) {
+ } else if (str_has_prefix(*str, "brl=")) {
*brl_options = *str + 4;
*str = strchr(*brl_options, ',');
if (!*str) {
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 1888f6a3b694..9e60dce4bdd5 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -121,13 +121,13 @@ static int __control_devkmsg(char *str)
if (!str)
return -EINVAL;
- if (!strncmp(str, "on", 2)) {
+ if (str_has_prefix(str, "on")) {
devkmsg_log = DEVKMSG_LOG_MASK_ON;
return 2;
- } else if (!strncmp(str, "off", 3)) {
+ } else if (str_has_prefix(str, "off")) {
devkmsg_log = DEVKMSG_LOG_MASK_OFF;
return 3;
- } else if (!strncmp(str, "ratelimit", 9)) {
+ } else if (str_has_prefix(str, "ratelimit")) {
devkmsg_log = DEVKMSG_LOG_MASK_DEFAULT;
return 9;
}
--
2.20.1
next reply other threads:[~2019-07-29 15:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-29 15:15 Chuhong Yuan [this message]
2019-07-30 0:16 ` [PATCH 08/12] printk: Replace strncmp with str_has_prefix Joe Perches
2019-08-01 15:23 ` Chuhong Yuan
2019-08-01 16:19 ` Joe Perches
2019-08-01 16:40 ` Steven Rostedt
2019-08-01 17:51 ` Joe Perches
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=20190729151505.9660-1-hslester96@gmail.com \
--to=hslester96@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).