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. MFC after: 3 days Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D34231
This commit is contained in:
parent
0c37ffda79
commit
c840d5cec2
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user