Re: [PATCH v13 1/6] x86/boot: Introduce kstrtoull() to boot directory instead of simple_strtoull()

From: Borislav Petkov
Date: Thu Dec 13 2018 - 07:51:10 EST


On Wed, Dec 12, 2018 at 11:10:48AM +0800, Chao Fan wrote:
> Introduce kstrtoull() from lib/kstrtox.c to boot directory so that code
> in boot/ can use kstrtoull() and the old simple_strtoull() can be
> replaced.
>
> Signed-off-by: Chao Fan <fanc.fnst@xxxxxxxxxxxxxx>
> ---
> arch/x86/boot/string.c | 137 +++++++++++++++++++++++++++++++++++++++++
> arch/x86/boot/string.h | 2 +
> 2 files changed, 139 insertions(+)
>
> diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
> index c4428a176973..e02405f20f98 100644
> --- a/arch/x86/boot/string.c
> +++ b/arch/x86/boot/string.c
> @@ -12,7 +12,10 @@
> * Very basic string functions
> */
>
> +#define _LINUX_CTYPE_H
> #include <linux/types.h>
> +#include <linux/kernel.h>
> +#include <linux/errno.h>
> #include <asm/asm.h>
> #include "ctype.h"
> #include "string.h"
> @@ -187,3 +190,137 @@ char *strchr(const char *s, int c)
> return NULL;
> return (char *)s;
> }
> +
> +static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
> +{
> + union {
> + u64 v64;
> + u32 v32[2];
> + } d = { dividend };
> + u32 upper;
> +
> + upper = d.v32[1];
> + d.v32[1] = 0;
> + if (upper >= divisor) {
> + d.v32[1] = upper / divisor;
> + upper %= divisor;
> + }
> + asm ("divl %2" : "=a" (d.v32[0]), "=d" (*remainder) :
> + "rm" (divisor), "0" (d.v32[0]), "1" (upper));
> + return d.v64;
> +}

Why aren't you using the simple one from include/linux/math64.h ?

Rest looks ok.

--
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.