aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Kconfig10
-rw-r--r--lib/Makefile4
-rw-r--r--lib/btree.c1
-rw-r--r--lib/cordic.c2
-rw-r--r--lib/crc32.c21
-rw-r--r--lib/debugobjects.c54
-rw-r--r--lib/decompress_bunzip2.c5
-rw-r--r--lib/decompress_unlzma.c2
-rw-r--r--lib/devres.c55
-rw-r--r--lib/dma-debug.c2
-rw-r--r--lib/dynamic_queue_limits.c133
-rw-r--r--lib/fault-inject.c8
-rw-r--r--lib/kobject.c37
-rw-r--r--lib/kobject_uevent.c3
-rw-r--r--lib/kref.c97
-rw-r--r--lib/reciprocal_div.c2
-rw-r--r--lib/swiotlb.c5
-rw-r--r--lib/vsprintf.c19
18 files changed, 293 insertions, 167 deletions
diff --git a/lib/Kconfig b/lib/Kconfig
index 36884b409e37..7f6b8bca8c25 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -251,6 +251,9 @@ config CPU_RMAP
251 bool 251 bool
252 depends on SMP 252 depends on SMP
253 253
254config DQL
255 bool
256
254# 257#
255# Netlink attribute parsing support is select'ed if needed 258# Netlink attribute parsing support is select'ed if needed
256# 259#
@@ -277,10 +280,9 @@ config AVERAGE
277 If unsure, say N. 280 If unsure, say N.
278 281
279config CORDIC 282config CORDIC
280 tristate "Cordic function" 283 tristate "CORDIC algorithm"
281 help 284 help
282 The option provides arithmetic function using cordic algorithm 285 This option provides an implementation of the CORDIC algorithm;
283 so its calculations are in fixed point. Modules can select this 286 calculations are in fixed point. Module will be called cordic.
284 when they require this function. Module will be called cordic.
285 287
286endmenu 288endmenu
diff --git a/lib/Makefile b/lib/Makefile
index 609b2adc604c..884ed376164d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -17,7 +17,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
17lib-$(CONFIG_MMU) += ioremap.o 17lib-$(CONFIG_MMU) += ioremap.o
18lib-$(CONFIG_SMP) += cpumask.o 18lib-$(CONFIG_SMP) += cpumask.o
19 19
20lib-y += kobject.o kref.o klist.o 20lib-y += kobject.o klist.o
21 21
22obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ 22obj-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 \
@@ -116,6 +116,8 @@ obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o
116 116
117obj-$(CONFIG_CORDIC) += cordic.o 117obj-$(CONFIG_CORDIC) += cordic.o
118 118
119obj-$(CONFIG_DQL) += dynamic_queue_limits.o
120
119hostprogs-y := gen_crc32table 121hostprogs-y := gen_crc32table
120clean-files := crc32table.h 122clean-files := crc32table.h
121 123
diff --git a/lib/btree.c b/lib/btree.c
index 2a34392bcecc..e5ec1e9c1aa5 100644
--- a/lib/btree.c
+++ b/lib/btree.c
@@ -357,6 +357,7 @@ miss:
357 } 357 }
358 return NULL; 358 return NULL;
359} 359}
360EXPORT_SYMBOL_GPL(btree_get_prev);
360 361
361static int getpos(struct btree_geo *geo, unsigned long *node, 362static int getpos(struct btree_geo *geo, unsigned long *node,
362 unsigned long *key) 363 unsigned long *key)
diff --git a/lib/cordic.c b/lib/cordic.c
index aa27a88d7e04..6cf477839ebd 100644
--- a/lib/cordic.c
+++ b/lib/cordic.c
@@ -96,6 +96,6 @@ struct cordic_iq cordic_calc_iq(s32 theta)
96} 96}
97EXPORT_SYMBOL(cordic_calc_iq); 97EXPORT_SYMBOL(cordic_calc_iq);
98 98
99MODULE_DESCRIPTION("Cordic functions"); 99MODULE_DESCRIPTION("CORDIC algorithm");
100MODULE_AUTHOR("Broadcom Corporation"); 100MODULE_AUTHOR("Broadcom Corporation");
101MODULE_LICENSE("Dual BSD/GPL"); 101MODULE_LICENSE("Dual BSD/GPL");
diff --git a/lib/crc32.c b/lib/crc32.c
index a6e633a48cea..4b35d2b4437c 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -51,20 +51,21 @@ static inline u32
51crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256]) 51crc32_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[0][(crc ^ (x)) & 255] ^ (crc >> 8) 54# define DO_CRC(x) crc = t0[(crc ^ (x)) & 255] ^ (crc >> 8)
55# define DO_CRC4 crc = tab[3][(crc) & 255] ^ \ 55# define DO_CRC4 crc = t3[(crc) & 255] ^ \
56 tab[2][(crc >> 8) & 255] ^ \ 56 t2[(crc >> 8) & 255] ^ \
57 tab[1][(crc >> 16) & 255] ^ \ 57 t1[(crc >> 16) & 255] ^ \
58 tab[0][(crc >> 24) & 255] 58 t0[(crc >> 24) & 255]
59# else 59# else
60# define DO_CRC(x) crc = tab[0][((crc >> 24) ^ (x)) & 255] ^ (crc << 8) 60# define DO_CRC(x) crc = t0[((crc >> 24) ^ (x)) & 255] ^ (crc << 8)
61# define DO_CRC4 crc = tab[0][(crc) & 255] ^ \ 61# define DO_CRC4 crc = t0[(crc) & 255] ^ \
62 tab[1][(crc >> 8) & 255] ^ \ 62 t1[(crc >> 8) & 255] ^ \
63 tab[2][(crc >> 16) & 255] ^ \ 63 t2[(crc >> 16) & 255] ^ \
64 tab[3][(crc >> 24) & 255] 64 t3[(crc >> 24) & 255]
65# endif 65# endif
66 const u32 *b; 66 const u32 *b;
67 size_t rem_len; 67 size_t rem_len;
68 const u32 *t0=tab[0], *t1=tab[1], *t2=tab[2], *t3=tab[3];
68 69
69 /* Align it */ 70 /* Align it */
70 if (unlikely((long)buf & 3 && len)) { 71 if (unlikely((long)buf & 3 && len)) {
diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index a78b7c6e042c..77cb245f8e7b 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -268,12 +268,16 @@ static void debug_print_object(struct debug_obj *obj, char *msg)
268 * Try to repair the damage, so we have a better chance to get useful 268 * Try to repair the damage, so we have a better chance to get useful
269 * debug output. 269 * debug output.
270 */ 270 */
271static void 271static int
272debug_object_fixup(int (*fixup)(void *addr, enum debug_obj_state state), 272debug_object_fixup(int (*fixup)(void *addr, enum debug_obj_state state),
273 void * addr, enum debug_obj_state state) 273 void * addr, enum debug_obj_state state)
274{ 274{
275 int fixed = 0;
276
275 if (fixup) 277 if (fixup)
276 debug_objects_fixups += fixup(addr, state); 278 fixed = fixup(addr, state);
279 debug_objects_fixups += fixed;
280 return fixed;
277} 281}
278 282
279static void debug_object_is_on_stack(void *addr, int onstack) 283static void debug_object_is_on_stack(void *addr, int onstack)
@@ -386,6 +390,9 @@ void debug_object_activate(void *addr, struct debug_obj_descr *descr)
386 struct debug_bucket *db; 390 struct debug_bucket *db;
387 struct debug_obj *obj; 391 struct debug_obj *obj;
388 unsigned long flags; 392 unsigned long flags;
393 struct debug_obj o = { .object = addr,
394 .state = ODEBUG_STATE_NOTAVAILABLE,
395 .descr = descr };
389 396
390 if (!debug_objects_enabled) 397 if (!debug_objects_enabled)
391 return; 398 return;
@@ -425,8 +432,9 @@ void debug_object_activate(void *addr, struct debug_obj_descr *descr)
425 * let the type specific code decide whether this is 432 * let the type specific code decide whether this is
426 * true or not. 433 * true or not.
427 */ 434 */
428 debug_object_fixup(descr->fixup_activate, addr, 435 if (debug_object_fixup(descr->fixup_activate, addr,
429 ODEBUG_STATE_NOTAVAILABLE); 436 ODEBUG_STATE_NOTAVAILABLE))
437 debug_print_object(&o, "activate");
430} 438}
431 439
432/** 440/**
@@ -563,6 +571,44 @@ out_unlock:
563} 571}
564 572
565/** 573/**
574 * debug_object_assert_init - debug checks when object should be init-ed
575 * @addr: address of the object
576 * @descr: pointer to an object specific debug description structure
577 */
578void debug_object_assert_init(void *addr, struct debug_obj_descr *descr)
579{
580 struct debug_bucket *db;
581 struct debug_obj *obj;
582 unsigned long flags;
583
584 if (!debug_objects_enabled)
585 return;
586
587 db = get_bucket((unsigned long) addr);
588
589 raw_spin_lock_irqsave(&db->lock, flags);
590
591 obj = lookup_object(addr, db);
592 if (!obj) {
593 struct debug_obj o = { .object = addr,
594 .state = ODEBUG_STATE_NOTAVAILABLE,
595 .descr = descr };
596
597 raw_spin_unlock_irqrestore(&db->lock, flags);
598 /*
599 * Maybe the object is static. Let the type specific
600 * code decide what to do.
601 */
602 if (debug_object_fixup(descr->fixup_assert_init, addr,
603 ODEBUG_STATE_NOTAVAILABLE))
604 debug_print_object(&o, "assert_init");
605 return;
606 }
607
608 raw_spin_unlock_irqrestore(&db->lock, flags);
609}
610
611/**
566 * debug_object_active_state - debug checks object usage state machine 612 * debug_object_active_state - debug checks object usage state machine
567 * @addr: address of the object 613 * @addr: address of the object
568 * @descr: pointer to an object specific debug description structure 614 * @descr: pointer to an object specific debug description structure
diff --git a/lib/decompress_bunzip2.c b/lib/decompress_bunzip2.c
index a7b80c1d6a0d..31c5f7675fbf 100644
--- a/lib/decompress_bunzip2.c
+++ b/lib/decompress_bunzip2.c
@@ -1,4 +1,3 @@
1/* vi: set sw = 4 ts = 4: */
2/* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net). 1/* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net).
3 2
4 Based on bzip2 decompression code by Julian R Seward (jseward@acm.org), 3 Based on bzip2 decompression code by Julian R Seward (jseward@acm.org),
@@ -691,7 +690,7 @@ STATIC int INIT bunzip2(unsigned char *buf, int len,
691 outbuf = malloc(BZIP2_IOBUF_SIZE); 690 outbuf = malloc(BZIP2_IOBUF_SIZE);
692 691
693 if (!outbuf) { 692 if (!outbuf) {
694 error("Could not allocate output bufer"); 693 error("Could not allocate output buffer");
695 return RETVAL_OUT_OF_MEMORY; 694 return RETVAL_OUT_OF_MEMORY;
696 } 695 }
697 if (buf) 696 if (buf)
@@ -699,7 +698,7 @@ STATIC int INIT bunzip2(unsigned char *buf, int len,
699 else 698 else
700 inbuf = malloc(BZIP2_IOBUF_SIZE); 699 inbuf = malloc(BZIP2_IOBUF_SIZE);
701 if (!inbuf) { 700 if (!inbuf) {
702 error("Could not allocate input bufer"); 701 error("Could not allocate input buffer");
703 i = RETVAL_OUT_OF_MEMORY; 702 i = RETVAL_OUT_OF_MEMORY;
704 goto exit_0; 703 goto exit_0;
705 } 704 }
diff --git a/lib/decompress_unlzma.c b/lib/decompress_unlzma.c
index 476c65af9709..32adb73a9038 100644
--- a/lib/decompress_unlzma.c
+++ b/lib/decompress_unlzma.c
@@ -562,7 +562,7 @@ STATIC inline int INIT unlzma(unsigned char *buf, int in_len,
562 else 562 else
563 inbuf = malloc(LZMA_IOBUF_SIZE); 563 inbuf = malloc(LZMA_IOBUF_SIZE);
564 if (!inbuf) { 564 if (!inbuf) {
565 error("Could not allocate input bufer"); 565 error("Could not allocate input buffer");
566 goto exit_0; 566 goto exit_0;
567 } 567 }
568 568
diff --git a/lib/devres.c b/lib/devres.c
index 7c0e953a7486..4fbc09e6e9e6 100644
--- a/lib/devres.c
+++ b/lib/devres.c
@@ -85,6 +85,57 @@ void devm_iounmap(struct device *dev, void __iomem *addr)
85} 85}
86EXPORT_SYMBOL(devm_iounmap); 86EXPORT_SYMBOL(devm_iounmap);
87 87
88/**
89 * devm_request_and_ioremap() - Check, request region, and ioremap resource
90 * @dev: Generic device to handle the resource for
91 * @res: resource to be handled
92 *
93 * Takes all necessary steps to ioremap a mem resource. Uses managed device, so
94 * everything is undone on driver detach. Checks arguments, so you can feed
95 * it the result from e.g. platform_get_resource() directly. Returns the
96 * remapped pointer or NULL on error. Usage example:
97 *
98 * res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
99 * base = devm_request_and_ioremap(&pdev->dev, res);
100 * if (!base)
101 * return -EADDRNOTAVAIL;
102 */
103void __iomem *devm_request_and_ioremap(struct device *dev,
104 struct resource *res)
105{
106 resource_size_t size;
107 const char *name;
108 void __iomem *dest_ptr;
109
110 BUG_ON(!dev);
111
112 if (!res || resource_type(res) != IORESOURCE_MEM) {
113 dev_err(dev, "invalid resource\n");
114 return NULL;
115 }
116
117 size = resource_size(res);
118 name = res->name ?: dev_name(dev);
119
120 if (!devm_request_mem_region(dev, res->start, size, name)) {
121 dev_err(dev, "can't request region for resource %pR\n", res);
122 return NULL;
123 }
124
125 if (res->flags & IORESOURCE_CACHEABLE)
126 dest_ptr = devm_ioremap(dev, res->start, size);
127 else
128 dest_ptr = devm_ioremap_nocache(dev, res->start, size);
129
130 if (!dest_ptr) {
131 dev_err(dev, "ioremap failed for resource %pR\n", res);
132 devm_release_mem_region(dev, res->start, size);
133 }
134
135 return dest_ptr;
136}
137EXPORT_SYMBOL(devm_request_and_ioremap);
138
88#ifdef CONFIG_HAS_IOPORT 139#ifdef CONFIG_HAS_IOPORT
89/* 140/*
90 * Generic iomap devres 141 * Generic iomap devres
@@ -348,5 +399,5 @@ void pcim_iounmap_regions(struct pci_dev *pdev, u16 mask)
348 } 399 }
349} 400}
350EXPORT_SYMBOL(pcim_iounmap_regions); 401EXPORT_SYMBOL(pcim_iounmap_regions);
351#endif 402#endif /* CONFIG_PCI */
352#endif 403#endif /* CONFIG_HAS_IOPORT */
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index 74c6c7fce749..fea790a2b176 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -245,7 +245,7 @@ static void put_hash_bucket(struct hash_bucket *bucket,
245 245
246static bool exact_match(struct dma_debug_entry *a, struct dma_debug_entry *b) 246static bool exact_match(struct dma_debug_entry *a, struct dma_debug_entry *b)
247{ 247{
248 return ((a->dev_addr == a->dev_addr) && 248 return ((a->dev_addr == b->dev_addr) &&
249 (a->dev == b->dev)) ? true : false; 249 (a->dev == b->dev)) ? true : false;
250} 250}
251 251
diff --git a/lib/dynamic_queue_limits.c b/lib/dynamic_queue_limits.c
new file mode 100644
index 000000000000..3d1bdcdd7db4
--- /dev/null
+++ b/lib/dynamic_queue_limits.c
@@ -0,0 +1,133 @@
1/*
2 * Dynamic byte queue limits. See include/linux/dynamic_queue_limits.h
3 *
4 * Copyright (c) 2011, Tom Herbert <therbert@google.com>
5 */
6#include <linux/module.h>
7#include <linux/types.h>
8#include <linux/ctype.h>
9#include <linux/kernel.h>
10#include <linux/dynamic_queue_limits.h>
11
12#define POSDIFF(A, B) ((A) > (B) ? (A) - (B) : 0)
13
14/* Records completed count and recalculates the queue limit */
15void dql_completed(struct dql *dql, unsigned int count)
16{
17 unsigned int inprogress, prev_inprogress, limit;
18 unsigned int ovlimit, all_prev_completed, completed;
19
20 /* Can't complete more than what's in queue */
21 BUG_ON(count > dql->num_queued - dql->num_completed);
22
23 completed = dql->num_completed + count;
24 limit = dql->limit;
25 ovlimit = POSDIFF(dql->num_queued - dql->num_completed, limit);
26 inprogress = dql->num_queued - completed;
27 prev_inprogress = dql->prev_num_queued - dql->num_completed;
28 all_prev_completed = POSDIFF(completed, dql->prev_num_queued);
29
30 if ((ovlimit && !inprogress) ||
31 (dql->prev_ovlimit && all_prev_completed)) {
32 /*
33 * Queue considered starved if:
34 * - The queue was over-limit in the last interval,
35 * and there is no more data in the queue.
36 * OR
37 * - The queue was over-limit in the previous interval and
38 * when enqueuing it was possible that all queued data
39 * had been consumed. This covers the case when queue
40 * may have becomes starved between completion processing
41 * running and next time enqueue was scheduled.
42 *
43 * When queue is starved increase the limit by the amount
44 * of bytes both sent and completed in the last interval,
45 * plus any previous over-limit.
46 */
47 limit += POSDIFF(completed, dql->prev_num_queued) +
48 dql->prev_ovlimit;
49 dql->slack_start_time = jiffies;
50 dql->lowest_slack = UINT_MAX;
51 } else if (inprogress && prev_inprogress && !all_prev_completed) {
52 /*
53 * Queue was not starved, check if the limit can be decreased.
54 * A decrease is only considered if the queue has been busy in
55 * the whole interval (the check above).
56 *
57 * If there is slack, the amount of execess data queued above
58 * the the amount needed to prevent starvation, the queue limit
59 * can be decreased. To avoid hysteresis we consider the
60 * minimum amount of slack found over several iterations of the
61 * completion routine.
62 */
63 unsigned int slack, slack_last_objs;
64
65 /*
66 * Slack is the maximum of
67 * - The queue limit plus previous over-limit minus twice
68 * the number of objects completed. Note that two times
69 * number of completed bytes is a basis for an upper bound
70 * of the limit.
71 * - Portion of objects in the last queuing operation that
72 * was not part of non-zero previous over-limit. That is
73 * "round down" by non-overlimit portion of the last
74 * queueing operation.
75 */
76 slack = POSDIFF(limit + dql->prev_ovlimit,
77 2 * (completed - dql->num_completed));
78 slack_last_objs = dql->prev_ovlimit ?
79 POSDIFF(dql->prev_last_obj_cnt, dql->prev_ovlimit) : 0;
80
81 slack = max(slack, slack_last_objs);
82
83 if (slack < dql->lowest_slack)
84 dql->lowest_slack = slack;
85
86 if (time_after(jiffies,
87 dql->slack_start_time + dql->slack_hold_time)) {
88 limit = POSDIFF(limit, dql->lowest_slack);
89 dql->slack_start_time = jiffies;
90 dql->lowest_slack = UINT_MAX;
91 }
92 }
93
94 /* Enforce bounds on limit */
95 limit = clamp(limit, dql->min_limit, dql->max_limit);
96
97 if (limit != dql->limit) {
98 dql->limit = limit;
99 ovlimit = 0;
100 }
101
102 dql->adj_limit = limit + completed;
103 dql->prev_ovlimit = ovlimit;
104 dql->prev_last_obj_cnt = dql->last_obj_cnt;
105 dql->num_completed = completed;
106 dql->prev_num_queued = dql->num_queued;
107}
108EXPORT_SYMBOL(dql_completed);
109
110void dql_reset(struct dql *dql)
111{
112 /* Reset all dynamic values */
113 dql->limit = 0;
114 dql->num_queued = 0;
115 dql->num_completed = 0;
116 dql->last_obj_cnt = 0;
117 dql->prev_num_queued = 0;
118 dql->prev_last_obj_cnt = 0;
119 dql->prev_ovlimit = 0;
120 dql->lowest_slack = UINT_MAX;
121 dql->slack_start_time = jiffies;
122}
123EXPORT_SYMBOL(dql_reset);
124
125int dql_init(struct dql *dql, unsigned hold_time)
126{
127 dql->max_limit = DQL_MAX_LIMIT;
128 dql->min_limit = 0;
129 dql->slack_hold_time = hold_time;
130 dql_reset(dql);
131 return 0;
132}
133EXPORT_SYMBOL(dql_init);
diff --git a/lib/fault-inject.c b/lib/fault-inject.c
index 4f7554025e30..b4801f51b607 100644
--- a/lib/fault-inject.c
+++ b/lib/fault-inject.c
@@ -149,7 +149,7 @@ static int debugfs_ul_get(void *data, u64 *val)
149 149
150DEFINE_SIMPLE_ATTRIBUTE(fops_ul, debugfs_ul_get, debugfs_ul_set, "%llu\n"); 150DEFINE_SIMPLE_ATTRIBUTE(fops_ul, debugfs_ul_get, debugfs_ul_set, "%llu\n");
151 151
152static struct dentry *debugfs_create_ul(const char *name, mode_t mode, 152static struct dentry *debugfs_create_ul(const char *name, umode_t mode,
153 struct dentry *parent, unsigned long *value) 153 struct dentry *parent, unsigned long *value)
154{ 154{
155 return debugfs_create_file(name, mode, parent, value, &fops_ul); 155 return debugfs_create_file(name, mode, parent, value, &fops_ul);
@@ -169,7 +169,7 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_stacktrace_depth, debugfs_ul_get,
169 debugfs_stacktrace_depth_set, "%llu\n"); 169 debugfs_stacktrace_depth_set, "%llu\n");
170 170
171static struct dentry *debugfs_create_stacktrace_depth( 171static struct dentry *debugfs_create_stacktrace_depth(
172 const char *name, mode_t mode, 172 const char *name, umode_t mode,
173 struct dentry *parent, unsigned long *value) 173 struct dentry *parent, unsigned long *value)
174{ 174{
175 return debugfs_create_file(name, mode, parent, value, 175 return debugfs_create_file(name, mode, parent, value,
@@ -193,7 +193,7 @@ static int debugfs_atomic_t_get(void *data, u64 *val)
193DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get, 193DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get,
194 debugfs_atomic_t_set, "%lld\n"); 194 debugfs_atomic_t_set, "%lld\n");
195 195
196static struct dentry *debugfs_create_atomic_t(const char *name, mode_t mode, 196static struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
197 struct dentry *parent, atomic_t *value) 197 struct dentry *parent, atomic_t *value)
198{ 198{
199 return debugfs_create_file(name, mode, parent, value, &fops_atomic_t); 199 return debugfs_create_file(name, mode, parent, value, &fops_atomic_t);
@@ -202,7 +202,7 @@ static struct dentry *debugfs_create_atomic_t(const char *name, mode_t mode,
202struct dentry *fault_create_debugfs_attr(const char *name, 202struct dentry *fault_create_debugfs_attr(const char *name,
203 struct dentry *parent, struct fault_attr *attr) 203 struct dentry *parent, struct fault_attr *attr)
204{ 204{
205 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR; 205 umode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
206 struct dentry *dir; 206 struct dentry *dir;
207 207
208 dir = debugfs_create_dir(name, parent); 208 dir = debugfs_create_dir(name, parent);
diff --git a/lib/kobject.c b/lib/kobject.c
index 640bd98a4c8a..c33d7a18d635 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -746,43 +746,11 @@ void kset_unregister(struct kset *k)
746 */ 746 */
747struct kobject *kset_find_obj(struct kset *kset, const char *name) 747struct kobject *kset_find_obj(struct kset *kset, const char *name)
748{ 748{
749 return kset_find_obj_hinted(kset, name, NULL);
750}
751
752/**
753 * kset_find_obj_hinted - search for object in kset given a predecessor hint.
754 * @kset: kset we're looking in.
755 * @name: object's name.
756 * @hint: hint to possible object's predecessor.
757 *
758 * Check the hint's next object and if it is a match return it directly,
759 * otherwise, fall back to the behavior of kset_find_obj(). Either way
760 * a reference for the returned object is held and the reference on the
761 * hinted object is released.
762 */
763struct kobject *kset_find_obj_hinted(struct kset *kset, const char *name,
764 struct kobject *hint)
765{
766 struct kobject *k; 749 struct kobject *k;
767 struct kobject *ret = NULL; 750 struct kobject *ret = NULL;
768 751
769 spin_lock(&kset->list_lock); 752 spin_lock(&kset->list_lock);
770 753
771 if (!hint)
772 goto slow_search;
773
774 /* end of list detection */
775 if (hint->entry.next == kset->list.next)
776 goto slow_search;
777
778 k = container_of(hint->entry.next, struct kobject, entry);
779 if (!kobject_name(k) || strcmp(kobject_name(k), name))
780 goto slow_search;
781
782 ret = kobject_get(k);
783 goto unlock_exit;
784
785slow_search:
786 list_for_each_entry(k, &kset->list, entry) { 754 list_for_each_entry(k, &kset->list, entry) {
787 if (kobject_name(k) && !strcmp(kobject_name(k), name)) { 755 if (kobject_name(k) && !strcmp(kobject_name(k), name)) {
788 ret = kobject_get(k); 756 ret = kobject_get(k);
@@ -790,12 +758,7 @@ slow_search:
790 } 758 }
791 } 759 }
792 760
793unlock_exit:
794 spin_unlock(&kset->list_lock); 761 spin_unlock(&kset->list_lock);
795
796 if (hint)
797 kobject_put(hint);
798
799 return ret; 762 return ret;
800} 763}
801 764
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index ad72a03ce5e9..e66e9b632617 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -259,6 +259,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
259 struct sk_buff *skb; 259 struct sk_buff *skb;
260 size_t len; 260 size_t len;
261 261
262 if (!netlink_has_listeners(uevent_sock, 1))
263 continue;
264
262 /* allocate message with the maximum possible size */ 265 /* allocate message with the maximum possible size */
263 len = strlen(action_string) + strlen(devpath) + 2; 266 len = strlen(action_string) + strlen(devpath) + 2;
264 skb = alloc_skb(len + env->buflen, GFP_KERNEL); 267 skb = alloc_skb(len + env->buflen, GFP_KERNEL);
diff --git a/lib/kref.c b/lib/kref.c
deleted file mode 100644
index 3efb882b11db..000000000000
--- a/lib/kref.c
+++ /dev/null
@@ -1,97 +0,0 @@
1/*
2 * kref.c - library routines for handling generic reference counted objects
3 *
4 * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2004 IBM Corp.
6 *
7 * based on lib/kobject.c which was:
8 * Copyright (C) 2002-2003 Patrick Mochel <mochel@osdl.org>
9 *
10 * This file is released under the GPLv2.
11 *
12 */
13
14#include <linux/kref.h>
15#include <linux/module.h>
16#include <linux/slab.h>
17
18/**
19 * kref_init - initialize object.
20 * @kref: object in question.
21 */
22void kref_init(struct kref *kref)
23{
24 atomic_set(&kref->refcount, 1);
25 smp_mb();
26}
27
28/**
29 * kref_get - increment refcount for object.
30 * @kref: object.
31 */
32void kref_get(struct kref *kref)
33{
34 WARN_ON(!atomic_read(&kref->refcount));
35 atomic_inc(&kref->refcount);
36 smp_mb__after_atomic_inc();
37}
38
39/**
40 * kref_put - decrement refcount for object.
41 * @kref: object.
42 * @release: pointer to the function that will clean up the object when the
43 * last reference to the object is released.
44 * This pointer is required, and it is not acceptable to pass kfree
45 * in as this function.
46 *
47 * Decrement the refcount, and if 0, call release().
48 * Return 1 if the object was removed, otherwise return 0. Beware, if this
49 * function returns 0, you still can not count on the kref from remaining in
50 * memory. Only use the return value if you want to see if the kref is now
51 * gone, not present.
52 */
53int kref_put(struct kref *kref, void (*release)(struct kref *kref))
54{
55 WARN_ON(release == NULL);
56 WARN_ON(release == (void (*)(struct kref *))kfree);
57
58 if (atomic_dec_and_test(&kref->refcount)) {
59 release(kref);
60 return 1;
61 }
62 return 0;
63}
64
65
66/**
67 * kref_sub - subtract a number of refcounts for object.
68 * @kref: object.
69 * @count: Number of recounts to subtract.
70 * @release: pointer to the function that will clean up the object when the
71 * last reference to the object is released.
72 * This pointer is required, and it is not acceptable to pass kfree
73 * in as this function.
74 *
75 * Subtract @count from the refcount, and if 0, call release().
76 * Return 1 if the object was removed, otherwise return 0. Beware, if this
77 * function returns 0, you still can not count on the kref from remaining in
78 * memory. Only use the return value if you want to see if the kref is now
79 * gone, not present.
80 */
81int kref_sub(struct kref *kref, unsigned int count,
82 void (*release)(struct kref *kref))
83{
84 WARN_ON(release == NULL);
85 WARN_ON(release == (void (*)(struct kref *))kfree);
86
87 if (atomic_sub_and_test((int) count, &kref->refcount)) {
88 release(kref);
89 return 1;
90 }
91 return 0;
92}
93
94EXPORT_SYMBOL(kref_init);
95EXPORT_SYMBOL(kref_get);
96EXPORT_SYMBOL(kref_put);
97EXPORT_SYMBOL(kref_sub);
diff --git a/lib/reciprocal_div.c b/lib/reciprocal_div.c
index 6a3bd48fa2a0..75510e94f7d0 100644
--- a/lib/reciprocal_div.c
+++ b/lib/reciprocal_div.c
@@ -1,5 +1,6 @@
1#include <asm/div64.h> 1#include <asm/div64.h>
2#include <linux/reciprocal_div.h> 2#include <linux/reciprocal_div.h>
3#include <linux/export.h>
3 4
4u32 reciprocal_value(u32 k) 5u32 reciprocal_value(u32 k)
5{ 6{
@@ -7,3 +8,4 @@ u32 reciprocal_value(u32 k)
7 do_div(val, k); 8 do_div(val, k);
8 return (u32)val; 9 return (u32)val;
9} 10}
11EXPORT_SYMBOL(reciprocal_value);
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 99093b396145..058935ef3975 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -110,11 +110,11 @@ setup_io_tlb_npages(char *str)
110__setup("swiotlb=", setup_io_tlb_npages); 110__setup("swiotlb=", setup_io_tlb_npages);
111/* make io_tlb_overflow tunable too? */ 111/* make io_tlb_overflow tunable too? */
112 112
113unsigned long swioltb_nr_tbl(void) 113unsigned long swiotlb_nr_tbl(void)
114{ 114{
115 return io_tlb_nslabs; 115 return io_tlb_nslabs;
116} 116}
117 117EXPORT_SYMBOL_GPL(swiotlb_nr_tbl);
118/* Note that this doesn't work with highmem page */ 118/* Note that this doesn't work with highmem page */
119static dma_addr_t swiotlb_virt_to_bus(struct device *hwdev, 119static dma_addr_t swiotlb_virt_to_bus(struct device *hwdev,
120 volatile void *address) 120 volatile void *address)
@@ -321,6 +321,7 @@ void __init swiotlb_free(void)
321 free_bootmem_late(__pa(io_tlb_start), 321 free_bootmem_late(__pa(io_tlb_start),
322 PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT)); 322 PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
323 } 323 }
324 io_tlb_nslabs = 0;
324} 325}
325 326
326static int is_swiotlb_buffer(phys_addr_t paddr) 327static int is_swiotlb_buffer(phys_addr_t paddr)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 993599e66e5a..8e75003d62f6 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -777,6 +777,18 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
777 return string(buf, end, uuid, spec); 777 return string(buf, end, uuid, spec);
778} 778}
779 779
780static
781char *netdev_feature_string(char *buf, char *end, const u8 *addr,
782 struct printf_spec spec)
783{
784 spec.flags |= SPECIAL | SMALL | ZEROPAD;
785 if (spec.field_width == -1)
786 spec.field_width = 2 + 2 * sizeof(netdev_features_t);
787 spec.base = 16;
788
789 return number(buf, end, *(const netdev_features_t *)addr, spec);
790}
791
780int kptr_restrict __read_mostly; 792int kptr_restrict __read_mostly;
781 793
782/* 794/*
@@ -824,6 +836,7 @@ int kptr_restrict __read_mostly;
824 * Do not use this feature without some mechanism to verify the 836 * Do not use this feature without some mechanism to verify the
825 * correctness of the format string and va_list arguments. 837 * correctness of the format string and va_list arguments.
826 * - 'K' For a kernel pointer that should be hidden from unprivileged users 838 * - 'K' For a kernel pointer that should be hidden from unprivileged users
839 * - 'NF' For a netdev_features_t
827 * 840 *
828 * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 841 * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
829 * function pointers are really function descriptors, which contain a 842 * function pointers are really function descriptors, which contain a
@@ -896,6 +909,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
896 has_capability_noaudit(current, CAP_SYSLOG)))) 909 has_capability_noaudit(current, CAP_SYSLOG))))
897 ptr = NULL; 910 ptr = NULL;
898 break; 911 break;
912 case 'N':
913 switch (fmt[1]) {
914 case 'F':
915 return netdev_feature_string(buf, end, ptr, spec);
916 }
917 break;
899 } 918 }
900 spec.flags |= SMALL; 919 spec.flags |= SMALL;
901 if (spec.field_width == -1) { 920 if (spec.field_width == -1) {