aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux
diff options
context:
space:
mode:
authorSasha Levin <sasha.levin@oracle.com>2013-02-27 20:06:00 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 22:10:24 -0500
commitb67bfe0d42cac56c512dd5da4b1b347a23f4b70a (patch)
tree3d465aea12b97683f26ffa38eba8744469de9997 /security/selinux
parent1e142b29e210b5dfb2deeb6ce2210b60af16d2a6 (diff)
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived list_for_each_entry(pos, head, member) The hlist ones were greedy and wanted an extra parameter: hlist_for_each_entry(tpos, pos, head, member) Why did they need an extra pos parameter? I'm not quite sure. Not only they don't really need it, it also prevents the iterator from looking exactly like the list iterator, which is unfortunate. Besides the semantic patch, there was some manual work required: - Fix up the actual hlist iterators in linux/list.h - Fix up the declaration of other iterators based on the hlist ones. - A very small amount of places were using the 'node' parameter, this was modified to use 'obj->member' instead. - Coccinelle didn't handle the hlist_for_each_entry_safe iterator properly, so those had to be fixed up manually. The semantic patch which is mostly the work of Peter Senna Tschudin is here: @@ iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host; type T; expression a,c,d,e; identifier b; statement S; @@ -T b; <+... when != b ( hlist_for_each_entry(a, - b, c, d) S | hlist_for_each_entry_continue(a, - b, c) S | hlist_for_each_entry_from(a, - b, c) S | hlist_for_each_entry_rcu(a, - b, c, d) S | hlist_for_each_entry_rcu_bh(a, - b, c, d) S | hlist_for_each_entry_continue_rcu_bh(a, - b, c) S | for_each_busy_worker(a, c, - b, d) S | ax25_uid_for_each(a, - b, c) S | ax25_for_each(a, - b, c) S | inet_bind_bucket_for_each(a, - b, c) S | sctp_for_each_hentry(a, - b, c) S | sk_for_each(a, - b, c) S | sk_for_each_rcu(a, - b, c) S | sk_for_each_from -(a, b) +(a) S + sk_for_each_from(a) S | sk_for_each_safe(a, - b, c, d) S | sk_for_each_bound(a, - b, c) S | hlist_for_each_entry_safe(a, - b, c, d, e) S | hlist_for_each_entry_continue_rcu(a, - b, c) S | nr_neigh_for_each(a, - b, c) S | nr_neigh_for_each_safe(a, - b, c, d) S | nr_node_for_each(a, - b, c) S | nr_node_for_each_safe(a, - b, c, d) S | - for_each_gfn_sp(a, c, d, b) S + for_each_gfn_sp(a, c, d) S | - for_each_gfn_indirect_valid_sp(a, c, d, b) S + for_each_gfn_indirect_valid_sp(a, c, d) S | for_each_host(a, - b, c) S | for_each_host_safe(a, - b, c, d) S | for_each_mesh_entry(a, - b, c, d) S ) ...+> [akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c] [akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c] [akpm@linux-foundation.org: checkpatch fixes] [akpm@linux-foundation.org: fix warnings] [akpm@linux-foudnation.org: redo intrusive kvm changes] Tested-by: Peter Senna Tschudin <peter.senna@gmail.com> Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Signed-off-by: Sasha Levin <sasha.levin@oracle.com> Cc: Wu Fengguang <fengguang.wu@intel.com> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Gleb Natapov <gleb@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'security/selinux')
-rw-r--r--security/selinux/avc.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/security/selinux/avc.c b/security/selinux/avc.c
index 4d3fab47e643..dad36a6ab45f 100644
--- a/security/selinux/avc.c
+++ b/security/selinux/avc.c
@@ -188,11 +188,9 @@ int avc_get_hash_stats(char *page)
188 for (i = 0; i < AVC_CACHE_SLOTS; i++) { 188 for (i = 0; i < AVC_CACHE_SLOTS; i++) {
189 head = &avc_cache.slots[i]; 189 head = &avc_cache.slots[i];
190 if (!hlist_empty(head)) { 190 if (!hlist_empty(head)) {
191 struct hlist_node *next;
192
193 slots_used++; 191 slots_used++;
194 chain_len = 0; 192 chain_len = 0;
195 hlist_for_each_entry_rcu(node, next, head, list) 193 hlist_for_each_entry_rcu(node, head, list)
196 chain_len++; 194 chain_len++;
197 if (chain_len > max_chain_len) 195 if (chain_len > max_chain_len)
198 max_chain_len = chain_len; 196 max_chain_len = chain_len;
@@ -241,7 +239,6 @@ static inline int avc_reclaim_node(void)
241 int hvalue, try, ecx; 239 int hvalue, try, ecx;
242 unsigned long flags; 240 unsigned long flags;
243 struct hlist_head *head; 241 struct hlist_head *head;
244 struct hlist_node *next;
245 spinlock_t *lock; 242 spinlock_t *lock;
246 243
247 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) { 244 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
@@ -253,7 +250,7 @@ static inline int avc_reclaim_node(void)
253 continue; 250 continue;
254 251
255 rcu_read_lock(); 252 rcu_read_lock();
256 hlist_for_each_entry(node, next, head, list) { 253 hlist_for_each_entry(node, head, list) {
257 avc_node_delete(node); 254 avc_node_delete(node);
258 avc_cache_stats_incr(reclaims); 255 avc_cache_stats_incr(reclaims);
259 ecx++; 256 ecx++;
@@ -301,11 +298,10 @@ static inline struct avc_node *avc_search_node(u32 ssid, u32 tsid, u16 tclass)
301 struct avc_node *node, *ret = NULL; 298 struct avc_node *node, *ret = NULL;
302 int hvalue; 299 int hvalue;
303 struct hlist_head *head; 300 struct hlist_head *head;
304 struct hlist_node *next;
305 301
306 hvalue = avc_hash(ssid, tsid, tclass); 302 hvalue = avc_hash(ssid, tsid, tclass);
307 head = &avc_cache.slots[hvalue]; 303 head = &avc_cache.slots[hvalue];
308 hlist_for_each_entry_rcu(node, next, head, list) { 304 hlist_for_each_entry_rcu(node, head, list) {
309 if (ssid == node->ae.ssid && 305 if (ssid == node->ae.ssid &&
310 tclass == node->ae.tclass && 306 tclass == node->ae.tclass &&
311 tsid == node->ae.tsid) { 307 tsid == node->ae.tsid) {
@@ -394,7 +390,6 @@ static struct avc_node *avc_insert(u32 ssid, u32 tsid, u16 tclass, struct av_dec
394 node = avc_alloc_node(); 390 node = avc_alloc_node();
395 if (node) { 391 if (node) {
396 struct hlist_head *head; 392 struct hlist_head *head;
397 struct hlist_node *next;
398 spinlock_t *lock; 393 spinlock_t *lock;
399 394
400 hvalue = avc_hash(ssid, tsid, tclass); 395 hvalue = avc_hash(ssid, tsid, tclass);
@@ -404,7 +399,7 @@ static struct avc_node *avc_insert(u32 ssid, u32 tsid, u16 tclass, struct av_dec
404 lock = &avc_cache.slots_lock[hvalue]; 399 lock = &avc_cache.slots_lock[hvalue];
405 400
406 spin_lock_irqsave(lock, flag); 401 spin_lock_irqsave(lock, flag);
407 hlist_for_each_entry(pos, next, head, list) { 402 hlist_for_each_entry(pos, head, list) {
408 if (pos->ae.ssid == ssid && 403 if (pos->ae.ssid == ssid &&
409 pos->ae.tsid == tsid && 404 pos->ae.tsid == tsid &&
410 pos->ae.tclass == tclass) { 405 pos->ae.tclass == tclass) {
@@ -541,7 +536,6 @@ static int avc_update_node(u32 event, u32 perms, u32 ssid, u32 tsid, u16 tclass,
541 unsigned long flag; 536 unsigned long flag;
542 struct avc_node *pos, *node, *orig = NULL; 537 struct avc_node *pos, *node, *orig = NULL;
543 struct hlist_head *head; 538 struct hlist_head *head;
544 struct hlist_node *next;
545 spinlock_t *lock; 539 spinlock_t *lock;
546 540
547 node = avc_alloc_node(); 541 node = avc_alloc_node();
@@ -558,7 +552,7 @@ static int avc_update_node(u32 event, u32 perms, u32 ssid, u32 tsid, u16 tclass,
558 552
559 spin_lock_irqsave(lock, flag); 553 spin_lock_irqsave(lock, flag);
560 554
561 hlist_for_each_entry(pos, next, head, list) { 555 hlist_for_each_entry(pos, head, list) {
562 if (ssid == pos->ae.ssid && 556 if (ssid == pos->ae.ssid &&
563 tsid == pos->ae.tsid && 557 tsid == pos->ae.tsid &&
564 tclass == pos->ae.tclass && 558 tclass == pos->ae.tclass &&
@@ -614,7 +608,6 @@ out:
614static void avc_flush(void) 608static void avc_flush(void)
615{ 609{
616 struct hlist_head *head; 610 struct hlist_head *head;
617 struct hlist_node *next;
618 struct avc_node *node; 611 struct avc_node *node;
619 spinlock_t *lock; 612 spinlock_t *lock;
620 unsigned long flag; 613 unsigned long flag;
@@ -630,7 +623,7 @@ static void avc_flush(void)
630 * prevent RCU grace periods from ending. 623 * prevent RCU grace periods from ending.
631 */ 624 */
632 rcu_read_lock(); 625 rcu_read_lock();
633 hlist_for_each_entry(node, next, head, list) 626 hlist_for_each_entry(node, head, list)
634 avc_node_delete(node); 627 avc_node_delete(node);
635 rcu_read_unlock(); 628 rcu_read_unlock();
636 spin_unlock_irqrestore(lock, flag); 629 spin_unlock_irqrestore(lock, flag);