aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/printk/braille.c
diff options
context:
space:
mode:
authorChuhong Yuan <hslester96@gmail.com>2019-08-09 15:10:34 +0800
committerPetr Mladek <pmladek@suse.com>2019-08-16 09:54:08 +0200
commit35c35493b0e3343522256f6054516f4e2161a6d4 (patch)
tree44d06154bcf3d4b1fa7b2cfb09c4f0e6ed04183d /kernel/printk/braille.c
parentlib/test_printf: Remove obvious comments from %pd and %pD tests (diff)
downloadlinux-dev-35c35493b0e3343522256f6054516f4e2161a6d4.tar.xz
linux-dev-35c35493b0e3343522256f6054516f4e2161a6d4.zip
printk: Replace strncmp() with str_has_prefix()
strncmp(str, const, len) is error-prone because len is easy to have typo. An 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() to make code better. Link: http://lkml.kernel.org/r/20190809071034.17279-1-hslester96@gmail.com Cc: "Steven Rostedt" <rostedt@goodmis.org> Cc: linux-kernel@vger.kernel.org Signed-off-by: Chuhong Yuan <hslester96@gmail.com> Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> [pmladek@suse.com: Slightly updated and reformatted the commit message.] Signed-off-by: Petr Mladek <pmladek@suse.com>
Diffstat (limited to 'kernel/printk/braille.c')
-rw-r--r--kernel/printk/braille.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/kernel/printk/braille.c b/kernel/printk/braille.c
index 1d21ebacfdb8..17a9591e54ff 100644
--- a/kernel/printk/braille.c
+++ b/kernel/printk/braille.c
@@ -11,11 +11,18 @@
int _braille_console_setup(char **str, char **brl_options)
{
- if (!strncmp(*str, "brl,", 4)) {
+ size_t len;
+
+ len = str_has_prefix(*str, "brl,");
+ if (len) {
*brl_options = "";
- *str += 4;
- } else if (!strncmp(*str, "brl=", 4)) {
- *brl_options = *str + 4;
+ *str += len;
+ return 0;
+ }
+
+ len = str_has_prefix(*str, "brl=");
+ if (len) {
+ *brl_options = *str + len;
*str = strchr(*brl_options, ',');
if (!*str) {
pr_err("need port name after brl=\n");