summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2018-04-09 16:12:31 -0400
committerDavid Howells <dhowells@redhat.com>2018-04-09 16:12:31 -0400
commitfe342cf77bc3c3ba89e8bb1e4eddbe614df4efa4 (patch)
treed47c6b4998b585a3c845d70617669119a4456877 /fs
parenta09acf4b43b90581bf53b0c03cc84ed693bf27e2 (diff)
afs: Fix checker warnings
Fix warnings raised by checker, including: (*) Warnings raised by unequal comparison for the purposes of sorting, where the endianness doesn't matter: fs/afs/addr_list.c:246:21: warning: restricted __be16 degrades to integer fs/afs/addr_list.c:246:30: warning: restricted __be16 degrades to integer fs/afs/addr_list.c:248:21: warning: restricted __be32 degrades to integer fs/afs/addr_list.c:248:49: warning: restricted __be32 degrades to integer fs/afs/addr_list.c:283:21: warning: restricted __be16 degrades to integer fs/afs/addr_list.c:283:30: warning: restricted __be16 degrades to integer (*) afs_set_cb_interest() is not actually used and can be removed. (*) afs_cell_gc_delay() should be provided with a sysctl. (*) afs_cell_destroy() needs to use rcu_access_pointer() to read cell->vl_addrs. (*) afs_init_fs_cursor() should be static. (*) struct afs_vnode::permit_cache needs to be marked __rcu. (*) afs_server_rcu() needs to use rcu_access_pointer(). (*) afs_destroy_server() should use rcu_access_pointer() on server->addresses as the server object is no longer accessible. (*) afs_find_server() casts __be16/__be32 values to int in order to directly compare them for the purpose of finding a match in a list, but is should also annotate the cast with __force to avoid checker warnings. (*) afs_check_permit() accesses vnode->permit_cache outside of the RCU readlock, though it doesn't then access the value; the extraneous access is deleted. False positives: (*) Conditional locking around the code in xdr_decode_AFSFetchStatus. This can be dealt with in a separate patch. fs/afs/fsclient.c:148:9: warning: context imbalance in 'xdr_decode_AFSFetchStatus' - different lock contexts for basic block (*) Incorrect handling of seq-retry lock context balance: fs/afs/inode.c:455:38: warning: context imbalance in 'afs_getattr' - different lock contexts for basic block fs/afs/server.c:52:17: warning: context imbalance in 'afs_find_server' - different lock contexts for basic block fs/afs/server.c:128:17: warning: context imbalance in 'afs_find_server_by_uuid' - different lock contexts for basic block Errors: (*) afs_lookup_cell_rcu() needs to break out of the seq-retry loop, not go round again if it successfully found the workstation cell. (*) Fix UUID decode in afs_deliver_cb_probe_uuid(). (*) afs_cache_permit() has a missing rcu_read_unlock() before one of the jumps to the someone_else_changed_it label. Move the unlock to after the label. (*) afs_vl_get_addrs_u() is using ntohl() rather than htonl() when encoding to XDR. (*) afs_deliver_yfsvl_get_endpoints() is using htonl() rather than ntohl() when decoding from XDR. Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/afs/addr_list.c6
-rw-r--r--fs/afs/callback.c20
-rw-r--r--fs/afs/cell.c6
-rw-r--r--fs/afs/cmservice.c6
-rw-r--r--fs/afs/inode.c2
-rw-r--r--fs/afs/internal.h2
-rw-r--r--fs/afs/proc.c8
-rw-r--r--fs/afs/rotate.c2
-rw-r--r--fs/afs/security.c11
-rw-r--r--fs/afs/server.c14
-rw-r--r--fs/afs/vlclient.c8
11 files changed, 35 insertions, 50 deletions
diff --git a/fs/afs/addr_list.c b/fs/afs/addr_list.c
index fd9f28b8a933..3bedfed608a2 100644
--- a/fs/afs/addr_list.c
+++ b/fs/afs/addr_list.c
@@ -243,9 +243,9 @@ void afs_merge_fs_addr4(struct afs_addr_list *alist, __be32 xdr, u16 port)
243 xport == a->sin6_port) 243 xport == a->sin6_port)
244 return; 244 return;
245 if (xdr == a->sin6_addr.s6_addr32[3] && 245 if (xdr == a->sin6_addr.s6_addr32[3] &&
246 xport < a->sin6_port) 246 (u16 __force)xport < (u16 __force)a->sin6_port)
247 break; 247 break;
248 if (xdr < a->sin6_addr.s6_addr32[3]) 248 if ((u32 __force)xdr < (u32 __force)a->sin6_addr.s6_addr32[3])
249 break; 249 break;
250 } 250 }
251 251
@@ -280,7 +280,7 @@ void afs_merge_fs_addr6(struct afs_addr_list *alist, __be32 *xdr, u16 port)
280 xport == a->sin6_port) 280 xport == a->sin6_port)
281 return; 281 return;
282 if (diff == 0 && 282 if (diff == 0 &&
283 xport < a->sin6_port) 283 (u16 __force)xport < (u16 __force)a->sin6_port)
284 break; 284 break;
285 if (diff < 0) 285 if (diff < 0)
286 break; 286 break;
diff --git a/fs/afs/callback.c b/fs/afs/callback.c
index f4291b576054..bf082c719645 100644
--- a/fs/afs/callback.c
+++ b/fs/afs/callback.c
@@ -97,26 +97,6 @@ again:
97} 97}
98 98
99/* 99/*
100 * Set a vnode's interest on a server.
101 */
102void afs_set_cb_interest(struct afs_vnode *vnode, struct afs_cb_interest *cbi)
103{
104 struct afs_cb_interest *old_cbi = NULL;
105
106 if (vnode->cb_interest == cbi)
107 return;
108
109 write_seqlock(&vnode->cb_lock);
110 if (vnode->cb_interest != cbi) {
111 afs_get_cb_interest(cbi);
112 old_cbi = vnode->cb_interest;
113 vnode->cb_interest = cbi;
114 }
115 write_sequnlock(&vnode->cb_lock);
116 afs_put_cb_interest(afs_v2net(vnode), cbi);
117}
118
119/*
120 * Remove an interest on a server. 100 * Remove an interest on a server.
121 */ 101 */
122void afs_put_cb_interest(struct afs_net *net, struct afs_cb_interest *cbi) 102void afs_put_cb_interest(struct afs_net *net, struct afs_cb_interest *cbi)
diff --git a/fs/afs/cell.c b/fs/afs/cell.c
index 4235a05afc76..69b95faacc5e 100644
--- a/fs/afs/cell.c
+++ b/fs/afs/cell.c
@@ -18,7 +18,7 @@
18#include <keys/rxrpc-type.h> 18#include <keys/rxrpc-type.h>
19#include "internal.h" 19#include "internal.h"
20 20
21unsigned __read_mostly afs_cell_gc_delay = 10; 21static unsigned __read_mostly afs_cell_gc_delay = 10;
22 22
23static void afs_manage_cell(struct work_struct *); 23static void afs_manage_cell(struct work_struct *);
24 24
@@ -75,7 +75,7 @@ struct afs_cell *afs_lookup_cell_rcu(struct afs_net *net,
75 cell = rcu_dereference_raw(net->ws_cell); 75 cell = rcu_dereference_raw(net->ws_cell);
76 if (cell) { 76 if (cell) {
77 afs_get_cell(cell); 77 afs_get_cell(cell);
78 continue; 78 break;
79 } 79 }
80 ret = -EDESTADDRREQ; 80 ret = -EDESTADDRREQ;
81 continue; 81 continue;
@@ -411,7 +411,7 @@ static void afs_cell_destroy(struct rcu_head *rcu)
411 411
412 ASSERTCMP(atomic_read(&cell->usage), ==, 0); 412 ASSERTCMP(atomic_read(&cell->usage), ==, 0);
413 413
414 afs_put_addrlist(cell->vl_addrs); 414 afs_put_addrlist(rcu_access_pointer(cell->vl_addrs));
415 key_put(cell->anonymous_key); 415 key_put(cell->anonymous_key);
416 kfree(cell); 416 kfree(cell);
417 417
diff --git a/fs/afs/cmservice.c b/fs/afs/cmservice.c
index 41e277f57b20..83ff283979a4 100644
--- a/fs/afs/cmservice.c
+++ b/fs/afs/cmservice.c
@@ -500,9 +500,9 @@ static int afs_deliver_cb_probe_uuid(struct afs_call *call)
500 500
501 b = call->buffer; 501 b = call->buffer;
502 r = call->request; 502 r = call->request;
503 r->time_low = ntohl(b[0]); 503 r->time_low = b[0];
504 r->time_mid = ntohl(b[1]); 504 r->time_mid = htons(ntohl(b[1]));
505 r->time_hi_and_version = ntohl(b[2]); 505 r->time_hi_and_version = htons(ntohl(b[2]));
506 r->clock_seq_hi_and_reserved = ntohl(b[3]); 506 r->clock_seq_hi_and_reserved = ntohl(b[3]);
507 r->clock_seq_low = ntohl(b[4]); 507 r->clock_seq_low = ntohl(b[4]);
508 508
diff --git a/fs/afs/inode.c b/fs/afs/inode.c
index 65c5b1edd338..d5db9dead18c 100644
--- a/fs/afs/inode.c
+++ b/fs/afs/inode.c
@@ -544,7 +544,7 @@ void afs_evict_inode(struct inode *inode)
544 } 544 }
545#endif 545#endif
546 546
547 afs_put_permits(vnode->permit_cache); 547 afs_put_permits(rcu_access_pointer(vnode->permit_cache));
548 _leave(""); 548 _leave("");
549} 549}
550 550
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index a6a1d75eee41..135192b7dc04 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -458,7 +458,7 @@ struct afs_vnode {
458#ifdef CONFIG_AFS_FSCACHE 458#ifdef CONFIG_AFS_FSCACHE
459 struct fscache_cookie *cache; /* caching cookie */ 459 struct fscache_cookie *cache; /* caching cookie */
460#endif 460#endif
461 struct afs_permits *permit_cache; /* cache of permits so far obtained */ 461 struct afs_permits __rcu *permit_cache; /* cache of permits so far obtained */
462 struct mutex io_lock; /* Lock for serialising I/O on this mutex */ 462 struct mutex io_lock; /* Lock for serialising I/O on this mutex */
463 struct mutex validate_lock; /* lock for validating this vnode */ 463 struct mutex validate_lock; /* lock for validating this vnode */
464 spinlock_t wb_lock; /* lock for wb_keys */ 464 spinlock_t wb_lock; /* lock for wb_keys */
diff --git a/fs/afs/proc.c b/fs/afs/proc.c
index 4508dd54f789..1c95756335b7 100644
--- a/fs/afs/proc.c
+++ b/fs/afs/proc.c
@@ -183,6 +183,7 @@ static int afs_proc_cells_open(struct inode *inode, struct file *file)
183 * first item 183 * first item
184 */ 184 */
185static void *afs_proc_cells_start(struct seq_file *m, loff_t *_pos) 185static void *afs_proc_cells_start(struct seq_file *m, loff_t *_pos)
186 __acquires(rcu)
186{ 187{
187 struct afs_net *net = afs_seq2net(m); 188 struct afs_net *net = afs_seq2net(m);
188 189
@@ -204,6 +205,7 @@ static void *afs_proc_cells_next(struct seq_file *m, void *v, loff_t *pos)
204 * clean up after reading from the cells list 205 * clean up after reading from the cells list
205 */ 206 */
206static void afs_proc_cells_stop(struct seq_file *m, void *v) 207static void afs_proc_cells_stop(struct seq_file *m, void *v)
208 __releases(rcu)
207{ 209{
208 rcu_read_unlock(); 210 rcu_read_unlock();
209} 211}
@@ -413,6 +415,7 @@ static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file)
413 * first item 415 * first item
414 */ 416 */
415static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos) 417static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos)
418 __acquires(cell->proc_lock)
416{ 419{
417 struct afs_cell *cell = m->private; 420 struct afs_cell *cell = m->private;
418 421
@@ -438,6 +441,7 @@ static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
438 * clean up after reading from the cells list 441 * clean up after reading from the cells list
439 */ 442 */
440static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v) 443static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v)
444 __releases(cell->proc_lock)
441{ 445{
442 struct afs_cell *cell = p->private; 446 struct afs_cell *cell = p->private;
443 447
@@ -500,6 +504,7 @@ static int afs_proc_cell_vlservers_open(struct inode *inode, struct file *file)
500 * first item 504 * first item
501 */ 505 */
502static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos) 506static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos)
507 __acquires(rcu)
503{ 508{
504 struct afs_addr_list *alist; 509 struct afs_addr_list *alist;
505 struct afs_cell *cell = m->private; 510 struct afs_cell *cell = m->private;
@@ -544,6 +549,7 @@ static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v,
544 * clean up after reading from the cells list 549 * clean up after reading from the cells list
545 */ 550 */
546static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v) 551static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v)
552 __releases(rcu)
547{ 553{
548 rcu_read_unlock(); 554 rcu_read_unlock();
549} 555}
@@ -580,6 +586,7 @@ static int afs_proc_servers_open(struct inode *inode, struct file *file)
580 * first item. 586 * first item.
581 */ 587 */
582static void *afs_proc_servers_start(struct seq_file *m, loff_t *_pos) 588static void *afs_proc_servers_start(struct seq_file *m, loff_t *_pos)
589 __acquires(rcu)
583{ 590{
584 struct afs_net *net = afs_seq2net(m); 591 struct afs_net *net = afs_seq2net(m);
585 592
@@ -601,6 +608,7 @@ static void *afs_proc_servers_next(struct seq_file *m, void *v, loff_t *_pos)
601 * clean up after reading from the cells list 608 * clean up after reading from the cells list
602 */ 609 */
603static void afs_proc_servers_stop(struct seq_file *p, void *v) 610static void afs_proc_servers_stop(struct seq_file *p, void *v)
611 __releases(rcu)
604{ 612{
605 rcu_read_unlock(); 613 rcu_read_unlock();
606} 614}
diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c
index ad1328d85526..ac0feac9d746 100644
--- a/fs/afs/rotate.c
+++ b/fs/afs/rotate.c
@@ -21,7 +21,7 @@
21/* 21/*
22 * Initialise a filesystem server cursor for iterating over FS servers. 22 * Initialise a filesystem server cursor for iterating over FS servers.
23 */ 23 */
24void afs_init_fs_cursor(struct afs_fs_cursor *fc, struct afs_vnode *vnode) 24static void afs_init_fs_cursor(struct afs_fs_cursor *fc, struct afs_vnode *vnode)
25{ 25{
26 memset(fc, 0, sizeof(*fc)); 26 memset(fc, 0, sizeof(*fc));
27} 27}
diff --git a/fs/afs/security.c b/fs/afs/security.c
index b88b7d45fdaa..bd82c5bf4a6a 100644
--- a/fs/afs/security.c
+++ b/fs/afs/security.c
@@ -178,18 +178,14 @@ void afs_cache_permit(struct afs_vnode *vnode, struct key *key,
178 } 178 }
179 } 179 }
180 180
181 if (cb_break != (vnode->cb_break + vnode->cb_interest->server->cb_s_break)) { 181 if (cb_break != (vnode->cb_break + vnode->cb_interest->server->cb_s_break))
182 rcu_read_unlock();
183 goto someone_else_changed_it; 182 goto someone_else_changed_it;
184 }
185 183
186 /* We need a ref on any permits list we want to copy as we'll have to 184 /* We need a ref on any permits list we want to copy as we'll have to
187 * drop the lock to do memory allocation. 185 * drop the lock to do memory allocation.
188 */ 186 */
189 if (permits && !refcount_inc_not_zero(&permits->usage)) { 187 if (permits && !refcount_inc_not_zero(&permits->usage))
190 rcu_read_unlock();
191 goto someone_else_changed_it; 188 goto someone_else_changed_it;
192 }
193 189
194 rcu_read_unlock(); 190 rcu_read_unlock();
195 191
@@ -278,6 +274,7 @@ someone_else_changed_it:
278 /* Someone else changed the cache under us - don't recheck at this 274 /* Someone else changed the cache under us - don't recheck at this
279 * time. 275 * time.
280 */ 276 */
277 rcu_read_unlock();
281 return; 278 return;
282} 279}
283 280
@@ -296,8 +293,6 @@ int afs_check_permit(struct afs_vnode *vnode, struct key *key,
296 _enter("{%x:%u},%x", 293 _enter("{%x:%u},%x",
297 vnode->fid.vid, vnode->fid.vnode, key_serial(key)); 294 vnode->fid.vid, vnode->fid.vnode, key_serial(key));
298 295
299 permits = vnode->permit_cache;
300
301 /* check the permits to see if we've got one yet */ 296 /* check the permits to see if we've got one yet */
302 if (key == vnode->volume->cell->anonymous_key) { 297 if (key == vnode->volume->cell->anonymous_key) {
303 _debug("anon"); 298 _debug("anon");
diff --git a/fs/afs/server.c b/fs/afs/server.c
index a43ef77dabae..e23be63998a8 100644
--- a/fs/afs/server.c
+++ b/fs/afs/server.c
@@ -59,7 +59,8 @@ struct afs_server *afs_find_server(struct afs_net *net,
59 alist = rcu_dereference(server->addresses); 59 alist = rcu_dereference(server->addresses);
60 for (i = alist->nr_ipv4; i < alist->nr_addrs; i++) { 60 for (i = alist->nr_ipv4; i < alist->nr_addrs; i++) {
61 b = &alist->addrs[i].transport.sin6; 61 b = &alist->addrs[i].transport.sin6;
62 diff = (u16)a->sin6_port - (u16)b->sin6_port; 62 diff = ((u16 __force)a->sin6_port -
63 (u16 __force)b->sin6_port);
63 if (diff == 0) 64 if (diff == 0)
64 diff = memcmp(&a->sin6_addr, 65 diff = memcmp(&a->sin6_addr,
65 &b->sin6_addr, 66 &b->sin6_addr,
@@ -79,10 +80,11 @@ struct afs_server *afs_find_server(struct afs_net *net,
79 alist = rcu_dereference(server->addresses); 80 alist = rcu_dereference(server->addresses);
80 for (i = 0; i < alist->nr_ipv4; i++) { 81 for (i = 0; i < alist->nr_ipv4; i++) {
81 b = &alist->addrs[i].transport.sin6; 82 b = &alist->addrs[i].transport.sin6;
82 diff = (u16)a->sin6_port - (u16)b->sin6_port; 83 diff = ((u16 __force)a->sin6_port -
84 (u16 __force)b->sin6_port);
83 if (diff == 0) 85 if (diff == 0)
84 diff = ((u32)a->sin6_addr.s6_addr32[3] - 86 diff = ((u32 __force)a->sin6_addr.s6_addr32[3] -
85 (u32)b->sin6_addr.s6_addr32[3]); 87 (u32 __force)b->sin6_addr.s6_addr32[3]);
86 if (diff == 0) 88 if (diff == 0)
87 goto found; 89 goto found;
88 if (diff < 0) { 90 if (diff < 0) {
@@ -381,7 +383,7 @@ static void afs_server_rcu(struct rcu_head *rcu)
381{ 383{
382 struct afs_server *server = container_of(rcu, struct afs_server, rcu); 384 struct afs_server *server = container_of(rcu, struct afs_server, rcu);
383 385
384 afs_put_addrlist(server->addresses); 386 afs_put_addrlist(rcu_access_pointer(server->addresses));
385 kfree(server); 387 kfree(server);
386} 388}
387 389
@@ -390,7 +392,7 @@ static void afs_server_rcu(struct rcu_head *rcu)
390 */ 392 */
391static void afs_destroy_server(struct afs_net *net, struct afs_server *server) 393static void afs_destroy_server(struct afs_net *net, struct afs_server *server)
392{ 394{
393 struct afs_addr_list *alist = server->addresses; 395 struct afs_addr_list *alist = rcu_access_pointer(server->addresses);
394 struct afs_addr_cursor ac = { 396 struct afs_addr_cursor ac = {
395 .alist = alist, 397 .alist = alist,
396 .addr = &alist->addrs[0], 398 .addr = &alist->addrs[0],
diff --git a/fs/afs/vlclient.c b/fs/afs/vlclient.c
index 5d8562f1ad4a..f9d89795e41b 100644
--- a/fs/afs/vlclient.c
+++ b/fs/afs/vlclient.c
@@ -303,7 +303,7 @@ struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *net,
303 r->uuid.clock_seq_hi_and_reserved = htonl(u->clock_seq_hi_and_reserved); 303 r->uuid.clock_seq_hi_and_reserved = htonl(u->clock_seq_hi_and_reserved);
304 r->uuid.clock_seq_low = htonl(u->clock_seq_low); 304 r->uuid.clock_seq_low = htonl(u->clock_seq_low);
305 for (i = 0; i < 6; i++) 305 for (i = 0; i < 6; i++)
306 r->uuid.node[i] = ntohl(u->node[i]); 306 r->uuid.node[i] = htonl(u->node[i]);
307 307
308 trace_afs_make_vl_call(call); 308 trace_afs_make_vl_call(call);
309 return (struct afs_addr_list *)afs_make_call(ac, call, GFP_KERNEL, false); 309 return (struct afs_addr_list *)afs_make_call(ac, call, GFP_KERNEL, false);
@@ -504,7 +504,7 @@ again:
504 /* Got either the type of the next entry or the count of 504 /* Got either the type of the next entry or the count of
505 * volEndpoints if no more fsEndpoints. 505 * volEndpoints if no more fsEndpoints.
506 */ 506 */
507 call->count2 = htonl(*bp++); 507 call->count2 = ntohl(*bp++);
508 508
509 call->offset = 0; 509 call->offset = 0;
510 call->count--; 510 call->count--;
@@ -531,7 +531,7 @@ again:
531 return ret; 531 return ret;
532 532
533 bp = call->buffer; 533 bp = call->buffer;
534 call->count2 = htonl(*bp++); 534 call->count2 = ntohl(*bp++);
535 call->offset = 0; 535 call->offset = 0;
536 call->unmarshall = 4; 536 call->unmarshall = 4;
537 537
@@ -576,7 +576,7 @@ again:
576 call->offset = 0; 576 call->offset = 0;
577 call->count--; 577 call->count--;
578 if (call->count > 0) { 578 if (call->count > 0) {
579 call->count2 = htonl(*bp++); 579 call->count2 = ntohl(*bp++);
580 goto again; 580 goto again;
581 } 581 }
582 582