Sparse reports the following warnings: net/rds/af_rds.c:245:22: warning: invalid assignment: |= net/rds/af_rds.c:245:22: left side has type restricted __poll_t net/rds/af_rds.c:245:22: right side has type int __poll_t is typedef'ed to __bitwise while POLLERR is defined as 0x0008, force conversion. net/rds/recv.c:218:42: warning: cast to restricted __be16 net/rds/recv.c:222:44: warning: cast to restricted __be32 Replace be{16,32}_to_cpu with explicit __force to force conversion. The value remains the same either way so not a bug. net/rds/send.c:1050:24: warning: incorrect type in argument 1 (different base types) net/rds/send.c:1050:24: expected unsigned int [usertype] a net/rds/send.c:1050:24: got restricted __be16 [usertype] sin6_port net/rds/send.c:1052:24: warning: incorrect type in argument 1 (different base types) net/rds/send.c:1052:24: expected unsigned int [usertype] a net/rds/send.c:1052:24: got restricted __be16 [usertype] sin6_port net/rds/send.c:1457:30: warning: incorrect type in initializer (different base types) net/rds/send.c:1457:30: expected unsigned short [usertype] npaths net/rds/send.c:1457:30: got restricted __be16 [usertype] net/rds/send.c:1458:34: warning: incorrect type in initializer (different base types) net/rds/send.c:1458:34: expected unsigned int [usertype] my_gen_num net/rds/send.c:1458:34: got restricted __be32 [usertype] Use correct endianness. Replace cpu_to_be{16,32} for the same reason as above. net/rds/connection.c:71:31: warning: incorrect type in argument 1 (different base types) net/rds/connection.c:71:31: expected restricted __be32 const [usertype] laddr net/rds/connection.c:71:31: got unsigned int [assigned] [usertype] lhash net/rds/connection.c:71:41: warning: incorrect type in argument 3 (different base types) net/rds/connection.c:71:41: expected restricted __be32 const [usertype] faddr net/rds/connection.c:71:41: got unsigned int [assigned] [usertype] fhash Signed-off-by: Ujwal Kundur --- net/rds/af_rds.c | 2 +- net/rds/connection.c | 6 +++--- net/rds/rdma.c | 1 - net/rds/rds.h | 2 +- net/rds/recv.c | 4 ++-- net/rds/send.c | 4 ++-- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/net/rds/af_rds.c b/net/rds/af_rds.c index 086a13170e09..9cd5905d916a 100644 --- a/net/rds/af_rds.c +++ b/net/rds/af_rds.c @@ -242,7 +242,7 @@ static __poll_t rds_poll(struct file *file, struct socket *sock, if (rs->rs_snd_bytes < rds_sk_sndbuf(rs)) mask |= (EPOLLOUT | EPOLLWRNORM); if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) - mask |= POLLERR; + mask |= (__force __poll_t)POLLERR; read_unlock_irqrestore(&rs->rs_recv_lock, flags); /* clear state any time we wake a seen-congested socket */ diff --git a/net/rds/connection.c b/net/rds/connection.c index d62f486ab29f..0047b76c3c0b 100644 --- a/net/rds/connection.c +++ b/net/rds/connection.c @@ -62,13 +62,13 @@ static struct hlist_head *rds_conn_bucket(const struct in6_addr *laddr, net_get_random_once(&rds_hash_secret, sizeof(rds_hash_secret)); net_get_random_once(&rds6_hash_secret, sizeof(rds6_hash_secret)); - lhash = (__force u32)laddr->s6_addr32[3]; + lhash = (__force __u32)laddr->s6_addr32[3]; #if IS_ENABLED(CONFIG_IPV6) fhash = __ipv6_addr_jhash(faddr, rds6_hash_secret); #else - fhash = (__force u32)faddr->s6_addr32[3]; + fhash = (__force __u32)(faddr->s6_addr32[3]); #endif - hash = __inet_ehashfn(lhash, 0, fhash, 0, rds_hash_secret); + hash = __inet_ehashfn((__force __be32)lhash, 0, (__force __be32)fhash, 0, rds_hash_secret); return &rds_conn_hash[hash & RDS_CONNECTION_HASH_MASK]; } diff --git a/net/rds/rdma.c b/net/rds/rdma.c index 00dbcd4d28e6..f9bcec8f745a 100644 --- a/net/rds/rdma.c +++ b/net/rds/rdma.c @@ -39,7 +39,6 @@ /* * XXX - * - build with sparse * - should we detect duplicate keys on a socket? hmm. * - an rdma is an mlock, apply rlimit? */ diff --git a/net/rds/rds.h b/net/rds/rds.h index dc360252c515..c2fb47e1fe07 100644 --- a/net/rds/rds.h +++ b/net/rds/rds.h @@ -93,7 +93,7 @@ enum { /* Max number of multipaths per RDS connection. Must be a power of 2 */ #define RDS_MPATH_WORKERS 8 -#define RDS_MPATH_HASH(rs, n) (jhash_1word((rs)->rs_bound_port, \ +#define RDS_MPATH_HASH(rs, n) (jhash_1word((__force __u16)(rs)->rs_bound_port, \ (rs)->rs_hash_initval) & ((n) - 1)) #define IS_CANONICAL(laddr, faddr) (htonl(laddr) < htonl(faddr)) diff --git a/net/rds/recv.c b/net/rds/recv.c index 5627f80013f8..7fc7a3850a7b 100644 --- a/net/rds/recv.c +++ b/net/rds/recv.c @@ -216,10 +216,10 @@ static void rds_recv_hs_exthdrs(struct rds_header *hdr, switch (type) { case RDS_EXTHDR_NPATHS: conn->c_npaths = min_t(int, RDS_MPATH_WORKERS, - be16_to_cpu(buffer.rds_npaths)); + (__force __u16)buffer.rds_npaths); break; case RDS_EXTHDR_GEN_NUM: - new_peer_gen_num = be32_to_cpu(buffer.rds_gen_num); + new_peer_gen_num = (__force __u32)buffer.rds_gen_num; break; default: pr_warn_ratelimited("ignoring unknown exthdr type " diff --git a/net/rds/send.c b/net/rds/send.c index 42d991bc8543..0d79455c9721 100644 --- a/net/rds/send.c +++ b/net/rds/send.c @@ -1454,8 +1454,8 @@ rds_send_probe(struct rds_conn_path *cp, __be16 sport, if (RDS_HS_PROBE(be16_to_cpu(sport), be16_to_cpu(dport)) && cp->cp_conn->c_trans->t_mp_capable) { - u16 npaths = cpu_to_be16(RDS_MPATH_WORKERS); - u32 my_gen_num = cpu_to_be32(cp->cp_conn->c_my_gen_num); + u16 npaths = (__force __u16)RDS_MPATH_WORKERS; + u32 my_gen_num = (__force __u32)cp->cp_conn->c_my_gen_num; rds_message_add_extension(&rm->m_inc.i_hdr, RDS_EXTHDR_NPATHS, &npaths, -- 2.30.2