From: Chuhong Yuan <hslester96@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Tony Luck <tony.luck@intel.com>,
Fenghua Yu <fenghua.yu@intel.com>,
linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org,
Chuhong Yuan <hslester96@gmail.com>
Subject: [PATCH 1/2] ia64: hp-sim: Replace strncmp with str_has_prefix
Date: Mon, 5 Aug 2019 15:26:59 +0800 [thread overview]
Message-ID: <20190805072659.32745-1-hslester96@gmail.com> (raw)
strncmp(str, const, len) is error-prone since the len is
easy to be wrong because of counting error or sizeof(const)
without - 1.
Use the newly introduced str_has_prefix() to substitute
it to make code better.
Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
---
arch/ia64/hp/sim/boot/bootloader.c | 2 +-
arch/ia64/hp/sim/simeth.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/ia64/hp/sim/boot/bootloader.c b/arch/ia64/hp/sim/boot/bootloader.c
index 6d804608dc81..bcb7af27466c 100644
--- a/arch/ia64/hp/sim/boot/bootloader.c
+++ b/arch/ia64/hp/sim/boot/bootloader.c
@@ -112,7 +112,7 @@ start_bootloader (void)
ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION);
elf = (struct elfhdr *) mem;
- if (elf->e_ident[0] == 0x7f && strncmp(elf->e_ident + 1, "ELF", 3) != 0) {
+ if (elf->e_ident[0] == 0x7f && !str_has_prefix(elf->e_ident + 1, "ELF", 3)) {
cons_write("not an ELF file\n");
return;
}
diff --git a/arch/ia64/hp/sim/simeth.c b/arch/ia64/hp/sim/simeth.c
index f39ef2b4ed72..9ad812cd8d0e 100644
--- a/arch/ia64/hp/sim/simeth.c
+++ b/arch/ia64/hp/sim/simeth.c
@@ -248,7 +248,7 @@ simeth_open(struct net_device *dev)
/* copied from lapbether.c */
static __inline__ int dev_is_ethdev(struct net_device *dev)
{
- return ( dev->type == ARPHRD_ETHER && strncmp(dev->name, "dummy", 5));
+ return (dev->type == ARPHRD_ETHER && !str_has_prefix(dev->name, "dummy"));
}
--
2.20.1
reply other threads:[~2019-08-05 7:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20190805072659.32745-1-hslester96@gmail.com \
--to=hslester96@gmail.com \
--cc=fenghua.yu@intel.com \
--cc=linux-ia64@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tony.luck@intel.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).