diff mbox

xen/serial: Fix incorrect length of strncmp for dtuart

Message ID 1465248548-28391-1-git-send-email-anjiandi@codeaurora.org (mailing list archive)
State New, archived
Headers show

Commit Message

Jiandi An June 6, 2016, 9:29 p.m. UTC
In serial_parse_handler(), length of strncmp for dtuart should have been
6, not 5.

Signed-off-by: Jiandi An <anjiandi@codeaurora.org>
---
 xen/drivers/char/serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefano Stabellini June 7, 2016, 10:11 a.m. UTC | #1
On Mon, 6 Jun 2016, Jiandi An wrote:
> In serial_parse_handler(), length of strncmp for dtuart should have been
> 6, not 5.
> 
> Signed-off-by: Jiandi An <anjiandi@codeaurora.org>

Acked-by: Stefano Stabellini <sstabellini@kernel.org>


>  xen/drivers/char/serial.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/xen/drivers/char/serial.c b/xen/drivers/char/serial.c
> index c583a48..0fc5ced 100644
> --- a/xen/drivers/char/serial.c
> +++ b/xen/drivers/char/serial.c
> @@ -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;
> -- 
> Jiandi An
> Qualcomm Innovation Center, Inc.
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
>
Philipp Hahn June 8, 2016, 5:30 a.m. UTC | #2
Hello,

Am 06.06.2016 um 23:29 schrieb Jiandi An:
> In serial_parse_handler(), length of strncmp for dtuart should have been
> 6, not 5.
> 
> Signed-off-by: Jiandi An <anjiandi@codeaurora.org>
> ---
>  xen/drivers/char/serial.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/xen/drivers/char/serial.c b/xen/drivers/char/serial.c
> index c583a48..0fc5ced 100644
> --- a/xen/drivers/char/serial.c
> +++ b/xen/drivers/char/serial.c
> @@ -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
diff mbox

Patch

diff --git a/xen/drivers/char/serial.c b/xen/drivers/char/serial.c
index c583a48..0fc5ced 100644
--- a/xen/drivers/char/serial.c
+++ b/xen/drivers/char/serial.c
@@ -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;