diff options
author | Hauke Mehrtens <hauke@hauke-m.de> | 2008-09-14 21:19:13 +0200 |
---|---|---|
committer | Luis R. Rodriguez <lrodriguez@atheros.com> | 2008-09-15 09:44:49 -0700 |
commit | 4d6306a48cd8b998754e9822184527bd22fbafc9 (patch) | |
tree | e17ecbe52c875ad0f3e00547c9192873f092c231 | |
parent | da12e108c14f0ad00a079d5fcd4314ceb876c06c (diff) | |
download | compat-wireless-2.6-old-4d6306a48cd8b998754e9822184527bd22fbafc9.tar.gz |
add functions needed by new iwlwifi driver for older kernel versions
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
-rw-r--r-- | include/net/compat.h | 7 | ||||
-rw-r--r-- | net/wireless/compat.c | 85 |
2 files changed, 92 insertions, 0 deletions
diff --git a/include/net/compat.h b/include/net/compat.h index 0e2e515..dd0adde 100644 --- a/include/net/compat.h +++ b/include/net/compat.h @@ -511,6 +511,13 @@ static inline void led_classdev_unregister_suspended(struct led_classdev *lcd) led_classdev_unregister(lcd); } +/** + * The following things are out of ./include/linux/kernel.h + * The new iwlwifi driver is using them. + */ +extern int strict_strtoul(const char *, unsigned int, unsigned long *); +extern int strict_strtol(const char *, unsigned int, long *); + #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)) */ #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)) diff --git a/net/wireless/compat.c b/net/wireless/compat.c index 84e3ab3..96b8e2b 100644 --- a/net/wireless/compat.c +++ b/net/wireless/compat.c @@ -242,6 +242,91 @@ void pm_qos_remove_requirement(int pm_qos_class, char *name) EXPORT_SYMBOL_GPL(pm_qos_remove_requirement); +/** + * The following things are out of ./lib/vsprintf.c + * The new iwlwifi driver is using them. + */ + +/** + * strict_strtoul - convert a string to an unsigned long strictly + * @cp: The string to be converted + * @base: The number base to use + * @res: The converted result value + * + * strict_strtoul converts a string to an unsigned long only if the + * string is really an unsigned long string, any string containing + * any invalid char at the tail will be rejected and -EINVAL is returned, + * only a newline char at the tail is acceptible because people generally + * change a module parameter in the following way: + * + * echo 1024 > /sys/module/e1000/parameters/copybreak + * + * echo will append a newline to the tail. + * + * It returns 0 if conversion is successful and *res is set to the converted + * value, otherwise it returns -EINVAL and *res is set to 0. + * + * simple_strtoul just ignores the successive invalid characters and + * return the converted value of prefix part of the string. + */ +int strict_strtoul(const char *cp, unsigned int base, unsigned long *res); + +/** + * strict_strtol - convert a string to a long strictly + * @cp: The string to be converted + * @base: The number base to use + * @res: The converted result value + * + * strict_strtol is similiar to strict_strtoul, but it allows the first + * character of a string is '-'. + * + * It returns 0 if conversion is successful and *res is set to the converted + * value, otherwise it returns -EINVAL and *res is set to 0. + */ +int strict_strtol(const char *cp, unsigned int base, long *res); + +#define define_strict_strtoux(type, valtype) \ +int strict_strtou##type(const char *cp, unsigned int base, valtype *res)\ +{ \ + char *tail; \ + valtype val; \ + size_t len; \ + \ + *res = 0; \ + len = strlen(cp); \ + if (len == 0) \ + return -EINVAL; \ + \ + val = simple_strtou##type(cp, &tail, base); \ + if ((*tail == '\0') || \ + ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {\ + *res = val; \ + return 0; \ + } \ + \ + return -EINVAL; \ +} \ + +#define define_strict_strtox(type, valtype) \ +int strict_strto##type(const char *cp, unsigned int base, valtype *res) \ +{ \ + int ret; \ + if (*cp == '-') { \ + ret = strict_strtou##type(cp+1, base, res); \ + if (!ret) \ + *res = -(*res); \ + } else \ + ret = strict_strtou##type(cp, base, res); \ + \ + return ret; \ +} \ + +define_strict_strtoux(l, unsigned long) +define_strict_strtox(l, long) + +EXPORT_SYMBOL(strict_strtoul); +EXPORT_SYMBOL(strict_strtol); + #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) */ /* All things not in 2.6.22 and 2.6.23 */ |