Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org Tested-by: Florian Fainelli <florian.fainelli@broadcom.com> Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com> Tested-by: Peter Schneider <pschneider1968@googlemail.com> Tested-by: Jon Hunter <jonathanh@nvidia.com> Tested-by: Salvatore Bonaccorso <carnil@debian.org> Tested-by: Brett A C Sheffield <bacs@librecast.net> Tested-by: Mark Brown <broonie@kernel.org> Tested-by: Luna Jernberg <droidbittin@gmail.com> Tested-by: Ronald Warsow <rwarsow@gmx.de> Tested-by: Justin M. Forbes <jforbes@fedoraproject.org> Tested-by: Ron Economos <re@w6rz.net> Tested-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
54 lines
875 B
C
54 lines
875 B
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* From lib/cmdline.c
|
|
*/
|
|
#include <stdlib.h>
|
|
|
|
#if __has_attribute(__fallthrough__)
|
|
# define fallthrough __attribute__((__fallthrough__))
|
|
#else
|
|
# define fallthrough do {} while (0) /* fallthrough */
|
|
#endif
|
|
|
|
unsigned long long memparse(const char *ptr, char **retptr)
|
|
{
|
|
char *endptr; /* local pointer to end of parsed string */
|
|
|
|
unsigned long long ret = strtoll(ptr, &endptr, 0);
|
|
|
|
switch (*endptr) {
|
|
case 'E':
|
|
case 'e':
|
|
ret <<= 10;
|
|
fallthrough;
|
|
case 'P':
|
|
case 'p':
|
|
ret <<= 10;
|
|
fallthrough;
|
|
case 'T':
|
|
case 't':
|
|
ret <<= 10;
|
|
fallthrough;
|
|
case 'G':
|
|
case 'g':
|
|
ret <<= 10;
|
|
fallthrough;
|
|
case 'M':
|
|
case 'm':
|
|
ret <<= 10;
|
|
fallthrough;
|
|
case 'K':
|
|
case 'k':
|
|
ret <<= 10;
|
|
endptr++;
|
|
fallthrough;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (retptr)
|
|
*retptr = endptr;
|
|
|
|
return ret;
|
|
}
|