~ubuntu-branches/ubuntu/trusty/linux-backports-modules-3.2.0/trusty

« back to all changes in this revision

Viewing changes to updates/cw-3.3/compat/compat-3.0.c

  • Committer: Package Import Robot
  • Author(s): Leann Ogasawara
  • Date: 2012-02-15 08:42:08 UTC
  • Revision ID: package-import@ubuntu.com-20120215084208-2gcs2zosufz014pi
Tags: 3.2.0-18.1
* Open Precise LBM
* Add compat-wireless v3.3
* Consolidated amd64 server flavour into generic
* Remove lpia control file
* Update Vcs-Git to ubuntu-preicse-lbm

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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(mac_pton);
 
38
 
 
39
#define kstrto_from_user(f, g, type)                                    \
 
40
int f(const char __user *s, size_t count, unsigned int base, type *res) \
 
41
{                                                                       \
 
42
        /* sign, base 2 representation, newline, terminator */          \
 
43
        char buf[1 + sizeof(type) * 8 + 1 + 1];                         \
 
44
                                                                        \
 
45
        count = min(count, sizeof(buf) - 1);                            \
 
46
        if (copy_from_user(buf, s, count))                              \
 
47
                return -EFAULT;                                         \
 
48
        buf[count] = '\0';                                              \
 
49
        return g(buf, base, res);                                       \
 
50
}                                                                       \
 
51
EXPORT_SYMBOL(f)
 
52
 
 
53
kstrto_from_user(kstrtoull_from_user,   kstrtoull,      unsigned long long);
 
54
kstrto_from_user(kstrtoll_from_user,    kstrtoll,       long long);
 
55
kstrto_from_user(kstrtoul_from_user,    kstrtoul,       unsigned long);
 
56
kstrto_from_user(kstrtol_from_user,     kstrtol,        long);
 
57
kstrto_from_user(kstrtouint_from_user,  kstrtouint,     unsigned int);
 
58
kstrto_from_user(kstrtoint_from_user,   kstrtoint,      int);
 
59
kstrto_from_user(kstrtou16_from_user,   kstrtou16,      u16);
 
60
kstrto_from_user(kstrtos16_from_user,   kstrtos16,      s16);
 
61
kstrto_from_user(kstrtou8_from_user,    kstrtou8,       u8);
 
62
kstrto_from_user(kstrtos8_from_user,    kstrtos8,       s8);