git: 8e587a5f13ce - main - linuxkpi: Add kstrtouint_from_user

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Wed, 23 Mar 2022 13:39:00 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=8e587a5f13ce676d7763ffa920148fe31bc3bfae

commit 8e587a5f13ce676d7763ffa920148fe31bc3bfae
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2022-03-22 09:22:42 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-03-23 13:37:32 +0000

    linuxkpi: Add kstrtouint_from_user
    
    Like kstrtoint_from_user but for uint.
    Needed by drm v5.10
    
    MFC after:      1 month
    Reviewed by:    hselasky
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D34642
---
 sys/compat/linuxkpi/common/include/linux/kernel.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/kernel.h b/sys/compat/linuxkpi/common/include/linux/kernel.h
index d6916812f02a..8fb92dd2f93e 100644
--- a/sys/compat/linuxkpi/common/include/linux/kernel.h
+++ b/sys/compat/linuxkpi/common/include/linux/kernel.h
@@ -524,6 +524,21 @@ kstrtoint_from_user(const char __user *s, size_t count, unsigned int base,
 	return (kstrtoint(buf, base, p));
 }
 
+static inline int
+kstrtouint_from_user(const char __user *s, size_t count, unsigned int base,
+    int *p)
+{
+	char buf[36] = {};
+
+	if (count > (sizeof(buf) - 1))
+		count = (sizeof(buf) - 1);
+
+	if (copy_from_user(buf, s, count))
+		return (-EFAULT);
+
+	return (kstrtouint(buf, base, p));
+}
+
 static inline int
 kstrtou8_from_user(const char __user *s, size_t count, unsigned int base,
     u8 *p)