Date: Wed, 27 May 2020 11:42:09 +0000 (UTC) From: Emmanuel Vadot <manu@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r361551 - head/sys/compat/linuxkpi/common/include/linux Message-ID: <202005271142.04RBg9K0010339@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: manu Date: Wed May 27 11:42:09 2020 New Revision: 361551 URL: https://svnweb.freebsd.org/changeset/base/361551 Log: linuxkpi: Add kstrtou16 This function convert a char * to a u16. Simply use strtoul and cast to compare for ERANGE Sponsored-by: The FreeBSD Foundation Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D24996 Modified: head/sys/compat/linuxkpi/common/include/linux/kernel.h Modified: head/sys/compat/linuxkpi/common/include/linux/kernel.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/kernel.h Wed May 27 10:01:30 2020 (r361550) +++ head/sys/compat/linuxkpi/common/include/linux/kernel.h Wed May 27 11:42:09 2020 (r361551) @@ -374,6 +374,24 @@ kstrtouint(const char *cp, unsigned int base, unsigned } static inline int +kstrtou16(const char *cp, unsigned int base, u16 *res) +{ + char *end; + unsigned long temp; + + *res = temp = strtoul(cp, &end, base); + + /* skip newline character, if any */ + if (*end == '\n') + end++; + if (*cp == 0 || *end != 0) + return (-EINVAL); + if (temp != (u16)temp) + return (-ERANGE); + return (0); +} + +static inline int kstrtou32(const char *cp, unsigned int base, u32 *res) { char *end;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005271142.04RBg9K0010339>