Skip to content

Commit 97bc84b

Browse files
Hoang Huu Ledavem330
authored andcommitted
tipc: clean up warnings detected by sparse
This patch fixes the following warning from sparse: net/tipc/monitor.c:263:35: warning: incorrect type in assignment (different base types) net/tipc/monitor.c:263:35: expected unsigned int net/tipc/monitor.c:263:35: got restricted __be32 [usertype] [...] net/tipc/node.c:374:13: warning: context imbalance in 'tipc_node_read_lock' - wrong count at exit net/tipc/node.c:379:13: warning: context imbalance in 'tipc_node_read_unlock' - unexpected unlock net/tipc/node.c:384:13: warning: context imbalance in 'tipc_node_write_lock' - wrong count at exit net/tipc/node.c:389:13: warning: context imbalance in 'tipc_node_write_unlock_fast' - unexpected unlock net/tipc/node.c:404:17: warning: context imbalance in 'tipc_node_write_unlock' - unexpected unlock [...] net/tipc/crypto.c:1201:9: warning: incorrect type in initializer (different address spaces) net/tipc/crypto.c:1201:9: expected struct tipc_aead [noderef] __rcu *__tmp net/tipc/crypto.c:1201:9: got struct tipc_aead * [...] Acked-by: Jon Maloy <jmaloy@redhat.com> Signed-off-by: Hoang Huu Le <hoang.h.le@dektech.com.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1980d37 commit 97bc84b

File tree

3 files changed

+58
-22
lines changed

3 files changed

+58
-22
lines changed

net/tipc/crypto.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static int tipc_aead_key_generate(struct tipc_aead_key *skey);
317317

318318
#define tipc_aead_rcu_replace(rcu_ptr, ptr, lock) \
319319
do { \
320-
typeof(rcu_ptr) __tmp = rcu_dereference_protected((rcu_ptr), \
320+
struct tipc_aead *__tmp = rcu_dereference_protected((rcu_ptr), \
321321
lockdep_is_held(lock)); \
322322
rcu_assign_pointer((rcu_ptr), (ptr)); \
323323
tipc_aead_put(__tmp); \
@@ -798,7 +798,7 @@ static int tipc_aead_encrypt(struct tipc_aead *aead, struct sk_buff *skb,
798798
ehdr = (struct tipc_ehdr *)skb->data;
799799
salt = aead->salt;
800800
if (aead->mode == CLUSTER_KEY)
801-
salt ^= ehdr->addr; /* __be32 */
801+
salt ^= __be32_to_cpu(ehdr->addr);
802802
else if (__dnode)
803803
salt ^= tipc_node_get_addr(__dnode);
804804
memcpy(iv, &salt, 4);
@@ -929,7 +929,7 @@ static int tipc_aead_decrypt(struct net *net, struct tipc_aead *aead,
929929
ehdr = (struct tipc_ehdr *)skb->data;
930930
salt = aead->salt;
931931
if (aead->mode == CLUSTER_KEY)
932-
salt ^= ehdr->addr; /* __be32 */
932+
salt ^= __be32_to_cpu(ehdr->addr);
933933
else if (ehdr->destined)
934934
salt ^= tipc_own_addr(net);
935935
memcpy(iv, &salt, 4);
@@ -1946,16 +1946,16 @@ static void tipc_crypto_rcv_complete(struct net *net, struct tipc_aead *aead,
19461946
goto rcv;
19471947
}
19481948
tipc_aead_put(aead);
1949-
aead = tipc_aead_get(tmp);
1949+
aead = tipc_aead_get((struct tipc_aead __force __rcu *)tmp);
19501950
}
19511951

19521952
if (unlikely(err)) {
1953-
tipc_aead_users_dec(aead, INT_MIN);
1953+
tipc_aead_users_dec((struct tipc_aead __force __rcu *)aead, INT_MIN);
19541954
goto free_skb;
19551955
}
19561956

19571957
/* Set the RX key's user */
1958-
tipc_aead_users_set(aead, 1);
1958+
tipc_aead_users_set((struct tipc_aead __force __rcu *)aead, 1);
19591959

19601960
/* Mark this point, RX works */
19611961
rx->timer1 = jiffies;

net/tipc/monitor.c

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,36 @@ static struct tipc_monitor *tipc_monitor(struct net *net, int bearer_id)
104104

105105
const int tipc_max_domain_size = sizeof(struct tipc_mon_domain);
106106

107+
static inline u16 mon_cpu_to_le16(u16 val)
108+
{
109+
return (__force __u16)htons(val);
110+
}
111+
112+
static inline u32 mon_cpu_to_le32(u32 val)
113+
{
114+
return (__force __u32)htonl(val);
115+
}
116+
117+
static inline u64 mon_cpu_to_le64(u64 val)
118+
{
119+
return (__force __u64)cpu_to_be64(val);
120+
}
121+
122+
static inline u16 mon_le16_to_cpu(u16 val)
123+
{
124+
return ntohs((__force __be16)val);
125+
}
126+
127+
static inline u32 mon_le32_to_cpu(u32 val)
128+
{
129+
return ntohl((__force __be32)val);
130+
}
131+
132+
static inline u64 mon_le64_to_cpu(u64 val)
133+
{
134+
return be64_to_cpu((__force __be64)val);
135+
}
136+
107137
/* dom_rec_len(): actual length of domain record for transport
108138
*/
109139
static int dom_rec_len(struct tipc_mon_domain *dom, u16 mcnt)
@@ -260,16 +290,16 @@ static void mon_update_local_domain(struct tipc_monitor *mon)
260290
diff |= dom->members[i] != peer->addr;
261291
dom->members[i] = peer->addr;
262292
map_set(&dom->up_map, i, peer->is_up);
263-
cache->members[i] = htonl(peer->addr);
293+
cache->members[i] = mon_cpu_to_le32(peer->addr);
264294
}
265295
diff |= dom->up_map != prev_up_map;
266296
if (!diff)
267297
return;
268298
dom->gen = ++mon->dom_gen;
269-
cache->len = htons(dom->len);
270-
cache->gen = htons(dom->gen);
271-
cache->member_cnt = htons(member_cnt);
272-
cache->up_map = cpu_to_be64(dom->up_map);
299+
cache->len = mon_cpu_to_le16(dom->len);
300+
cache->gen = mon_cpu_to_le16(dom->gen);
301+
cache->member_cnt = mon_cpu_to_le16(member_cnt);
302+
cache->up_map = mon_cpu_to_le64(dom->up_map);
273303
mon_apply_domain(mon, self);
274304
}
275305

@@ -455,10 +485,11 @@ void tipc_mon_rcv(struct net *net, void *data, u16 dlen, u32 addr,
455485
struct tipc_mon_domain dom_bef;
456486
struct tipc_mon_domain *dom;
457487
struct tipc_peer *peer;
458-
u16 new_member_cnt = ntohs(arrv_dom->member_cnt);
488+
u16 new_member_cnt = mon_le16_to_cpu(arrv_dom->member_cnt);
459489
int new_dlen = dom_rec_len(arrv_dom, new_member_cnt);
460-
u16 new_gen = ntohs(arrv_dom->gen);
461-
u16 acked_gen = ntohs(arrv_dom->ack_gen);
490+
u16 new_gen = mon_le16_to_cpu(arrv_dom->gen);
491+
u16 acked_gen = mon_le16_to_cpu(arrv_dom->ack_gen);
492+
u16 arrv_dlen = mon_le16_to_cpu(arrv_dom->len);
462493
bool probing = state->probing;
463494
int i, applied_bef;
464495

@@ -469,7 +500,7 @@ void tipc_mon_rcv(struct net *net, void *data, u16 dlen, u32 addr,
469500
return;
470501
if (dlen != dom_rec_len(arrv_dom, new_member_cnt))
471502
return;
472-
if ((dlen < new_dlen) || ntohs(arrv_dom->len) != new_dlen)
503+
if (dlen < new_dlen || arrv_dlen != new_dlen)
473504
return;
474505

475506
/* Synch generation numbers with peer if link just came up */
@@ -517,9 +548,9 @@ void tipc_mon_rcv(struct net *net, void *data, u16 dlen, u32 addr,
517548
dom->len = new_dlen;
518549
dom->gen = new_gen;
519550
dom->member_cnt = new_member_cnt;
520-
dom->up_map = be64_to_cpu(arrv_dom->up_map);
551+
dom->up_map = mon_le64_to_cpu(arrv_dom->up_map);
521552
for (i = 0; i < new_member_cnt; i++)
522-
dom->members[i] = ntohl(arrv_dom->members[i]);
553+
dom->members[i] = mon_le32_to_cpu(arrv_dom->members[i]);
523554

524555
/* Update peers affected by this domain record */
525556
applied_bef = peer->applied;
@@ -548,19 +579,19 @@ void tipc_mon_prep(struct net *net, void *data, int *dlen,
548579
if (likely(state->acked_gen == gen)) {
549580
len = dom_rec_len(dom, 0);
550581
*dlen = len;
551-
dom->len = htons(len);
552-
dom->gen = htons(gen);
553-
dom->ack_gen = htons(state->peer_gen);
582+
dom->len = mon_cpu_to_le16(len);
583+
dom->gen = mon_cpu_to_le16(gen);
584+
dom->ack_gen = mon_cpu_to_le16(state->peer_gen);
554585
dom->member_cnt = 0;
555586
return;
556587
}
557588
/* Send the full record */
558589
read_lock_bh(&mon->lock);
559-
len = ntohs(mon->cache.len);
590+
len = mon_le16_to_cpu(mon->cache.len);
560591
*dlen = len;
561592
memcpy(data, &mon->cache, len);
562593
read_unlock_bh(&mon->lock);
563-
dom->ack_gen = htons(state->peer_gen);
594+
dom->ack_gen = mon_cpu_to_le16(state->peer_gen);
564595
}
565596

566597
void tipc_mon_get_state(struct net *net, u32 addr,

net/tipc/node.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,26 +372,31 @@ static struct tipc_node *tipc_node_find_by_id(struct net *net, u8 *id)
372372
}
373373

374374
static void tipc_node_read_lock(struct tipc_node *n)
375+
__acquires(n->lock)
375376
{
376377
read_lock_bh(&n->lock);
377378
}
378379

379380
static void tipc_node_read_unlock(struct tipc_node *n)
381+
__releases(n->lock)
380382
{
381383
read_unlock_bh(&n->lock);
382384
}
383385

384386
static void tipc_node_write_lock(struct tipc_node *n)
387+
__acquires(n->lock)
385388
{
386389
write_lock_bh(&n->lock);
387390
}
388391

389392
static void tipc_node_write_unlock_fast(struct tipc_node *n)
393+
__releases(n->lock)
390394
{
391395
write_unlock_bh(&n->lock);
392396
}
393397

394398
static void tipc_node_write_unlock(struct tipc_node *n)
399+
__releases(n->lock)
395400
{
396401
struct net *net = n->net;
397402
u32 addr = 0;

0 commit comments

Comments
 (0)