diff options
author | Jiri Kosina <jkosina@suse.cz> | 2010-06-16 12:08:13 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2010-06-16 12:08:13 -0400 |
commit | f1bbbb6912662b9f6070c5bfc4ca9eb1f06a9d5b (patch) | |
tree | c2c130a74be25b0b2dff992e1a195e2728bdaadd /lib | |
parent | fd0961ff67727482bb20ca7e8ea97b83e9de2ddb (diff) | |
parent | 7e27d6e778cd87b6f2415515d7127eba53fe5d02 (diff) |
Merge branch 'master' into for-next
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig.debug | 28 | ||||
-rw-r--r-- | lib/Makefile | 3 | ||||
-rw-r--r-- | lib/atomic64_test.c | 4 | ||||
-rw-r--r-- | lib/bug.c | 2 | ||||
-rw-r--r-- | lib/cpu-notifier-error-inject.c | 63 | ||||
-rw-r--r-- | lib/crc32.c | 24 | ||||
-rw-r--r-- | lib/dynamic_debug.c | 2 | ||||
-rw-r--r-- | lib/gen_crc32table.c | 47 | ||||
-rw-r--r-- | lib/hexdump.c | 54 | ||||
-rw-r--r-- | lib/idr.c | 5 | ||||
-rw-r--r-- | lib/kobject_uevent.c | 3 | ||||
-rw-r--r-- | lib/radix-tree.c | 4 | ||||
-rw-r--r-- | lib/random32.c | 38 | ||||
-rw-r--r-- | lib/swiotlb.c | 31 | ||||
-rw-r--r-- | lib/uuid.c | 53 | ||||
-rw-r--r-- | lib/vsprintf.c | 69 |
16 files changed, 296 insertions, 134 deletions
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index d85be90d5888..e722e9d62221 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
@@ -898,6 +898,18 @@ config LKDTM | |||
898 | Documentation on how to use the module can be found in | 898 | Documentation on how to use the module can be found in |
899 | Documentation/fault-injection/provoke-crashes.txt | 899 | Documentation/fault-injection/provoke-crashes.txt |
900 | 900 | ||
901 | config CPU_NOTIFIER_ERROR_INJECT | ||
902 | tristate "CPU notifier error injection module" | ||
903 | depends on HOTPLUG_CPU && DEBUG_KERNEL | ||
904 | help | ||
905 | This option provides a kernel module that can be used to test | ||
906 | the error handling of the cpu notifiers | ||
907 | |||
908 | To compile this code as a module, choose M here: the module will | ||
909 | be called cpu-notifier-error-inject. | ||
910 | |||
911 | If unsure, say N. | ||
912 | |||
901 | config FAULT_INJECTION | 913 | config FAULT_INJECTION |
902 | bool "Fault-injection framework" | 914 | bool "Fault-injection framework" |
903 | depends on DEBUG_KERNEL | 915 | depends on DEBUG_KERNEL |
@@ -1039,10 +1051,10 @@ config DYNAMIC_DEBUG | |||
1039 | 1051 | ||
1040 | Usage: | 1052 | Usage: |
1041 | 1053 | ||
1042 | Dynamic debugging is controlled via the 'dynamic_debug/ddebug' file, | 1054 | Dynamic debugging is controlled via the 'dynamic_debug/control' file, |
1043 | which is contained in the 'debugfs' filesystem. Thus, the debugfs | 1055 | which is contained in the 'debugfs' filesystem. Thus, the debugfs |
1044 | filesystem must first be mounted before making use of this feature. | 1056 | filesystem must first be mounted before making use of this feature. |
1045 | We refer the control file as: <debugfs>/dynamic_debug/ddebug. This | 1057 | We refer the control file as: <debugfs>/dynamic_debug/control. This |
1046 | file contains a list of the debug statements that can be enabled. The | 1058 | file contains a list of the debug statements that can be enabled. The |
1047 | format for each line of the file is: | 1059 | format for each line of the file is: |
1048 | 1060 | ||
@@ -1057,7 +1069,7 @@ config DYNAMIC_DEBUG | |||
1057 | 1069 | ||
1058 | From a live system: | 1070 | From a live system: |
1059 | 1071 | ||
1060 | nullarbor:~ # cat <debugfs>/dynamic_debug/ddebug | 1072 | nullarbor:~ # cat <debugfs>/dynamic_debug/control |
1061 | # filename:lineno [module]function flags format | 1073 | # filename:lineno [module]function flags format |
1062 | fs/aio.c:222 [aio]__put_ioctx - "__put_ioctx:\040freeing\040%p\012" | 1074 | fs/aio.c:222 [aio]__put_ioctx - "__put_ioctx:\040freeing\040%p\012" |
1063 | fs/aio.c:248 [aio]ioctx_alloc - "ENOMEM:\040nr_events\040too\040high\012" | 1075 | fs/aio.c:248 [aio]ioctx_alloc - "ENOMEM:\040nr_events\040too\040high\012" |
@@ -1067,23 +1079,23 @@ config DYNAMIC_DEBUG | |||
1067 | 1079 | ||
1068 | // enable the message at line 1603 of file svcsock.c | 1080 | // enable the message at line 1603 of file svcsock.c |
1069 | nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' > | 1081 | nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' > |
1070 | <debugfs>/dynamic_debug/ddebug | 1082 | <debugfs>/dynamic_debug/control |
1071 | 1083 | ||
1072 | // enable all the messages in file svcsock.c | 1084 | // enable all the messages in file svcsock.c |
1073 | nullarbor:~ # echo -n 'file svcsock.c +p' > | 1085 | nullarbor:~ # echo -n 'file svcsock.c +p' > |
1074 | <debugfs>/dynamic_debug/ddebug | 1086 | <debugfs>/dynamic_debug/control |
1075 | 1087 | ||
1076 | // enable all the messages in the NFS server module | 1088 | // enable all the messages in the NFS server module |
1077 | nullarbor:~ # echo -n 'module nfsd +p' > | 1089 | nullarbor:~ # echo -n 'module nfsd +p' > |
1078 | <debugfs>/dynamic_debug/ddebug | 1090 | <debugfs>/dynamic_debug/control |
1079 | 1091 | ||
1080 | // enable all 12 messages in the function svc_process() | 1092 | // enable all 12 messages in the function svc_process() |
1081 | nullarbor:~ # echo -n 'func svc_process +p' > | 1093 | nullarbor:~ # echo -n 'func svc_process +p' > |
1082 | <debugfs>/dynamic_debug/ddebug | 1094 | <debugfs>/dynamic_debug/control |
1083 | 1095 | ||
1084 | // disable all 12 messages in the function svc_process() | 1096 | // disable all 12 messages in the function svc_process() |
1085 | nullarbor:~ # echo -n 'func svc_process -p' > | 1097 | nullarbor:~ # echo -n 'func svc_process -p' > |
1086 | <debugfs>/dynamic_debug/ddebug | 1098 | <debugfs>/dynamic_debug/control |
1087 | 1099 | ||
1088 | See Documentation/dynamic-debug-howto.txt for additional information. | 1100 | See Documentation/dynamic-debug-howto.txt for additional information. |
1089 | 1101 | ||
diff --git a/lib/Makefile b/lib/Makefile index 9e6d3c29d73a..3f1062cbbff4 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -21,7 +21,7 @@ lib-y += kobject.o kref.o klist.o | |||
21 | 21 | ||
22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | 22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ | 23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ |
24 | string_helpers.o gcd.o lcm.o list_sort.o | 24 | string_helpers.o gcd.o lcm.o list_sort.o uuid.o |
25 | 25 | ||
26 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) | 26 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) |
27 | CFLAGS_kobject.o += -DDEBUG | 27 | CFLAGS_kobject.o += -DDEBUG |
@@ -85,6 +85,7 @@ obj-$(CONFIG_AUDIT_GENERIC) += audit.o | |||
85 | obj-$(CONFIG_SWIOTLB) += swiotlb.o | 85 | obj-$(CONFIG_SWIOTLB) += swiotlb.o |
86 | obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o | 86 | obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o |
87 | obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o | 87 | obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o |
88 | obj-$(CONFIG_CPU_NOTIFIER_ERROR_INJECT) += cpu-notifier-error-inject.o | ||
88 | 89 | ||
89 | lib-$(CONFIG_GENERIC_BUG) += bug.o | 90 | lib-$(CONFIG_GENERIC_BUG) += bug.o |
90 | 91 | ||
diff --git a/lib/atomic64_test.c b/lib/atomic64_test.c index 65e482caf5e9..250ed11d3ed2 100644 --- a/lib/atomic64_test.c +++ b/lib/atomic64_test.c | |||
@@ -9,6 +9,7 @@ | |||
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
10 | */ | 10 | */ |
11 | #include <linux/init.h> | 11 | #include <linux/init.h> |
12 | #include <linux/kernel.h> | ||
12 | #include <asm/atomic.h> | 13 | #include <asm/atomic.h> |
13 | 14 | ||
14 | #define INIT(c) do { atomic64_set(&v, c); r = c; } while (0) | 15 | #define INIT(c) do { atomic64_set(&v, c); r = c; } while (0) |
@@ -112,7 +113,8 @@ static __init int test_atomic64(void) | |||
112 | r += one; | 113 | r += one; |
113 | BUG_ON(v.counter != r); | 114 | BUG_ON(v.counter != r); |
114 | 115 | ||
115 | #if defined(CONFIG_X86) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(_ASM_GENERIC_ATOMIC64_H) | 116 | #if defined(CONFIG_X86) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \ |
117 | defined(CONFIG_S390) || defined(_ASM_GENERIC_ATOMIC64_H) | ||
116 | INIT(onestwos); | 118 | INIT(onestwos); |
117 | BUG_ON(atomic64_dec_if_positive(&v) != (onestwos - 1)); | 119 | BUG_ON(atomic64_dec_if_positive(&v) != (onestwos - 1)); |
118 | r -= one; | 120 | r -= one; |
@@ -165,7 +165,7 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs) | |||
165 | (void *)bugaddr); | 165 | (void *)bugaddr); |
166 | 166 | ||
167 | show_regs(regs); | 167 | show_regs(regs); |
168 | add_taint(TAINT_WARN); | 168 | add_taint(BUG_GET_TAINT(bug)); |
169 | return BUG_TRAP_TYPE_WARN; | 169 | return BUG_TRAP_TYPE_WARN; |
170 | } | 170 | } |
171 | 171 | ||
diff --git a/lib/cpu-notifier-error-inject.c b/lib/cpu-notifier-error-inject.c new file mode 100644 index 000000000000..4dc20321b0d5 --- /dev/null +++ b/lib/cpu-notifier-error-inject.c | |||
@@ -0,0 +1,63 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/cpu.h> | ||
3 | #include <linux/module.h> | ||
4 | #include <linux/notifier.h> | ||
5 | |||
6 | static int priority; | ||
7 | static int cpu_up_prepare_error; | ||
8 | static int cpu_down_prepare_error; | ||
9 | |||
10 | module_param(priority, int, 0); | ||
11 | MODULE_PARM_DESC(priority, "specify cpu notifier priority"); | ||
12 | |||
13 | module_param(cpu_up_prepare_error, int, 0644); | ||
14 | MODULE_PARM_DESC(cpu_up_prepare_error, | ||
15 | "specify error code to inject CPU_UP_PREPARE action"); | ||
16 | |||
17 | module_param(cpu_down_prepare_error, int, 0644); | ||
18 | MODULE_PARM_DESC(cpu_down_prepare_error, | ||
19 | "specify error code to inject CPU_DOWN_PREPARE action"); | ||
20 | |||
21 | static int err_inject_cpu_callback(struct notifier_block *nfb, | ||
22 | unsigned long action, void *hcpu) | ||
23 | { | ||
24 | int err = 0; | ||
25 | |||
26 | switch (action) { | ||
27 | case CPU_UP_PREPARE: | ||
28 | case CPU_UP_PREPARE_FROZEN: | ||
29 | err = cpu_up_prepare_error; | ||
30 | break; | ||
31 | case CPU_DOWN_PREPARE: | ||
32 | case CPU_DOWN_PREPARE_FROZEN: | ||
33 | err = cpu_down_prepare_error; | ||
34 | break; | ||
35 | } | ||
36 | if (err) | ||
37 | printk(KERN_INFO "Injecting error (%d) at cpu notifier\n", err); | ||
38 | |||
39 | return notifier_from_errno(err); | ||
40 | } | ||
41 | |||
42 | static struct notifier_block err_inject_cpu_notifier = { | ||
43 | .notifier_call = err_inject_cpu_callback, | ||
44 | }; | ||
45 | |||
46 | static int err_inject_init(void) | ||
47 | { | ||
48 | err_inject_cpu_notifier.priority = priority; | ||
49 | |||
50 | return register_hotcpu_notifier(&err_inject_cpu_notifier); | ||
51 | } | ||
52 | |||
53 | static void err_inject_exit(void) | ||
54 | { | ||
55 | unregister_hotcpu_notifier(&err_inject_cpu_notifier); | ||
56 | } | ||
57 | |||
58 | module_init(err_inject_init); | ||
59 | module_exit(err_inject_exit); | ||
60 | |||
61 | MODULE_DESCRIPTION("CPU notifier error injection module"); | ||
62 | MODULE_LICENSE("GPL"); | ||
63 | MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>"); | ||
diff --git a/lib/crc32.c b/lib/crc32.c index bc5b936e9142..4855995fcde9 100644 --- a/lib/crc32.c +++ b/lib/crc32.c | |||
@@ -48,12 +48,20 @@ MODULE_LICENSE("GPL"); | |||
48 | #if CRC_LE_BITS == 8 || CRC_BE_BITS == 8 | 48 | #if CRC_LE_BITS == 8 || CRC_BE_BITS == 8 |
49 | 49 | ||
50 | static inline u32 | 50 | static inline u32 |
51 | crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 *tab) | 51 | crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256]) |
52 | { | 52 | { |
53 | # ifdef __LITTLE_ENDIAN | 53 | # ifdef __LITTLE_ENDIAN |
54 | # define DO_CRC(x) crc = tab[(crc ^ (x)) & 255 ] ^ (crc >> 8) | 54 | # define DO_CRC(x) crc = tab[0][(crc ^ (x)) & 255] ^ (crc >> 8) |
55 | # define DO_CRC4 crc = tab[3][(crc) & 255] ^ \ | ||
56 | tab[2][(crc >> 8) & 255] ^ \ | ||
57 | tab[1][(crc >> 16) & 255] ^ \ | ||
58 | tab[0][(crc >> 24) & 255] | ||
55 | # else | 59 | # else |
56 | # define DO_CRC(x) crc = tab[((crc >> 24) ^ (x)) & 255] ^ (crc << 8) | 60 | # define DO_CRC(x) crc = tab[0][((crc >> 24) ^ (x)) & 255] ^ (crc << 8) |
61 | # define DO_CRC4 crc = tab[0][(crc) & 255] ^ \ | ||
62 | tab[1][(crc >> 8) & 255] ^ \ | ||
63 | tab[2][(crc >> 16) & 255] ^ \ | ||
64 | tab[3][(crc >> 24) & 255] | ||
57 | # endif | 65 | # endif |
58 | const u32 *b; | 66 | const u32 *b; |
59 | size_t rem_len; | 67 | size_t rem_len; |
@@ -70,10 +78,7 @@ crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 *tab) | |||
70 | b = (const u32 *)buf; | 78 | b = (const u32 *)buf; |
71 | for (--b; len; --len) { | 79 | for (--b; len; --len) { |
72 | crc ^= *++b; /* use pre increment for speed */ | 80 | crc ^= *++b; /* use pre increment for speed */ |
73 | DO_CRC(0); | 81 | DO_CRC4; |
74 | DO_CRC(0); | ||
75 | DO_CRC(0); | ||
76 | DO_CRC(0); | ||
77 | } | 82 | } |
78 | len = rem_len; | 83 | len = rem_len; |
79 | /* And the last few bytes */ | 84 | /* And the last few bytes */ |
@@ -85,6 +90,7 @@ crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 *tab) | |||
85 | } | 90 | } |
86 | return crc; | 91 | return crc; |
87 | #undef DO_CRC | 92 | #undef DO_CRC |
93 | #undef DO_CRC4 | ||
88 | } | 94 | } |
89 | #endif | 95 | #endif |
90 | /** | 96 | /** |
@@ -117,7 +123,7 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) | |||
117 | u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) | 123 | u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) |
118 | { | 124 | { |
119 | # if CRC_LE_BITS == 8 | 125 | # if CRC_LE_BITS == 8 |
120 | const u32 *tab = crc32table_le; | 126 | const u32 (*tab)[] = crc32table_le; |
121 | 127 | ||
122 | crc = __cpu_to_le32(crc); | 128 | crc = __cpu_to_le32(crc); |
123 | crc = crc32_body(crc, p, len, tab); | 129 | crc = crc32_body(crc, p, len, tab); |
@@ -174,7 +180,7 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) | |||
174 | u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) | 180 | u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) |
175 | { | 181 | { |
176 | # if CRC_BE_BITS == 8 | 182 | # if CRC_BE_BITS == 8 |
177 | const u32 *tab = crc32table_be; | 183 | const u32 (*tab)[] = crc32table_be; |
178 | 184 | ||
179 | crc = __cpu_to_be32(crc); | 185 | crc = __cpu_to_be32(crc); |
180 | crc = crc32_body(crc, p, len, tab); | 186 | crc = crc32_body(crc, p, len, tab); |
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index d6b8b9b1abfe..3df8eb17a607 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c | |||
@@ -456,7 +456,7 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, | |||
456 | __func__, (int)len); | 456 | __func__, (int)len); |
457 | 457 | ||
458 | nwords = ddebug_tokenize(tmpbuf, words, MAXWORDS); | 458 | nwords = ddebug_tokenize(tmpbuf, words, MAXWORDS); |
459 | if (nwords < 0) | 459 | if (nwords <= 0) |
460 | return -EINVAL; | 460 | return -EINVAL; |
461 | if (ddebug_parse_query(words, nwords-1, &query)) | 461 | if (ddebug_parse_query(words, nwords-1, &query)) |
462 | return -EINVAL; | 462 | return -EINVAL; |
diff --git a/lib/gen_crc32table.c b/lib/gen_crc32table.c index bea5d97df991..85d0e412a04f 100644 --- a/lib/gen_crc32table.c +++ b/lib/gen_crc32table.c | |||
@@ -7,8 +7,8 @@ | |||
7 | #define LE_TABLE_SIZE (1 << CRC_LE_BITS) | 7 | #define LE_TABLE_SIZE (1 << CRC_LE_BITS) |
8 | #define BE_TABLE_SIZE (1 << CRC_BE_BITS) | 8 | #define BE_TABLE_SIZE (1 << CRC_BE_BITS) |
9 | 9 | ||
10 | static uint32_t crc32table_le[LE_TABLE_SIZE]; | 10 | static uint32_t crc32table_le[4][LE_TABLE_SIZE]; |
11 | static uint32_t crc32table_be[BE_TABLE_SIZE]; | 11 | static uint32_t crc32table_be[4][BE_TABLE_SIZE]; |
12 | 12 | ||
13 | /** | 13 | /** |
14 | * crc32init_le() - allocate and initialize LE table data | 14 | * crc32init_le() - allocate and initialize LE table data |
@@ -22,12 +22,19 @@ static void crc32init_le(void) | |||
22 | unsigned i, j; | 22 | unsigned i, j; |
23 | uint32_t crc = 1; | 23 | uint32_t crc = 1; |
24 | 24 | ||
25 | crc32table_le[0] = 0; | 25 | crc32table_le[0][0] = 0; |
26 | 26 | ||
27 | for (i = 1 << (CRC_LE_BITS - 1); i; i >>= 1) { | 27 | for (i = 1 << (CRC_LE_BITS - 1); i; i >>= 1) { |
28 | crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); | 28 | crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); |
29 | for (j = 0; j < LE_TABLE_SIZE; j += 2 * i) | 29 | for (j = 0; j < LE_TABLE_SIZE; j += 2 * i) |
30 | crc32table_le[i + j] = crc ^ crc32table_le[j]; | 30 | crc32table_le[0][i + j] = crc ^ crc32table_le[0][j]; |
31 | } | ||
32 | for (i = 0; i < LE_TABLE_SIZE; i++) { | ||
33 | crc = crc32table_le[0][i]; | ||
34 | for (j = 1; j < 4; j++) { | ||
35 | crc = crc32table_le[0][crc & 0xff] ^ (crc >> 8); | ||
36 | crc32table_le[j][i] = crc; | ||
37 | } | ||
31 | } | 38 | } |
32 | } | 39 | } |
33 | 40 | ||
@@ -39,25 +46,35 @@ static void crc32init_be(void) | |||
39 | unsigned i, j; | 46 | unsigned i, j; |
40 | uint32_t crc = 0x80000000; | 47 | uint32_t crc = 0x80000000; |
41 | 48 | ||
42 | crc32table_be[0] = 0; | 49 | crc32table_be[0][0] = 0; |
43 | 50 | ||
44 | for (i = 1; i < BE_TABLE_SIZE; i <<= 1) { | 51 | for (i = 1; i < BE_TABLE_SIZE; i <<= 1) { |
45 | crc = (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 0); | 52 | crc = (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 0); |
46 | for (j = 0; j < i; j++) | 53 | for (j = 0; j < i; j++) |
47 | crc32table_be[i + j] = crc ^ crc32table_be[j]; | 54 | crc32table_be[0][i + j] = crc ^ crc32table_be[0][j]; |
55 | } | ||
56 | for (i = 0; i < BE_TABLE_SIZE; i++) { | ||
57 | crc = crc32table_be[0][i]; | ||
58 | for (j = 1; j < 4; j++) { | ||
59 | crc = crc32table_be[0][(crc >> 24) & 0xff] ^ (crc << 8); | ||
60 | crc32table_be[j][i] = crc; | ||
61 | } | ||
48 | } | 62 | } |
49 | } | 63 | } |
50 | 64 | ||
51 | static void output_table(uint32_t table[], int len, char *trans) | 65 | static void output_table(uint32_t table[4][256], int len, char *trans) |
52 | { | 66 | { |
53 | int i; | 67 | int i, j; |
54 | 68 | ||
55 | for (i = 0; i < len - 1; i++) { | 69 | for (j = 0 ; j < 4; j++) { |
56 | if (i % ENTRIES_PER_LINE == 0) | 70 | printf("{"); |
57 | printf("\n"); | 71 | for (i = 0; i < len - 1; i++) { |
58 | printf("%s(0x%8.8xL), ", trans, table[i]); | 72 | if (i % ENTRIES_PER_LINE == 0) |
73 | printf("\n"); | ||
74 | printf("%s(0x%8.8xL), ", trans, table[j][i]); | ||
75 | } | ||
76 | printf("%s(0x%8.8xL)},\n", trans, table[j][len - 1]); | ||
59 | } | 77 | } |
60 | printf("%s(0x%8.8xL)\n", trans, table[len - 1]); | ||
61 | } | 78 | } |
62 | 79 | ||
63 | int main(int argc, char** argv) | 80 | int main(int argc, char** argv) |
@@ -66,14 +83,14 @@ int main(int argc, char** argv) | |||
66 | 83 | ||
67 | if (CRC_LE_BITS > 1) { | 84 | if (CRC_LE_BITS > 1) { |
68 | crc32init_le(); | 85 | crc32init_le(); |
69 | printf("static const u32 crc32table_le[] = {"); | 86 | printf("static const u32 crc32table_le[4][256] = {"); |
70 | output_table(crc32table_le, LE_TABLE_SIZE, "tole"); | 87 | output_table(crc32table_le, LE_TABLE_SIZE, "tole"); |
71 | printf("};\n"); | 88 | printf("};\n"); |
72 | } | 89 | } |
73 | 90 | ||
74 | if (CRC_BE_BITS > 1) { | 91 | if (CRC_BE_BITS > 1) { |
75 | crc32init_be(); | 92 | crc32init_be(); |
76 | printf("static const u32 crc32table_be[] = {"); | 93 | printf("static const u32 crc32table_be[4][256] = {"); |
77 | output_table(crc32table_be, BE_TABLE_SIZE, "tobe"); | 94 | output_table(crc32table_be, BE_TABLE_SIZE, "tobe"); |
78 | printf("};\n"); | 95 | printf("};\n"); |
79 | } | 96 | } |
diff --git a/lib/hexdump.c b/lib/hexdump.c index 39af2560f765..5d7a4802c562 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c | |||
@@ -16,6 +16,24 @@ const char hex_asc[] = "0123456789abcdef"; | |||
16 | EXPORT_SYMBOL(hex_asc); | 16 | EXPORT_SYMBOL(hex_asc); |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * hex_to_bin - convert a hex digit to its real value | ||
20 | * @ch: ascii character represents hex digit | ||
21 | * | ||
22 | * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad | ||
23 | * input. | ||
24 | */ | ||
25 | int hex_to_bin(char ch) | ||
26 | { | ||
27 | if ((ch >= '0') && (ch <= '9')) | ||
28 | return ch - '0'; | ||
29 | ch = tolower(ch); | ||
30 | if ((ch >= 'a') && (ch <= 'f')) | ||
31 | return ch - 'a' + 10; | ||
32 | return -1; | ||
33 | } | ||
34 | EXPORT_SYMBOL(hex_to_bin); | ||
35 | |||
36 | /** | ||
19 | * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory | 37 | * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory |
20 | * @buf: data blob to dump | 38 | * @buf: data blob to dump |
21 | * @len: number of bytes in the @buf | 39 | * @len: number of bytes in the @buf |
@@ -34,7 +52,7 @@ EXPORT_SYMBOL(hex_asc); | |||
34 | * | 52 | * |
35 | * E.g.: | 53 | * E.g.: |
36 | * hex_dump_to_buffer(frame->data, frame->len, 16, 1, | 54 | * hex_dump_to_buffer(frame->data, frame->len, 16, 1, |
37 | * linebuf, sizeof(linebuf), 1); | 55 | * linebuf, sizeof(linebuf), true); |
38 | * | 56 | * |
39 | * example output buffer: | 57 | * example output buffer: |
40 | * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO | 58 | * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO |
@@ -65,8 +83,8 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize, | |||
65 | 83 | ||
66 | for (j = 0; j < ngroups; j++) | 84 | for (j = 0; j < ngroups; j++) |
67 | lx += scnprintf(linebuf + lx, linebuflen - lx, | 85 | lx += scnprintf(linebuf + lx, linebuflen - lx, |
68 | "%s%16.16llx", j ? " " : "", | 86 | "%s%16.16llx", j ? " " : "", |
69 | (unsigned long long)*(ptr8 + j)); | 87 | (unsigned long long)*(ptr8 + j)); |
70 | ascii_column = 17 * ngroups + 2; | 88 | ascii_column = 17 * ngroups + 2; |
71 | break; | 89 | break; |
72 | } | 90 | } |
@@ -77,7 +95,7 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize, | |||
77 | 95 | ||
78 | for (j = 0; j < ngroups; j++) | 96 | for (j = 0; j < ngroups; j++) |
79 | lx += scnprintf(linebuf + lx, linebuflen - lx, | 97 | lx += scnprintf(linebuf + lx, linebuflen - lx, |
80 | "%s%8.8x", j ? " " : "", *(ptr4 + j)); | 98 | "%s%8.8x", j ? " " : "", *(ptr4 + j)); |
81 | ascii_column = 9 * ngroups + 2; | 99 | ascii_column = 9 * ngroups + 2; |
82 | break; | 100 | break; |
83 | } | 101 | } |
@@ -88,7 +106,7 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize, | |||
88 | 106 | ||
89 | for (j = 0; j < ngroups; j++) | 107 | for (j = 0; j < ngroups; j++) |
90 | lx += scnprintf(linebuf + lx, linebuflen - lx, | 108 | lx += scnprintf(linebuf + lx, linebuflen - lx, |
91 | "%s%4.4x", j ? " " : "", *(ptr2 + j)); | 109 | "%s%4.4x", j ? " " : "", *(ptr2 + j)); |
92 | ascii_column = 5 * ngroups + 2; | 110 | ascii_column = 5 * ngroups + 2; |
93 | break; | 111 | break; |
94 | } | 112 | } |
@@ -111,9 +129,10 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize, | |||
111 | 129 | ||
112 | while (lx < (linebuflen - 1) && lx < (ascii_column - 1)) | 130 | while (lx < (linebuflen - 1) && lx < (ascii_column - 1)) |
113 | linebuf[lx++] = ' '; | 131 | linebuf[lx++] = ' '; |
114 | for (j = 0; (j < len) && (lx + 2) < linebuflen; j++) | 132 | for (j = 0; (j < len) && (lx + 2) < linebuflen; j++) { |
115 | linebuf[lx++] = (isascii(ptr[j]) && isprint(ptr[j])) ? ptr[j] | 133 | ch = ptr[j]; |
116 | : '.'; | 134 | linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.'; |
135 | } | ||
117 | nil: | 136 | nil: |
118 | linebuf[lx++] = '\0'; | 137 | linebuf[lx++] = '\0'; |
119 | } | 138 | } |
@@ -143,7 +162,7 @@ EXPORT_SYMBOL(hex_dump_to_buffer); | |||
143 | * | 162 | * |
144 | * E.g.: | 163 | * E.g.: |
145 | * print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS, | 164 | * print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS, |
146 | * 16, 1, frame->data, frame->len, 1); | 165 | * 16, 1, frame->data, frame->len, true); |
147 | * | 166 | * |
148 | * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode: | 167 | * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode: |
149 | * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO | 168 | * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO |
@@ -151,12 +170,12 @@ EXPORT_SYMBOL(hex_dump_to_buffer); | |||
151 | * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~. | 170 | * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~. |
152 | */ | 171 | */ |
153 | void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, | 172 | void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, |
154 | int rowsize, int groupsize, | 173 | int rowsize, int groupsize, |
155 | const void *buf, size_t len, bool ascii) | 174 | const void *buf, size_t len, bool ascii) |
156 | { | 175 | { |
157 | const u8 *ptr = buf; | 176 | const u8 *ptr = buf; |
158 | int i, linelen, remaining = len; | 177 | int i, linelen, remaining = len; |
159 | unsigned char linebuf[200]; | 178 | unsigned char linebuf[32 * 3 + 2 + 32 + 1]; |
160 | 179 | ||
161 | if (rowsize != 16 && rowsize != 32) | 180 | if (rowsize != 16 && rowsize != 32) |
162 | rowsize = 16; | 181 | rowsize = 16; |
@@ -164,13 +183,14 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, | |||
164 | for (i = 0; i < len; i += rowsize) { | 183 | for (i = 0; i < len; i += rowsize) { |
165 | linelen = min(remaining, rowsize); | 184 | linelen = min(remaining, rowsize); |
166 | remaining -= rowsize; | 185 | remaining -= rowsize; |
186 | |||
167 | hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, | 187 | hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, |
168 | linebuf, sizeof(linebuf), ascii); | 188 | linebuf, sizeof(linebuf), ascii); |
169 | 189 | ||
170 | switch (prefix_type) { | 190 | switch (prefix_type) { |
171 | case DUMP_PREFIX_ADDRESS: | 191 | case DUMP_PREFIX_ADDRESS: |
172 | printk("%s%s%*p: %s\n", level, prefix_str, | 192 | printk("%s%s%p: %s\n", |
173 | (int)(2 * sizeof(void *)), ptr + i, linebuf); | 193 | level, prefix_str, ptr + i, linebuf); |
174 | break; | 194 | break; |
175 | case DUMP_PREFIX_OFFSET: | 195 | case DUMP_PREFIX_OFFSET: |
176 | printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf); | 196 | printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf); |
@@ -196,9 +216,9 @@ EXPORT_SYMBOL(print_hex_dump); | |||
196 | * rowsize of 16, groupsize of 1, and ASCII output included. | 216 | * rowsize of 16, groupsize of 1, and ASCII output included. |
197 | */ | 217 | */ |
198 | void print_hex_dump_bytes(const char *prefix_str, int prefix_type, | 218 | void print_hex_dump_bytes(const char *prefix_str, int prefix_type, |
199 | const void *buf, size_t len) | 219 | const void *buf, size_t len) |
200 | { | 220 | { |
201 | print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1, | 221 | print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1, |
202 | buf, len, 1); | 222 | buf, len, true); |
203 | } | 223 | } |
204 | EXPORT_SYMBOL(print_hex_dump_bytes); | 224 | EXPORT_SYMBOL(print_hex_dump_bytes); |
@@ -445,6 +445,7 @@ EXPORT_SYMBOL(idr_remove); | |||
445 | void idr_remove_all(struct idr *idp) | 445 | void idr_remove_all(struct idr *idp) |
446 | { | 446 | { |
447 | int n, id, max; | 447 | int n, id, max; |
448 | int bt_mask; | ||
448 | struct idr_layer *p; | 449 | struct idr_layer *p; |
449 | struct idr_layer *pa[MAX_LEVEL]; | 450 | struct idr_layer *pa[MAX_LEVEL]; |
450 | struct idr_layer **paa = &pa[0]; | 451 | struct idr_layer **paa = &pa[0]; |
@@ -462,8 +463,10 @@ void idr_remove_all(struct idr *idp) | |||
462 | p = p->ary[(id >> n) & IDR_MASK]; | 463 | p = p->ary[(id >> n) & IDR_MASK]; |
463 | } | 464 | } |
464 | 465 | ||
466 | bt_mask = id; | ||
465 | id += 1 << n; | 467 | id += 1 << n; |
466 | while (n < fls(id)) { | 468 | /* Get the highest bit that the above add changed from 0->1. */ |
469 | while (n < fls(id ^ bt_mask)) { | ||
467 | if (p) | 470 | if (p) |
468 | free_layer(p); | 471 | free_layer(p); |
469 | n += IDR_BITS; | 472 | n += IDR_BITS; |
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c index 59c15511d58a..b93579504dfa 100644 --- a/lib/kobject_uevent.c +++ b/lib/kobject_uevent.c | |||
@@ -83,6 +83,7 @@ out: | |||
83 | return ret; | 83 | return ret; |
84 | } | 84 | } |
85 | 85 | ||
86 | #ifdef CONFIG_NET | ||
86 | static int kobj_bcast_filter(struct sock *dsk, struct sk_buff *skb, void *data) | 87 | static int kobj_bcast_filter(struct sock *dsk, struct sk_buff *skb, void *data) |
87 | { | 88 | { |
88 | struct kobject *kobj = data; | 89 | struct kobject *kobj = data; |
@@ -98,6 +99,7 @@ static int kobj_bcast_filter(struct sock *dsk, struct sk_buff *skb, void *data) | |||
98 | 99 | ||
99 | return 0; | 100 | return 0; |
100 | } | 101 | } |
102 | #endif | ||
101 | 103 | ||
102 | static int kobj_usermode_filter(struct kobject *kobj) | 104 | static int kobj_usermode_filter(struct kobject *kobj) |
103 | { | 105 | { |
@@ -378,6 +380,7 @@ static int uevent_net_init(struct net *net) | |||
378 | if (!ue_sk->sk) { | 380 | if (!ue_sk->sk) { |
379 | printk(KERN_ERR | 381 | printk(KERN_ERR |
380 | "kobject_uevent: unable to create netlink socket!\n"); | 382 | "kobject_uevent: unable to create netlink socket!\n"); |
383 | kfree(ue_sk); | ||
381 | return -ENODEV; | 384 | return -ENODEV; |
382 | } | 385 | } |
383 | mutex_lock(&uevent_sock_mutex); | 386 | mutex_lock(&uevent_sock_mutex); |
diff --git a/lib/radix-tree.c b/lib/radix-tree.c index 2a087e0f9863..05da38bcc298 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c | |||
@@ -656,7 +656,7 @@ EXPORT_SYMBOL(radix_tree_next_hole); | |||
656 | * | 656 | * |
657 | * Returns: the index of the hole if found, otherwise returns an index | 657 | * Returns: the index of the hole if found, otherwise returns an index |
658 | * outside of the set specified (in which case 'index - return >= max_scan' | 658 | * outside of the set specified (in which case 'index - return >= max_scan' |
659 | * will be true). In rare cases of wrap-around, LONG_MAX will be returned. | 659 | * will be true). In rare cases of wrap-around, ULONG_MAX will be returned. |
660 | * | 660 | * |
661 | * radix_tree_next_hole may be called under rcu_read_lock. However, like | 661 | * radix_tree_next_hole may be called under rcu_read_lock. However, like |
662 | * radix_tree_gang_lookup, this will not atomically search a snapshot of | 662 | * radix_tree_gang_lookup, this will not atomically search a snapshot of |
@@ -674,7 +674,7 @@ unsigned long radix_tree_prev_hole(struct radix_tree_root *root, | |||
674 | if (!radix_tree_lookup(root, index)) | 674 | if (!radix_tree_lookup(root, index)) |
675 | break; | 675 | break; |
676 | index--; | 676 | index--; |
677 | if (index == LONG_MAX) | 677 | if (index == ULONG_MAX) |
678 | break; | 678 | break; |
679 | } | 679 | } |
680 | 680 | ||
diff --git a/lib/random32.c b/lib/random32.c index 556d5ffe1106..fc3545a32771 100644 --- a/lib/random32.c +++ b/lib/random32.c | |||
@@ -39,13 +39,16 @@ | |||
39 | #include <linux/jiffies.h> | 39 | #include <linux/jiffies.h> |
40 | #include <linux/random.h> | 40 | #include <linux/random.h> |
41 | 41 | ||
42 | struct rnd_state { | ||
43 | u32 s1, s2, s3; | ||
44 | }; | ||
45 | |||
46 | static DEFINE_PER_CPU(struct rnd_state, net_rand_state); | 42 | static DEFINE_PER_CPU(struct rnd_state, net_rand_state); |
47 | 43 | ||
48 | static u32 __random32(struct rnd_state *state) | 44 | /** |
45 | * prandom32 - seeded pseudo-random number generator. | ||
46 | * @state: pointer to state structure holding seeded state. | ||
47 | * | ||
48 | * This is used for pseudo-randomness with no outside seeding. | ||
49 | * For more random results, use random32(). | ||
50 | */ | ||
51 | u32 prandom32(struct rnd_state *state) | ||
49 | { | 52 | { |
50 | #define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b) | 53 | #define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b) |
51 | 54 | ||
@@ -55,14 +58,7 @@ static u32 __random32(struct rnd_state *state) | |||
55 | 58 | ||
56 | return (state->s1 ^ state->s2 ^ state->s3); | 59 | return (state->s1 ^ state->s2 ^ state->s3); |
57 | } | 60 | } |
58 | 61 | EXPORT_SYMBOL(prandom32); | |
59 | /* | ||
60 | * Handle minimum values for seeds | ||
61 | */ | ||
62 | static inline u32 __seed(u32 x, u32 m) | ||
63 | { | ||
64 | return (x < m) ? x + m : x; | ||
65 | } | ||
66 | 62 | ||
67 | /** | 63 | /** |
68 | * random32 - pseudo random number generator | 64 | * random32 - pseudo random number generator |
@@ -75,7 +71,7 @@ u32 random32(void) | |||
75 | { | 71 | { |
76 | unsigned long r; | 72 | unsigned long r; |
77 | struct rnd_state *state = &get_cpu_var(net_rand_state); | 73 | struct rnd_state *state = &get_cpu_var(net_rand_state); |
78 | r = __random32(state); | 74 | r = prandom32(state); |
79 | put_cpu_var(state); | 75 | put_cpu_var(state); |
80 | return r; | 76 | return r; |
81 | } | 77 | } |
@@ -118,12 +114,12 @@ static int __init random32_init(void) | |||
118 | state->s3 = __seed(LCG(state->s2), 15); | 114 | state->s3 = __seed(LCG(state->s2), 15); |
119 | 115 | ||
120 | /* "warm it up" */ | 116 | /* "warm it up" */ |
121 | __random32(state); | 117 | prandom32(state); |
122 | __random32(state); | 118 | prandom32(state); |
123 | __random32(state); | 119 | prandom32(state); |
124 | __random32(state); | 120 | prandom32(state); |
125 | __random32(state); | 121 | prandom32(state); |
126 | __random32(state); | 122 | prandom32(state); |
127 | } | 123 | } |
128 | return 0; | 124 | return 0; |
129 | } | 125 | } |
@@ -147,7 +143,7 @@ static int __init random32_reseed(void) | |||
147 | state->s3 = __seed(seeds[2], 15); | 143 | state->s3 = __seed(seeds[2], 15); |
148 | 144 | ||
149 | /* mix it in */ | 145 | /* mix it in */ |
150 | __random32(state); | 146 | prandom32(state); |
151 | } | 147 | } |
152 | return 0; | 148 | return 0; |
153 | } | 149 | } |
diff --git a/lib/swiotlb.c b/lib/swiotlb.c index 5fddf720da73..a009055140ec 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c | |||
@@ -757,37 +757,6 @@ swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, | |||
757 | EXPORT_SYMBOL(swiotlb_sync_single_for_device); | 757 | EXPORT_SYMBOL(swiotlb_sync_single_for_device); |
758 | 758 | ||
759 | /* | 759 | /* |
760 | * Same as above, but for a sub-range of the mapping. | ||
761 | */ | ||
762 | static void | ||
763 | swiotlb_sync_single_range(struct device *hwdev, dma_addr_t dev_addr, | ||
764 | unsigned long offset, size_t size, | ||
765 | int dir, int target) | ||
766 | { | ||
767 | swiotlb_sync_single(hwdev, dev_addr + offset, size, dir, target); | ||
768 | } | ||
769 | |||
770 | void | ||
771 | swiotlb_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dev_addr, | ||
772 | unsigned long offset, size_t size, | ||
773 | enum dma_data_direction dir) | ||
774 | { | ||
775 | swiotlb_sync_single_range(hwdev, dev_addr, offset, size, dir, | ||
776 | SYNC_FOR_CPU); | ||
777 | } | ||
778 | EXPORT_SYMBOL_GPL(swiotlb_sync_single_range_for_cpu); | ||
779 | |||
780 | void | ||
781 | swiotlb_sync_single_range_for_device(struct device *hwdev, dma_addr_t dev_addr, | ||
782 | unsigned long offset, size_t size, | ||
783 | enum dma_data_direction dir) | ||
784 | { | ||
785 | swiotlb_sync_single_range(hwdev, dev_addr, offset, size, dir, | ||
786 | SYNC_FOR_DEVICE); | ||
787 | } | ||
788 | EXPORT_SYMBOL_GPL(swiotlb_sync_single_range_for_device); | ||
789 | |||
790 | /* | ||
791 | * Map a set of buffers described by scatterlist in streaming mode for DMA. | 760 | * Map a set of buffers described by scatterlist in streaming mode for DMA. |
792 | * This is the scatter-gather version of the above swiotlb_map_page | 761 | * This is the scatter-gather version of the above swiotlb_map_page |
793 | * interface. Here the scatter gather list elements are each tagged with the | 762 | * interface. Here the scatter gather list elements are each tagged with the |
diff --git a/lib/uuid.c b/lib/uuid.c new file mode 100644 index 000000000000..8fadd7cef46c --- /dev/null +++ b/lib/uuid.c | |||
@@ -0,0 +1,53 @@ | |||
1 | /* | ||
2 | * Unified UUID/GUID definition | ||
3 | * | ||
4 | * Copyright (C) 2009, Intel Corp. | ||
5 | * Huang Ying <ying.huang@intel.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License version | ||
9 | * 2 as published by the Free Software Foundation; | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | */ | ||
20 | |||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/uuid.h> | ||
24 | #include <linux/random.h> | ||
25 | |||
26 | static void __uuid_gen_common(__u8 b[16]) | ||
27 | { | ||
28 | int i; | ||
29 | u32 r; | ||
30 | |||
31 | for (i = 0; i < 4; i++) { | ||
32 | r = random32(); | ||
33 | memcpy(b + i * 4, &r, 4); | ||
34 | } | ||
35 | /* reversion 0b10 */ | ||
36 | b[8] = (b[8] & 0x3F) | 0x80; | ||
37 | } | ||
38 | |||
39 | void uuid_le_gen(uuid_le *lu) | ||
40 | { | ||
41 | __uuid_gen_common(lu->b); | ||
42 | /* version 4 : random generation */ | ||
43 | lu->b[7] = (lu->b[7] & 0x0F) | 0x40; | ||
44 | } | ||
45 | EXPORT_SYMBOL_GPL(uuid_le_gen); | ||
46 | |||
47 | void uuid_be_gen(uuid_be *bu) | ||
48 | { | ||
49 | __uuid_gen_common(bu->b); | ||
50 | /* version 4 : random generation */ | ||
51 | bu->b[6] = (bu->b[6] & 0x0F) | 0x40; | ||
52 | } | ||
53 | EXPORT_SYMBOL_GPL(uuid_be_gen); | ||
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 46d34b0b74a8..b8a2f549ab0e 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -267,7 +267,8 @@ int strict_strtoll(const char *cp, unsigned int base, long long *res) | |||
267 | } | 267 | } |
268 | EXPORT_SYMBOL(strict_strtoll); | 268 | EXPORT_SYMBOL(strict_strtoll); |
269 | 269 | ||
270 | static int skip_atoi(const char **s) | 270 | static noinline_for_stack |
271 | int skip_atoi(const char **s) | ||
271 | { | 272 | { |
272 | int i = 0; | 273 | int i = 0; |
273 | 274 | ||
@@ -287,7 +288,8 @@ static int skip_atoi(const char **s) | |||
287 | /* Formats correctly any integer in [0,99999]. | 288 | /* Formats correctly any integer in [0,99999]. |
288 | * Outputs from one to five digits depending on input. | 289 | * Outputs from one to five digits depending on input. |
289 | * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ | 290 | * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ |
290 | static char *put_dec_trunc(char *buf, unsigned q) | 291 | static noinline_for_stack |
292 | char *put_dec_trunc(char *buf, unsigned q) | ||
291 | { | 293 | { |
292 | unsigned d3, d2, d1, d0; | 294 | unsigned d3, d2, d1, d0; |
293 | d1 = (q>>4) & 0xf; | 295 | d1 = (q>>4) & 0xf; |
@@ -324,7 +326,8 @@ static char *put_dec_trunc(char *buf, unsigned q) | |||
324 | return buf; | 326 | return buf; |
325 | } | 327 | } |
326 | /* Same with if's removed. Always emits five digits */ | 328 | /* Same with if's removed. Always emits five digits */ |
327 | static char *put_dec_full(char *buf, unsigned q) | 329 | static noinline_for_stack |
330 | char *put_dec_full(char *buf, unsigned q) | ||
328 | { | 331 | { |
329 | /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ | 332 | /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ |
330 | /* but anyway, gcc produces better code with full-sized ints */ | 333 | /* but anyway, gcc produces better code with full-sized ints */ |
@@ -366,7 +369,8 @@ static char *put_dec_full(char *buf, unsigned q) | |||
366 | return buf; | 369 | return buf; |
367 | } | 370 | } |
368 | /* No inlining helps gcc to use registers better */ | 371 | /* No inlining helps gcc to use registers better */ |
369 | static noinline char *put_dec(char *buf, unsigned long long num) | 372 | static noinline_for_stack |
373 | char *put_dec(char *buf, unsigned long long num) | ||
370 | { | 374 | { |
371 | while (1) { | 375 | while (1) { |
372 | unsigned rem; | 376 | unsigned rem; |
@@ -417,8 +421,9 @@ struct printf_spec { | |||
417 | s16 precision; /* # of digits/chars */ | 421 | s16 precision; /* # of digits/chars */ |
418 | }; | 422 | }; |
419 | 423 | ||
420 | static char *number(char *buf, char *end, unsigned long long num, | 424 | static noinline_for_stack |
421 | struct printf_spec spec) | 425 | char *number(char *buf, char *end, unsigned long long num, |
426 | struct printf_spec spec) | ||
422 | { | 427 | { |
423 | /* we are called with base 8, 10 or 16, only, thus don't need "G..." */ | 428 | /* we are called with base 8, 10 or 16, only, thus don't need "G..." */ |
424 | static const char digits[16] = "0123456789ABCDEF"; /* "GHIJKLMNOPQRSTUVWXYZ"; */ | 429 | static const char digits[16] = "0123456789ABCDEF"; /* "GHIJKLMNOPQRSTUVWXYZ"; */ |
@@ -537,7 +542,8 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
537 | return buf; | 542 | return buf; |
538 | } | 543 | } |
539 | 544 | ||
540 | static char *string(char *buf, char *end, const char *s, struct printf_spec spec) | 545 | static noinline_for_stack |
546 | char *string(char *buf, char *end, const char *s, struct printf_spec spec) | ||
541 | { | 547 | { |
542 | int len, i; | 548 | int len, i; |
543 | 549 | ||
@@ -567,8 +573,9 @@ static char *string(char *buf, char *end, const char *s, struct printf_spec spec | |||
567 | return buf; | 573 | return buf; |
568 | } | 574 | } |
569 | 575 | ||
570 | static char *symbol_string(char *buf, char *end, void *ptr, | 576 | static noinline_for_stack |
571 | struct printf_spec spec, char ext) | 577 | char *symbol_string(char *buf, char *end, void *ptr, |
578 | struct printf_spec spec, char ext) | ||
572 | { | 579 | { |
573 | unsigned long value = (unsigned long) ptr; | 580 | unsigned long value = (unsigned long) ptr; |
574 | #ifdef CONFIG_KALLSYMS | 581 | #ifdef CONFIG_KALLSYMS |
@@ -588,8 +595,9 @@ static char *symbol_string(char *buf, char *end, void *ptr, | |||
588 | #endif | 595 | #endif |
589 | } | 596 | } |
590 | 597 | ||
591 | static char *resource_string(char *buf, char *end, struct resource *res, | 598 | static noinline_for_stack |
592 | struct printf_spec spec, const char *fmt) | 599 | char *resource_string(char *buf, char *end, struct resource *res, |
600 | struct printf_spec spec, const char *fmt) | ||
593 | { | 601 | { |
594 | #ifndef IO_RSRC_PRINTK_SIZE | 602 | #ifndef IO_RSRC_PRINTK_SIZE |
595 | #define IO_RSRC_PRINTK_SIZE 6 | 603 | #define IO_RSRC_PRINTK_SIZE 6 |
@@ -690,8 +698,9 @@ static char *resource_string(char *buf, char *end, struct resource *res, | |||
690 | return string(buf, end, sym, spec); | 698 | return string(buf, end, sym, spec); |
691 | } | 699 | } |
692 | 700 | ||
693 | static char *mac_address_string(char *buf, char *end, u8 *addr, | 701 | static noinline_for_stack |
694 | struct printf_spec spec, const char *fmt) | 702 | char *mac_address_string(char *buf, char *end, u8 *addr, |
703 | struct printf_spec spec, const char *fmt) | ||
695 | { | 704 | { |
696 | char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")]; | 705 | char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")]; |
697 | char *p = mac_addr; | 706 | char *p = mac_addr; |
@@ -714,7 +723,8 @@ static char *mac_address_string(char *buf, char *end, u8 *addr, | |||
714 | return string(buf, end, mac_addr, spec); | 723 | return string(buf, end, mac_addr, spec); |
715 | } | 724 | } |
716 | 725 | ||
717 | static char *ip4_string(char *p, const u8 *addr, const char *fmt) | 726 | static noinline_for_stack |
727 | char *ip4_string(char *p, const u8 *addr, const char *fmt) | ||
718 | { | 728 | { |
719 | int i; | 729 | int i; |
720 | bool leading_zeros = (fmt[0] == 'i'); | 730 | bool leading_zeros = (fmt[0] == 'i'); |
@@ -763,7 +773,8 @@ static char *ip4_string(char *p, const u8 *addr, const char *fmt) | |||
763 | return p; | 773 | return p; |
764 | } | 774 | } |
765 | 775 | ||
766 | static char *ip6_compressed_string(char *p, const char *addr) | 776 | static noinline_for_stack |
777 | char *ip6_compressed_string(char *p, const char *addr) | ||
767 | { | 778 | { |
768 | int i, j, range; | 779 | int i, j, range; |
769 | unsigned char zerolength[8]; | 780 | unsigned char zerolength[8]; |
@@ -843,7 +854,8 @@ static char *ip6_compressed_string(char *p, const char *addr) | |||
843 | return p; | 854 | return p; |
844 | } | 855 | } |
845 | 856 | ||
846 | static char *ip6_string(char *p, const char *addr, const char *fmt) | 857 | static noinline_for_stack |
858 | char *ip6_string(char *p, const char *addr, const char *fmt) | ||
847 | { | 859 | { |
848 | int i; | 860 | int i; |
849 | 861 | ||
@@ -858,8 +870,9 @@ static char *ip6_string(char *p, const char *addr, const char *fmt) | |||
858 | return p; | 870 | return p; |
859 | } | 871 | } |
860 | 872 | ||
861 | static char *ip6_addr_string(char *buf, char *end, const u8 *addr, | 873 | static noinline_for_stack |
862 | struct printf_spec spec, const char *fmt) | 874 | char *ip6_addr_string(char *buf, char *end, const u8 *addr, |
875 | struct printf_spec spec, const char *fmt) | ||
863 | { | 876 | { |
864 | char ip6_addr[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")]; | 877 | char ip6_addr[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")]; |
865 | 878 | ||
@@ -871,8 +884,9 @@ static char *ip6_addr_string(char *buf, char *end, const u8 *addr, | |||
871 | return string(buf, end, ip6_addr, spec); | 884 | return string(buf, end, ip6_addr, spec); |
872 | } | 885 | } |
873 | 886 | ||
874 | static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | 887 | static noinline_for_stack |
875 | struct printf_spec spec, const char *fmt) | 888 | char *ip4_addr_string(char *buf, char *end, const u8 *addr, |
889 | struct printf_spec spec, const char *fmt) | ||
876 | { | 890 | { |
877 | char ip4_addr[sizeof("255.255.255.255")]; | 891 | char ip4_addr[sizeof("255.255.255.255")]; |
878 | 892 | ||
@@ -881,8 +895,9 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | |||
881 | return string(buf, end, ip4_addr, spec); | 895 | return string(buf, end, ip4_addr, spec); |
882 | } | 896 | } |
883 | 897 | ||
884 | static char *uuid_string(char *buf, char *end, const u8 *addr, | 898 | static noinline_for_stack |
885 | struct printf_spec spec, const char *fmt) | 899 | char *uuid_string(char *buf, char *end, const u8 *addr, |
900 | struct printf_spec spec, const char *fmt) | ||
886 | { | 901 | { |
887 | char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]; | 902 | char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]; |
888 | char *p = uuid; | 903 | char *p = uuid; |
@@ -970,8 +985,9 @@ static char *uuid_string(char *buf, char *end, const u8 *addr, | |||
970 | * function pointers are really function descriptors, which contain a | 985 | * function pointers are really function descriptors, which contain a |
971 | * pointer to the real address. | 986 | * pointer to the real address. |
972 | */ | 987 | */ |
973 | static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | 988 | static noinline_for_stack |
974 | struct printf_spec spec) | 989 | char *pointer(const char *fmt, char *buf, char *end, void *ptr, |
990 | struct printf_spec spec) | ||
975 | { | 991 | { |
976 | if (!ptr) | 992 | if (!ptr) |
977 | return string(buf, end, "(null)", spec); | 993 | return string(buf, end, "(null)", spec); |
@@ -1040,7 +1056,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
1040 | * @precision: precision of a number | 1056 | * @precision: precision of a number |
1041 | * @qualifier: qualifier of a number (long, size_t, ...) | 1057 | * @qualifier: qualifier of a number (long, size_t, ...) |
1042 | */ | 1058 | */ |
1043 | static int format_decode(const char *fmt, struct printf_spec *spec) | 1059 | static noinline_for_stack |
1060 | int format_decode(const char *fmt, struct printf_spec *spec) | ||
1044 | { | 1061 | { |
1045 | const char *start = fmt; | 1062 | const char *start = fmt; |
1046 | 1063 | ||
@@ -1980,7 +1997,7 @@ int vsscanf(const char *buf, const char *fmt, va_list args) | |||
1980 | { | 1997 | { |
1981 | char *s = (char *)va_arg(args, char *); | 1998 | char *s = (char *)va_arg(args, char *); |
1982 | if (field_width == -1) | 1999 | if (field_width == -1) |
1983 | field_width = SHORT_MAX; | 2000 | field_width = SHRT_MAX; |
1984 | /* first, skip leading white space in buffer */ | 2001 | /* first, skip leading white space in buffer */ |
1985 | str = skip_spaces(str); | 2002 | str = skip_spaces(str); |
1986 | 2003 | ||