compat: Fix autoconf probe for pcie_mpss
[~emulex/for-vlad/old/compat.git] / compat / compat-3.0.c
1 /*
2  * Copyright 2011    Hauke Mehrtens <hauke@hauke-m.de>
3  * Copyright 2011    Alexey Dobriyan <adobriyan@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Compatibility file for Linux wireless for kernels 3.0.
10  */
11
12 #include <linux/compat.h>
13 #include <linux/if_ether.h>
14
15 int mac_pton(const char *s, u8 *mac)
16 {
17         int i;
18
19         /* XX:XX:XX:XX:XX:XX */
20         if (strlen(s) < 3 * ETH_ALEN - 1)
21                 return 0;
22
23         /* Don't dirty result unless string is valid MAC. */
24         for (i = 0; i < ETH_ALEN; i++) {
25                 if (!strchr("0123456789abcdefABCDEF", s[i * 3]))
26                         return 0;
27                 if (!strchr("0123456789abcdefABCDEF", s[i * 3 + 1]))
28                         return 0;
29                 if (i != ETH_ALEN - 1 && s[i * 3 + 2] != ':')
30                         return 0;
31         }
32         for (i = 0; i < ETH_ALEN; i++) {
33                 mac[i] = (hex_to_bin(s[i * 3]) << 4) | hex_to_bin(s[i * 3 + 1]);
34         }
35         return 1;
36 }
37 EXPORT_SYMBOL_GPL(mac_pton);
38
39 #ifndef CONFIG_COMPAT_IS_KSTRTOX
40 #define kstrto_from_user(f, g, type)                                    \
41 int f(const char __user *s, size_t count, unsigned int base, type *res) \
42 {                                                                       \
43         /* sign, base 2 representation, newline, terminator */          \
44         char buf[1 + sizeof(type) * 8 + 1 + 1];                         \
45                                                                         \
46         count = min(count, sizeof(buf) - 1);                            \
47         if (copy_from_user(buf, s, count))                              \
48                 return -EFAULT;                                         \
49         buf[count] = '\0';                                              \
50         return g(buf, base, res);                                       \
51 }                                                                       \
52 EXPORT_SYMBOL_GPL(f)
53
54 kstrto_from_user(kstrtoull_from_user,   kstrtoull,      unsigned long long);
55 kstrto_from_user(kstrtoll_from_user,    kstrtoll,       long long);
56 kstrto_from_user(kstrtoul_from_user,    kstrtoul,       unsigned long);
57 kstrto_from_user(kstrtol_from_user,     kstrtol,        long);
58 kstrto_from_user(kstrtouint_from_user,  kstrtouint,     unsigned int);
59 kstrto_from_user(kstrtoint_from_user,   kstrtoint,      int);
60 kstrto_from_user(kstrtou16_from_user,   kstrtou16,      u16);
61 kstrto_from_user(kstrtos16_from_user,   kstrtos16,      s16);
62 kstrto_from_user(kstrtou8_from_user,    kstrtou8,       u8);
63 kstrto_from_user(kstrtos8_from_user,    kstrtos8,       s8);
64 #endif