[PATCH 1/3] Use standard C string APIs in FDT helper
Anup Patel
Anup.Patel at wdc.com
Fri Jul 24 00:37:15 EDT 2020
> -----Original Message-----
> From: Abner Chang <abner.chang at hpe.com>
> Sent: 23 July 2020 07:24
> To: opensbi at lists.infradead.org
> Cc: abner.chang at hpe.com; Atish Patra <Atish.Patra at wdc.com>; Anup Patel
> <Anup.Patel at wdc.com>; Daniel Schaefer <daniel.schaefer at hpe.com>
> Subject: [PATCH 1/3] Use standard C string APIs in FDT helper
>
> Use strncmp instead of using sbi_strcmp directly in fdthelp.c.
> - This commit add implementation of sbi_strncmp.
>
> Signed-off-by: Abner Chang <abner.chang at hpe.com>
>
> Cc: Atish Patra <atish.patra at wdc.com>
> Cc: Anup Patel <anup.patel at wdc.com>
> Cc: Daniel Schaefer <daniel.schaefer at hpe.com>
> ---
> include/sbi/sbi_string.h | 2 +-
> lib/sbi/sbi_string.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/include/sbi/sbi_string.h b/include/sbi/sbi_string.h index
> 338075f..5e7304f 100644
> --- a/include/sbi/sbi_string.h
> +++ b/include/sbi/sbi_string.h
> @@ -12,7 +12,7 @@
>
> #include <sbi/sbi_types.h>
>
> -int sbi_strcmp(const char *a, const char *b);
> +int sbi_strncmp(const char *a, const char *b, size_t count);
>
> size_t sbi_strlen(const char *str);
>
> diff --git a/lib/sbi/sbi_string.c b/lib/sbi/sbi_string.c index 38b700b..c29120a
> 100644
> --- a/lib/sbi/sbi_string.c
> +++ b/lib/sbi/sbi_string.c
> @@ -14,10 +14,10 @@
>
> #include <sbi/sbi_string.h>
>
> -int sbi_strcmp(const char *a, const char *b)
> +int sbi_strncmp(const char *a, const char *b, size_t count)
> {
> /* search first diff or end of string */
> - for (; *a == *b && *a != '\0'; a++, b++)
> + for (; count > 0 && *a == *b && *a != '\0'; a++, b++, count--)
> ;
>
> return *a - *b;
> --
> 2.25.0
I think we should keep both sbi_strcmp() and sbi_strncmp().
Otherwise looks good to me.
Reviewed-by: Anup Patel <anup.patel at wdc.com>
Regards,
Anup
More information about the opensbi
mailing list