Skip to contentSkip to conversation

ia64: hp-sim: Replace strncmp with str_has_prefix

PATCH New Chuhong Yuan 1 participant 1 message Aug 5, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ia64: hp-sim: Replace strncmp with str_has_prefix

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.

---
 arch/ia64/hp/sim/boot/bootloader.c | 2 +-
 arch/ia64/hp/sim/simeth.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/ia64/hp/sim/boot/bootloader.c +1 -1
index 6d804608dc81..bcb7af27466c 100644
@@ -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;
 	}
arch/ia64/hp/sim/simeth.c +1 -1
index f39ef2b4ed72..9ad812cd8d0e 100644
@@ -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"));
 }
 
 
Signature · 1 line
2.20.1