svn commit: r361551 - head/sys/compat/linuxkpi/common/include/linux

Emmanuel Vadot manu at FreeBSD.org
Wed May 27 11:42:09 UTC 2020


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;


More information about the svn-src-head mailing list