From 8e587a5f13ce676d7763ffa920148fe31bc3bfae Mon Sep 17 00:00:00 2001 From: Emmanuel Vadot Date: Tue, 22 Mar 2022 10:22:42 +0100 Subject: [PATCH] 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 d6916812f02..8fb92dd2f93 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)