Skip to content

Commit

Permalink
LinuxKPI: add kstrtoint_from_user() and DECLARE_FLEX_ARRAY()
Browse files Browse the repository at this point in the history
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 c840d5c)
  • Loading branch information
Bjoern A. Zeeb authored and Bjoern A. Zeeb committed Feb 20, 2022
1 parent 715d53e commit c3ffedd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions sys/compat/linuxkpi/common/include/linux/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c3ffedd

Please sign in to comment.