diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 14 | ||||
-rw-r--r-- | lib/Makefile | 3 | ||||
-rw-r--r-- | lib/bitmap.c | 2 | ||||
-rw-r--r-- | lib/checksum.c | 13 | ||||
-rw-r--r-- | lib/cordic.c | 101 | ||||
-rw-r--r-- | lib/crc8.c | 86 | ||||
-rw-r--r-- | lib/debugobjects.c | 2 | ||||
-rw-r--r-- | lib/kobject.c | 26 |
8 files changed, 220 insertions, 27 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index 830181cc7a83..32f3e5ae2be5 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
@@ -79,6 +79,13 @@ config LIBCRC32C | |||
79 | require M here. See Castagnoli93. | 79 | require M here. See Castagnoli93. |
80 | Module will be libcrc32c. | 80 | Module will be libcrc32c. |
81 | 81 | ||
82 | config CRC8 | ||
83 | tristate "CRC8 function" | ||
84 | help | ||
85 | This option provides CRC8 function. Drivers may select this | ||
86 | when they need to do cyclic redundancy check according CRC8 | ||
87 | algorithm. Module will be called crc8. | ||
88 | |||
82 | config AUDIT_GENERIC | 89 | config AUDIT_GENERIC |
83 | bool | 90 | bool |
84 | depends on AUDIT && !AUDIT_ARCH | 91 | depends on AUDIT && !AUDIT_ARCH |
@@ -262,4 +269,11 @@ config AVERAGE | |||
262 | 269 | ||
263 | If unsure, say N. | 270 | If unsure, say N. |
264 | 271 | ||
272 | config CORDIC | ||
273 | tristate "Cordic function" | ||
274 | help | ||
275 | The option provides arithmetic function using cordic algorithm | ||
276 | so its calculations are in fixed point. Modules can select this | ||
277 | when they require this function. Module will be called cordic. | ||
278 | |||
265 | endmenu | 279 | endmenu |
diff --git a/lib/Makefile b/lib/Makefile index 6b597fdb1898..892f4e282ea1 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -61,6 +61,7 @@ obj-$(CONFIG_CRC_ITU_T) += crc-itu-t.o | |||
61 | obj-$(CONFIG_CRC32) += crc32.o | 61 | obj-$(CONFIG_CRC32) += crc32.o |
62 | obj-$(CONFIG_CRC7) += crc7.o | 62 | obj-$(CONFIG_CRC7) += crc7.o |
63 | obj-$(CONFIG_LIBCRC32C) += libcrc32c.o | 63 | obj-$(CONFIG_LIBCRC32C) += libcrc32c.o |
64 | obj-$(CONFIG_CRC8) += crc8.o | ||
64 | obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o | 65 | obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o |
65 | 66 | ||
66 | obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/ | 67 | obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/ |
@@ -112,6 +113,8 @@ obj-$(CONFIG_AVERAGE) += average.o | |||
112 | 113 | ||
113 | obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o | 114 | obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o |
114 | 115 | ||
116 | obj-$(CONFIG_CORDIC) += cordic.o | ||
117 | |||
115 | hostprogs-y := gen_crc32table | 118 | hostprogs-y := gen_crc32table |
116 | clean-files := crc32table.h | 119 | clean-files := crc32table.h |
117 | 120 | ||
diff --git a/lib/bitmap.c b/lib/bitmap.c index 41baf02924e6..3f3b68199d74 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c | |||
@@ -572,7 +572,7 @@ EXPORT_SYMBOL(bitmap_scnlistprintf); | |||
572 | 572 | ||
573 | /** | 573 | /** |
574 | * __bitmap_parselist - convert list format ASCII string to bitmap | 574 | * __bitmap_parselist - convert list format ASCII string to bitmap |
575 | * @bp: read nul-terminated user string from this buffer | 575 | * @buf: read nul-terminated user string from this buffer |
576 | * @buflen: buffer size in bytes. If string is smaller than this | 576 | * @buflen: buffer size in bytes. If string is smaller than this |
577 | * then it must be terminated with a \0. | 577 | * then it must be terminated with a \0. |
578 | * @is_user: location of buffer, 0 indicates kernel space | 578 | * @is_user: location of buffer, 0 indicates kernel space |
diff --git a/lib/checksum.c b/lib/checksum.c index 097508732f34..8df2f91e6d98 100644 --- a/lib/checksum.c +++ b/lib/checksum.c | |||
@@ -49,7 +49,7 @@ static inline unsigned short from32to16(unsigned int x) | |||
49 | 49 | ||
50 | static unsigned int do_csum(const unsigned char *buff, int len) | 50 | static unsigned int do_csum(const unsigned char *buff, int len) |
51 | { | 51 | { |
52 | int odd, count; | 52 | int odd; |
53 | unsigned int result = 0; | 53 | unsigned int result = 0; |
54 | 54 | ||
55 | if (len <= 0) | 55 | if (len <= 0) |
@@ -64,25 +64,22 @@ static unsigned int do_csum(const unsigned char *buff, int len) | |||
64 | len--; | 64 | len--; |
65 | buff++; | 65 | buff++; |
66 | } | 66 | } |
67 | count = len >> 1; /* nr of 16-bit words.. */ | 67 | if (len >= 2) { |
68 | if (count) { | ||
69 | if (2 & (unsigned long) buff) { | 68 | if (2 & (unsigned long) buff) { |
70 | result += *(unsigned short *) buff; | 69 | result += *(unsigned short *) buff; |
71 | count--; | ||
72 | len -= 2; | 70 | len -= 2; |
73 | buff += 2; | 71 | buff += 2; |
74 | } | 72 | } |
75 | count >>= 1; /* nr of 32-bit words.. */ | 73 | if (len >= 4) { |
76 | if (count) { | 74 | const unsigned char *end = buff + ((unsigned)len & ~3); |
77 | unsigned int carry = 0; | 75 | unsigned int carry = 0; |
78 | do { | 76 | do { |
79 | unsigned int w = *(unsigned int *) buff; | 77 | unsigned int w = *(unsigned int *) buff; |
80 | count--; | ||
81 | buff += 4; | 78 | buff += 4; |
82 | result += carry; | 79 | result += carry; |
83 | result += w; | 80 | result += w; |
84 | carry = (w > result); | 81 | carry = (w > result); |
85 | } while (count); | 82 | } while (buff < end); |
86 | result += carry; | 83 | result += carry; |
87 | result = (result & 0xffff) + (result >> 16); | 84 | result = (result & 0xffff) + (result >> 16); |
88 | } | 85 | } |
diff --git a/lib/cordic.c b/lib/cordic.c new file mode 100644 index 000000000000..aa27a88d7e04 --- /dev/null +++ b/lib/cordic.c | |||
@@ -0,0 +1,101 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2011 Broadcom Corporation | ||
3 | * | ||
4 | * Permission to use, copy, modify, and/or distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/cordic.h> | ||
18 | |||
19 | #define CORDIC_ANGLE_GEN 39797 | ||
20 | #define CORDIC_PRECISION_SHIFT 16 | ||
21 | #define CORDIC_NUM_ITER (CORDIC_PRECISION_SHIFT + 2) | ||
22 | |||
23 | #define FIXED(X) ((s32)((X) << CORDIC_PRECISION_SHIFT)) | ||
24 | #define FLOAT(X) (((X) >= 0) \ | ||
25 | ? ((((X) >> (CORDIC_PRECISION_SHIFT - 1)) + 1) >> 1) \ | ||
26 | : -((((-(X)) >> (CORDIC_PRECISION_SHIFT - 1)) + 1) >> 1)) | ||
27 | |||
28 | static const s32 arctan_table[] = { | ||
29 | 2949120, | ||
30 | 1740967, | ||
31 | 919879, | ||
32 | 466945, | ||
33 | 234379, | ||
34 | 117304, | ||
35 | 58666, | ||
36 | 29335, | ||
37 | 14668, | ||
38 | 7334, | ||
39 | 3667, | ||
40 | 1833, | ||
41 | 917, | ||
42 | 458, | ||
43 | 229, | ||
44 | 115, | ||
45 | 57, | ||
46 | 29 | ||
47 | }; | ||
48 | |||
49 | /* | ||
50 | * cordic_calc_iq() - calculates the i/q coordinate for given angle | ||
51 | * | ||
52 | * theta: angle in degrees for which i/q coordinate is to be calculated | ||
53 | * coord: function output parameter holding the i/q coordinate | ||
54 | */ | ||
55 | struct cordic_iq cordic_calc_iq(s32 theta) | ||
56 | { | ||
57 | struct cordic_iq coord; | ||
58 | s32 angle, valtmp; | ||
59 | unsigned iter; | ||
60 | int signx = 1; | ||
61 | int signtheta; | ||
62 | |||
63 | coord.i = CORDIC_ANGLE_GEN; | ||
64 | coord.q = 0; | ||
65 | angle = 0; | ||
66 | |||
67 | theta = FIXED(theta); | ||
68 | signtheta = (theta < 0) ? -1 : 1; | ||
69 | theta = ((theta + FIXED(180) * signtheta) % FIXED(360)) - | ||
70 | FIXED(180) * signtheta; | ||
71 | |||
72 | if (FLOAT(theta) > 90) { | ||
73 | theta -= FIXED(180); | ||
74 | signx = -1; | ||
75 | } else if (FLOAT(theta) < -90) { | ||
76 | theta += FIXED(180); | ||
77 | signx = -1; | ||
78 | } | ||
79 | |||
80 | for (iter = 0; iter < CORDIC_NUM_ITER; iter++) { | ||
81 | if (theta > angle) { | ||
82 | valtmp = coord.i - (coord.q >> iter); | ||
83 | coord.q += (coord.i >> iter); | ||
84 | angle += arctan_table[iter]; | ||
85 | } else { | ||
86 | valtmp = coord.i + (coord.q >> iter); | ||
87 | coord.q -= (coord.i >> iter); | ||
88 | angle -= arctan_table[iter]; | ||
89 | } | ||
90 | coord.i = valtmp; | ||
91 | } | ||
92 | |||
93 | coord.i *= signx; | ||
94 | coord.q *= signx; | ||
95 | return coord; | ||
96 | } | ||
97 | EXPORT_SYMBOL(cordic_calc_iq); | ||
98 | |||
99 | MODULE_DESCRIPTION("Cordic functions"); | ||
100 | MODULE_AUTHOR("Broadcom Corporation"); | ||
101 | MODULE_LICENSE("Dual BSD/GPL"); | ||
diff --git a/lib/crc8.c b/lib/crc8.c new file mode 100644 index 000000000000..87b59cafdb83 --- /dev/null +++ b/lib/crc8.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2011 Broadcom Corporation | ||
3 | * | ||
4 | * Permission to use, copy, modify, and/or distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/crc8.h> | ||
21 | #include <linux/printk.h> | ||
22 | |||
23 | /* | ||
24 | * crc8_populate_msb - fill crc table for given polynomial in reverse bit order. | ||
25 | * | ||
26 | * table: table to be filled. | ||
27 | * polynomial: polynomial for which table is to be filled. | ||
28 | */ | ||
29 | void crc8_populate_msb(u8 table[CRC8_TABLE_SIZE], u8 polynomial) | ||
30 | { | ||
31 | int i, j; | ||
32 | const u8 msbit = 0x80; | ||
33 | u8 t = msbit; | ||
34 | |||
35 | table[0] = 0; | ||
36 | |||
37 | for (i = 1; i < CRC8_TABLE_SIZE; i *= 2) { | ||
38 | t = (t << 1) ^ (t & msbit ? polynomial : 0); | ||
39 | for (j = 0; j < i; j++) | ||
40 | table[i+j] = table[j] ^ t; | ||
41 | } | ||
42 | } | ||
43 | EXPORT_SYMBOL(crc8_populate_msb); | ||
44 | |||
45 | /* | ||
46 | * crc8_populate_lsb - fill crc table for given polynomial in regular bit order. | ||
47 | * | ||
48 | * table: table to be filled. | ||
49 | * polynomial: polynomial for which table is to be filled. | ||
50 | */ | ||
51 | void crc8_populate_lsb(u8 table[CRC8_TABLE_SIZE], u8 polynomial) | ||
52 | { | ||
53 | int i, j; | ||
54 | u8 t = 1; | ||
55 | |||
56 | table[0] = 0; | ||
57 | |||
58 | for (i = (CRC8_TABLE_SIZE >> 1); i; i >>= 1) { | ||
59 | t = (t >> 1) ^ (t & 1 ? polynomial : 0); | ||
60 | for (j = 0; j < CRC8_TABLE_SIZE; j += 2*i) | ||
61 | table[i+j] = table[j] ^ t; | ||
62 | } | ||
63 | } | ||
64 | EXPORT_SYMBOL(crc8_populate_lsb); | ||
65 | |||
66 | /* | ||
67 | * crc8 - calculate a crc8 over the given input data. | ||
68 | * | ||
69 | * table: crc table used for calculation. | ||
70 | * pdata: pointer to data buffer. | ||
71 | * nbytes: number of bytes in data buffer. | ||
72 | * crc: previous returned crc8 value. | ||
73 | */ | ||
74 | u8 crc8(const u8 table[CRC8_TABLE_SIZE], u8 *pdata, size_t nbytes, u8 crc) | ||
75 | { | ||
76 | /* loop over the buffer data */ | ||
77 | while (nbytes-- > 0) | ||
78 | crc = table[(crc ^ *pdata++) & 0xff]; | ||
79 | |||
80 | return crc; | ||
81 | } | ||
82 | EXPORT_SYMBOL(crc8); | ||
83 | |||
84 | MODULE_DESCRIPTION("CRC8 (by Williams, Ross N.) function"); | ||
85 | MODULE_AUTHOR("Broadcom Corporation"); | ||
86 | MODULE_LICENSE("Dual BSD/GPL"); | ||
diff --git a/lib/debugobjects.c b/lib/debugobjects.c index 9d86e45086f5..a78b7c6e042c 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c | |||
@@ -198,7 +198,7 @@ static void free_object(struct debug_obj *obj) | |||
198 | * initialized: | 198 | * initialized: |
199 | */ | 199 | */ |
200 | if (obj_pool_free > ODEBUG_POOL_SIZE && obj_cache) | 200 | if (obj_pool_free > ODEBUG_POOL_SIZE && obj_cache) |
201 | sched = !work_pending(&debug_obj_work); | 201 | sched = keventd_up() && !work_pending(&debug_obj_work); |
202 | hlist_add_head(&obj->node, &obj_pool); | 202 | hlist_add_head(&obj->node, &obj_pool); |
203 | obj_pool_free++; | 203 | obj_pool_free++; |
204 | obj_pool_used--; | 204 | obj_pool_used--; |
diff --git a/lib/kobject.c b/lib/kobject.c index 82dc34c095c2..640bd98a4c8a 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
@@ -948,14 +948,14 @@ const struct kobj_ns_type_operations *kobj_ns_ops(struct kobject *kobj) | |||
948 | } | 948 | } |
949 | 949 | ||
950 | 950 | ||
951 | const void *kobj_ns_current(enum kobj_ns_type type) | 951 | void *kobj_ns_grab_current(enum kobj_ns_type type) |
952 | { | 952 | { |
953 | const void *ns = NULL; | 953 | void *ns = NULL; |
954 | 954 | ||
955 | spin_lock(&kobj_ns_type_lock); | 955 | spin_lock(&kobj_ns_type_lock); |
956 | if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES) && | 956 | if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES) && |
957 | kobj_ns_ops_tbl[type]) | 957 | kobj_ns_ops_tbl[type]) |
958 | ns = kobj_ns_ops_tbl[type]->current_ns(); | 958 | ns = kobj_ns_ops_tbl[type]->grab_current_ns(); |
959 | spin_unlock(&kobj_ns_type_lock); | 959 | spin_unlock(&kobj_ns_type_lock); |
960 | 960 | ||
961 | return ns; | 961 | return ns; |
@@ -987,23 +987,15 @@ const void *kobj_ns_initial(enum kobj_ns_type type) | |||
987 | return ns; | 987 | return ns; |
988 | } | 988 | } |
989 | 989 | ||
990 | /* | 990 | void kobj_ns_drop(enum kobj_ns_type type, void *ns) |
991 | * kobj_ns_exit - invalidate a namespace tag | ||
992 | * | ||
993 | * @type: the namespace type (i.e. KOBJ_NS_TYPE_NET) | ||
994 | * @ns: the actual namespace being invalidated | ||
995 | * | ||
996 | * This is called when a tag is no longer valid. For instance, | ||
997 | * when a network namespace exits, it uses this helper to | ||
998 | * make sure no sb's sysfs_info points to the now-invalidated | ||
999 | * netns. | ||
1000 | */ | ||
1001 | void kobj_ns_exit(enum kobj_ns_type type, const void *ns) | ||
1002 | { | 991 | { |
1003 | sysfs_exit_ns(type, ns); | 992 | spin_lock(&kobj_ns_type_lock); |
993 | if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES) && | ||
994 | kobj_ns_ops_tbl[type] && kobj_ns_ops_tbl[type]->drop_ns) | ||
995 | kobj_ns_ops_tbl[type]->drop_ns(ns); | ||
996 | spin_unlock(&kobj_ns_type_lock); | ||
1004 | } | 997 | } |
1005 | 998 | ||
1006 | |||
1007 | EXPORT_SYMBOL(kobject_get); | 999 | EXPORT_SYMBOL(kobject_get); |
1008 | EXPORT_SYMBOL(kobject_put); | 1000 | EXPORT_SYMBOL(kobject_put); |
1009 | EXPORT_SYMBOL(kobject_del); | 1001 | EXPORT_SYMBOL(kobject_del); |