Skip to contentSkip to conversation

xen/serial: Fix incorrect length of strncmp for dtuart

PATCH In review Jiandi An 5 participants 5 messages Jun 6, 2016 – Jun 8, 2016

lore
Share & tools
lore

Jiandi An

author
#0 lore raw

PATCH 1/1 xen/serial: Fix incorrect length of strncmp for dtuart

In serial_parse_handler(), length of strncmp for dtuart should have been 6, not 5.

---
 xen/drivers/char/serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/drivers/char/serial.c +1 -1
index c583a48..0fc5ced 100644
@@ -310,7 +310,7 @@ int __init serial_parse_handle(char *conf)
         goto common;
     }
 
-    if ( !strncmp(conf, "dtuart", 5) )
+    if ( !strncmp(conf, "dtuart", 6) )
     {
         handle = SERHND_DTUART;
         goto common;
Signature · 9 lines
Jiandi An
Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.06.16 at 23:29, <[email protected]> wrote:

In serial_parse_handler(), length of strncmp for dtuart should have been 6, not 5.

Wei - trivial enough for inclusion in 4.7, I would think?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
Quoted 10 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.06.16 at 23:29, <[email protected]> wrote:

In serial_parse_handler(), length of strncmp for dtuart should have been 6, not 5.

Wei - trivial enough for inclusion in 4.7, I would think?

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on v1 1/1
#3 lore raw
In reply to Jiandi An
Quoted 4 lines · Jiandi An

In serial_parse_handler(), length of strncmp for dtuart should have been 6, not 5.

Quoted 21 lines
 xen/drivers/char/serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/drivers/char/serial.c +1 -1
index c583a48..0fc5ced 100644
@@ -310,7 +310,7 @@ int __init serial_parse_handle(char *conf)
         goto common;
     }
 
-    if ( !strncmp(conf, "dtuart", 5) )
+    if ( !strncmp(conf, "dtuart", 6) )
     {
         handle = SERHND_DTUART;
         goto common;
Signature · 3 lines
Jiandi An
Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#4 lore raw
In reply to Jiandi An

Hello,

Am 06.06.2016 um 23:29 schrieb Jiandi An:

Quoted 13 lines

In serial_parse_handler(), length of strncmp for dtuart should have been 6, not 5.

---
 xen/drivers/char/serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/drivers/char/serial.c +0 -0
index c583a48..0fc5ced 100644

xen/drivers/char/serial.c int __init serial_parse_handle(char *conf) · line 313

Quoted 5 lines
xen/drivers/char/serial.c +1 -1
@@ -310,7 +310,7 @@ int __init serial_parse_handle(char *conf)
         goto common;
     }
 
-    if ( !strncmp(conf, "dtuart", 5) )
+    if ( !strncmp(conf, "dtuart", 6) )

Do you really want to check for a prefix, that it that conf starts with "dtuart"?

If you want to check for an exact string match, you need to include the trailing \0!
In that case just use "strcmp()" as there is (AFAIK) not reason to use the n-variant as one of your string is a constant already and thus the comparison will terminate when the \0 of that const-string is reached.

Philipp

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

static const char *confs[] = {
	"dtuar",
	"dtuart",
	"dtuartx",
	NULL
};
int main(void) {
	int i;
	for (i = 0; confs[i]; i++) {
		const char *conf = confs[i];
		printf("%s\t%d\t%d\n", conf, strncmp(conf, "dtuart", 5),  strncmp(conf, "dtuart", 6));
	}
	return 0;
}

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel