Skip to content

Commit 5fafbeb

Browse files
Vamshi K Sthambamkadisuryasaimadhu
authored andcommitted
x86/boot: Add kstrtoul() from lib/
Add kstrtoul() to ../boot/ to be used by facilities there too. [ bp: Massage, make _kstrtoul() static. Prepend function names with "boot_". This is a temporary workaround for build errors like: ld: arch/x86/boot/compressed/acpi.o: in function `count_immovable_mem_regions': acpi.c:(.text+0x463): undefined reference to `_kstrtoul' make[2]: *** [arch/x86/boot/compressed/Makefile:117: arch/x86/boot/compressed/vmlinux] Error 1 due to the namespace clash between x86/boot/ and kernel proper. Future reorg will get rid of the linux/linux/ namespace as much as possible so that x86/boot/ can be independent from kernel proper. ] Signed-off-by: Vamshi K Sthambamkadi <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 767dea2 commit 5fafbeb

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

arch/x86/boot/string.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ static unsigned int simple_guess_base(const char *cp)
117117
* @endp: A pointer to the end of the parsed string will be placed here
118118
* @base: The number base to use
119119
*/
120-
121120
unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
122121
{
123122
unsigned long long result = 0;
@@ -335,3 +334,45 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
335334
s++;
336335
return _kstrtoull(s, base, res);
337336
}
337+
338+
static int _kstrtoul(const char *s, unsigned int base, unsigned long *res)
339+
{
340+
unsigned long long tmp;
341+
int rv;
342+
343+
rv = kstrtoull(s, base, &tmp);
344+
if (rv < 0)
345+
return rv;
346+
if (tmp != (unsigned long)tmp)
347+
return -ERANGE;
348+
*res = tmp;
349+
return 0;
350+
}
351+
352+
/**
353+
* kstrtoul - convert a string to an unsigned long
354+
* @s: The start of the string. The string must be null-terminated, and may also
355+
* include a single newline before its terminating null. The first character
356+
* may also be a plus sign, but not a minus sign.
357+
* @base: The number base to use. The maximum supported base is 16. If base is
358+
* given as 0, then the base of the string is automatically detected with the
359+
* conventional semantics - If it begins with 0x the number will be parsed as a
360+
* hexadecimal (case insensitive), if it otherwise begins with 0, it will be
361+
* parsed as an octal number. Otherwise it will be parsed as a decimal.
362+
* @res: Where to write the result of the conversion on success.
363+
*
364+
* Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
365+
* Used as a replacement for the simple_strtoull.
366+
*/
367+
int boot_kstrtoul(const char *s, unsigned int base, unsigned long *res)
368+
{
369+
/*
370+
* We want to shortcut function call, but
371+
* __builtin_types_compatible_p(unsigned long, unsigned long long) = 0.
372+
*/
373+
if (sizeof(unsigned long) == sizeof(unsigned long long) &&
374+
__alignof__(unsigned long) == __alignof__(unsigned long long))
375+
return kstrtoull(s, base, (unsigned long long *)res);
376+
else
377+
return _kstrtoul(s, base, res);
378+
}

arch/x86/boot/string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ extern unsigned long long simple_strtoull(const char *cp, char **endp,
3030
unsigned int base);
3131

3232
int kstrtoull(const char *s, unsigned int base, unsigned long long *res);
33+
int boot_kstrtoul(const char *s, unsigned int base, unsigned long *res);
3334
#endif /* BOOT_STRING_H */

0 commit comments

Comments
 (0)