git: c3ffeddb4709 - stable/13 - LinuxKPI: add kstrtoint_from_user() and DECLARE_FLEX_ARRAY()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 20 Feb 2022 18:15:40 UTC
The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=c3ffeddb4709fc6c5bebf84c52de7dd11dfca61c commit c3ffeddb4709fc6c5bebf84c52de7dd11dfca61c Author: Bjoern A. Zeeb <bz@FreeBSD.org> AuthorDate: 2022-02-09 11:58:40 +0000 Commit: Bjoern A. Zeeb <bz@FreeBSD.org> CommitDate: 2022-02-20 16:24:51 +0000 LinuxKPI: add kstrtoint_from_user() and DECLARE_FLEX_ARRAY() Add an implementation of kstrtoint_from_user() based on the other implementations and an attempt at DECLARE_FLEX_ARRAY() which works for the driver needing it. Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D34231 (cherry picked from commit c840d5cec2607932d077ffcfee7ccf0a6b50cdf3) --- sys/compat/linuxkpi/common/include/linux/kernel.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/kernel.h b/sys/compat/linuxkpi/common/include/linux/kernel.h index 58581ebe9101..1e8fef985803 100644 --- a/sys/compat/linuxkpi/common/include/linux/kernel.h +++ b/sys/compat/linuxkpi/common/include/linux/kernel.h @@ -509,6 +509,21 @@ kstrtobool_from_user(const char __user *s, size_t count, bool *res) return (kstrtobool(buf, res)); } +static inline int +kstrtoint_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 (kstrtoint(buf, base, p)); +} + static inline int kstrtou8_from_user(const char __user *s, size_t count, unsigned int base, u8 *p) @@ -684,6 +699,9 @@ hex2bin(uint8_t *bindst, const char *hexsrc, size_t binlen) return (0); } +#define DECLARE_FLEX_ARRAY(_t, _n) \ + struct { struct { } __dummy_ ## _n; _t _n[]; } + /* * Checking if an option is defined would be easy if we could do CPP inside CPP. * The defined case whether -Dxxx or -Dxxx=1 are easy to deal with. In either