net: Remove casts to same type
Subsystems (10)
PATCH 1/1 net: Remove casts to same type
Adding casts of objects to the same type is unnecessary and confusing for a human reader.
For example, this cast:
int y; int *p = (int *)&y;
I used the coccinelle script below to find and remove these unnecessary casts. I manually removed the conversions this script produces of casts with __force and __user.
@@
type T;
T *p;
@@
- (T *)p
+ p
---
Let me know if this needs to be broken up by maintainer.
net/9p/client.c | 2 +- net/atm/lec.c | 2 +- net/decnet/dn_nsp_out.c | 2 +- net/ipv4/af_inet.c | 2 +- net/ipv4/fib_trie.c | 13 ++++++------- net/ipv4/netfilter/nf_nat_snmp_basic.c | 4 ++-- net/ipv6/exthdrs.c | 4 ++-- net/irda/irqueue.c | 6 +++--- net/l2tp/l2tp_ppp.c | 8 ++++---- net/mac80211/scan.c | 3 +-- net/netfilter/nf_conntrack_core.c | 2 +- net/packet/af_packet.c | 9 ++++----- net/tipc/port.c | 9 ++++----- net/tipc/socket.c | 2 +- 14 files changed, 32 insertions(+), 36 deletions(-)
net/9p/client.c +1 -1
@@ -1548,7 +1548,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset, kernel_buf =1 ; indata = data; }else - indata = (char *)udata; + indata = udata;/* * response header len is 11 * PDU Header(7) + IO Size (4)
net/atm/lec.c +1 -1
@@ -1602,7 +1602,7 @@ static void lec_arp_expire_vcc(unsigned long data) {unsigned long flags;struct lec_arp_table *to_remove = (struct lec_arp_table *)data; -struct lec_priv *priv = (struct lec_priv *)to_remove->priv; +struct lec_priv *priv = to_remove->priv;del_timer (&to_remove->timer);
net/decnet/dn_nsp_out.c +1 -1
@@ -322,7 +322,7 @@ static __le16 *dn_mk_ack_header(struct sock *sk, struct sk_buff *skb, unsigned c/* Set "cross subchannel" bit in ackcrs */ ackcrs |=0x2000 ; - ptr = (__le16 *)dn_mk_common_header (scp, skb, msgflag, hlen); + ptr =dn_mk_common_header (scp, skb, msgflag, hlen); *ptr++ =cpu_to_le16 (acknum); *ptr++ =cpu_to_le16 (ackcrs);
net/ipv4/af_inet.c +1 -1
@@ -553,7 +553,7 @@ int inet_dgram_connect(struct socket *sock, struct sockaddr *uaddr,if (!inet_sk (sk)->inet_num &&inet_autobind (sk))return -EAGAIN ; -return sk->sk_prot->connect (sk, (struct sockaddr *)uaddr, addr_len); +return sk->sk_prot->connect (sk, uaddr, addr_len); }EXPORT_SYMBOL (inet_dgram_connect);
net/ipv4/fib_trie.c +6 -7
@@ -1007,9 +1007,9 @@ static void trie_rebalance(struct trie *t, struct tnode *tn)while (tn !=NULL && (tp =node_parent ((struct rt_trie_node *)tn)) !=NULL ) { cindex =tkey_extract_bits (key, tp->pos, tp->bits); wasfull =tnode_full (tp,tnode_get_child (tp, cindex)); - tn = (struct tnode *)resize (t, (struct tnode *)tn); + tn = (struct tnode *)resize (t, tn); -tnode_put_child_reorg ((struct tnode *)tp, cindex, +tnode_put_child_reorg (tp, cindex, (struct rt_trie_node *)tn, wasfull); tp =node_parent ((struct rt_trie_node *) tn);
@@ -1024,7 +1024,7 @@ static void trie_rebalance(struct trie *t, struct tnode *tn)/* Handle last (top) tnode */ if (IS_TNODE (tn)) - tn = (struct tnode *)resize (t, (struct tnode *)tn); + tn = (struct tnode *)resize (t, tn);rcu_assign_pointer (t->trie, (struct rt_trie_node *)tn);tnode_free_flush ();
@@ -1125,7 +1125,7 @@ static struct list_head *fib_insert_node(struct trie *t, u32 key, int plen)node_set_parent ((struct rt_trie_node *)l, tp); cindex =tkey_extract_bits (key, tp->pos, tp->bits); -put_child (t, (struct tnode *)tp, cindex, (struct rt_trie_node *)l); +put_child (t, tp, cindex, (struct rt_trie_node *)l); }else {/* Case 3: n is a LEAF or a TNODE and the key doesn't match. */ /*
@@ -1160,8 +1160,7 @@ static struct list_head *fib_insert_node(struct trie *t, u32 key, int plen)if (tp) { cindex =tkey_extract_bits (key, tp->pos, tp->bits); -put_child (t, (struct tnode *)tp, cindex, - (struct rt_trie_node *)tn); +put_child (t, tp, cindex, (struct rt_trie_node *)tn); }else {rcu_assign_pointer (t->trie, (struct rt_trie_node *)tn); tp = tn;
@@ -1620,7 +1619,7 @@ static void trie_leaf_remove(struct trie *t, struct leaf *l)if (tp) {t_key cindex =tkey_extract_bits (l->key, tp->pos, tp->bits); -put_child (t, (struct tnode *)tp, cindex,NULL ); +put_child (t, tp, cindex,NULL );trie_rebalance (t, tp); }else RCU_INIT_POINTER (t->trie,NULL );
net/ipv4/netfilter/nf_nat_snmp_basic.c +2 -2
@@ -405,7 +405,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx, ptr = *octets;while (ctx->pointer < eoc) { -if (!asn1_octet_decode (ctx, (unsigned char *)ptr++)) { +if (!asn1_octet_decode (ctx, ptr++)) {kfree (*octets); *octets =NULL ;return 0 ;
@@ -759,7 +759,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx, }break ;case SNMP_OBJECTID : -if (!asn1_oid_decode (ctx, end, (unsigned long **)&lp, &len)) { +if (!asn1_oid_decode (ctx, end, &lp, &len)) {kfree (id);return 0 ; }
net/ipv6/exthdrs.c +2 -2
@@ -791,14 +791,14 @@ static int ipv6_renew_option(void *ohdr,if (ohdr) {memcpy (*p, ohdr,ipv6_optlen ((struct ipv6_opt_hdr *)ohdr)); *hdr = (struct ipv6_opt_hdr *)*p; - *p +=CMSG_ALIGN (ipv6_optlen (*(struct ipv6_opt_hdr **)hdr)); + *p +=CMSG_ALIGN (ipv6_optlen (*hdr)); } }else {if (newopt) {if (copy_from_user (*p, newopt, newoptlen))return -EFAULT ; *hdr = (struct ipv6_opt_hdr *)*p; -if (ipv6_optlen (*(struct ipv6_opt_hdr **)hdr) > newoptlen) +if (ipv6_optlen (*hdr) > newoptlen)return -EINVAL ; *p +=CMSG_ALIGN (newoptlen); }
net/irda/irqueue.c +3 -3
@@ -523,7 +523,7 @@ void *hashbin_remove_first( hashbin_t *hashbin)* Dequeue the entry... */ dequeue_general ( (irda_queue_t **) &hashbin->hb_queue[ bin ], - (irda_queue_t *) entry ); + entry); hashbin->hb_size--; entry->q_next =NULL ; entry->q_prev =NULL ;
@@ -615,7 +615,7 @@ void* hashbin_remove( hashbin_t* hashbin, long hashv, const char* name)*/ if ( found ) {dequeue_general ( (irda_queue_t **) &hashbin->hb_queue[ bin ], - (irda_queue_t *) entry ); + entry); hashbin->hb_size--;/*
@@ -685,7 +685,7 @@ void* hashbin_remove_this( hashbin_t* hashbin, irda_queue_t* entry)* Dequeue the entry... */ dequeue_general ( (irda_queue_t **) &hashbin->hb_queue[ bin ], - (irda_queue_t *) entry ); + entry); hashbin->hb_size--; entry->q_next =NULL ; entry->q_prev =NULL ;
net/l2tp/l2tp_ppp.c +4 -4
@@ -1522,8 +1522,8 @@ static int pppol2tp_session_getsockopt(struct sock *sk,* handler, according to whether the PPPoX socket is a for a regular session * or the special tunnel type. */ -static int pppol2tp_getsockopt (struct socket *sock,int level, -int optname,char __user *optval,int __user *optlen) +static int pppol2tp_getsockopt (struct socket *sock,int level,int optname, +char __user *optval,int __user *optlen) {struct sock *sk = sock->sk;struct l2tp_session *session;
@@ -1535,7 +1535,7 @@ static int pppol2tp_getsockopt(struct socket *sock, int level,if (level !=SOL_PPPOL2TP )return udp_prot.getsockopt (sk, level, optname, optval, optlen); -if (get_user (len, (int __user *) optlen)) +if (get_user (len, optlen))return -EFAULT ; len = min_t(unsigned int, len, sizeof(int));
@@ -1568,7 +1568,7 @@ static int pppol2tp_getsockopt(struct socket *sock, int level, err =pppol2tp_session_getsockopt (sk, session, optname, &val); err = -EFAULT ; -if (put_user (len, (int __user *) optlen)) +if (put_user (len, optlen)) goto end_put_sess;if (copy_to_user ((void __user *) optval, &val, len))
net/mac80211/scan.c +1 -2
@@ -114,8 +114,7 @@ ieee80211_bss_info_update(struct ieee80211_local *local,if (elems->tim && (!elems->parse_error || !(bss->valid_data &IEEE80211_BSS_VALID_DTIM ))) { -struct ieee80211_tim_ie *tim_ie = - (struct ieee80211_tim_ie *)elems->tim; +struct ieee80211_tim_ie *tim_ie = elems->tim; bss->dtim_period = tim_ie->dtim_period;if (!elems->parse_error) bss->valid_data |=IEEE80211_BSS_VALID_DTIM ;
net/netfilter/nf_conntrack_core.c +1 -1
@@ -531,7 +531,7 @@ __nf_conntrack_confirm(struct sk_buff *skb) tstamp =nf_conn_tstamp_find (ct);if (tstamp) {if (skb->tstamp.tv64 ==0 ) -__net_timestamp ((struct sk_buff *)skb); +__net_timestamp (skb); tstamp->start =ktime_to_ns (skb->tstamp); }
net/packet/af_packet.c +4 -5
@@ -592,7 +592,7 @@ static void init_prb_bdqc(struct packet_sock *po, p1->knxt_seq_num =1 ; p1->pkbdq = pg_vec; pbd = (struct tpacket_block_desc *)pg_vec[0 ].buffer; - p1->pkblk_start = (char *)pg_vec[0 ].buffer; + p1->pkblk_start = pg_vec[0 ].buffer; p1->kblk_size = req_u->req3.tp_block_size; p1->knum_blocks = req_u->req3.tp_block_nr; p1->hdrlen = po->tp_hdrlen;
@@ -824,8 +824,7 @@ static void prb_open_block(struct tpacket_kbdq_core *pkc1, h1->ts_first_pkt.ts_sec = ts.tv_sec; h1->ts_first_pkt.ts_nsec = ts.tv_nsec; pkc1->pkblk_start = (char *)pbd1; - pkc1->nxt_offset = (char *)(pkc1->pkblk_start + -BLK_PLUS_PRIV (pkc1->blk_sizeof_priv)); + pkc1->nxt_offset = pkc1->pkblk_start +BLK_PLUS_PRIV (pkc1->blk_sizeof_priv);BLOCK_O2FP (pbd1) = (__u32 )BLK_PLUS_PRIV (pkc1->blk_sizeof_priv);BLOCK_O2PRIV (pbd1) =BLK_HDR_LEN ; pbd1->version = pkc1->version;
@@ -1018,7 +1017,7 @@ static void *__packet_lookup_frame_in_block(struct packet_sock *po,struct tpacket_block_desc *pbd;char *curr, *end; - pkc =GET_PBDQC_FROM_RB (((struct packet_ring_buffer *)&po->rx_ring)); + pkc =GET_PBDQC_FROM_RB (&po->rx_ring); pbd =GET_CURR_PBLOCK_DESC_FROM_CORE (pkc);/* Queue is frozen when user space is lagging behind */
@@ -1044,7 +1043,7 @@ static void *__packet_lookup_frame_in_block(struct packet_sock *po,smp_mb (); curr = pkc->nxt_offset; pkc->skb = skb; - end = (char *) ((char *)pbd + pkc->kblk_size); + end = (char *)pbd + pkc->kblk_size;/* first try the current block */ if (curr+TOTAL_PKT_LEN_INCL_ALIGN (len) < end) {
net/tipc/port.c +4 -5
@@ -909,8 +909,8 @@ int tipc_createport(void *usr_handle,warn ("Port creation failed, no memory\n" );return -ENOMEM ; } - p_ptr = (struct tipc_port *)tipc_createport_raw (NULL , port_dispatcher, - port_wakeup, importance); + p_ptr =tipc_createport_raw (NULL , port_dispatcher, port_wakeup, + importance);if (!p_ptr) {kfree (up_ptr);return -ENOMEM ;
@@ -1078,8 +1078,7 @@ int tipc_disconnect_port(struct tipc_port *tp_ptr)if (tp_ptr->connected) { tp_ptr->connected =0 ;/* let timer expire on it's own to avoid deadlock! */ -tipc_nodesub_unsubscribe ( - &((struct tipc_port *)tp_ptr)->subscription); +tipc_nodesub_unsubscribe (&tp_ptr->subscription); res =0 ; }else { res = -ENOTCONN ;
@@ -1099,7 +1098,7 @@ int tipc_disconnect(u32 ref) p_ptr =tipc_port_lock (ref);if (!p_ptr)return -EINVAL ; - res =tipc_disconnect_port ((struct tipc_port *)p_ptr); + res =tipc_disconnect_port (p_ptr);tipc_port_unlock (p_ptr);return res; }
net/tipc/socket.c +1 -1
@@ -54,7 +54,7 @@ struct tipc_sock { };#define tipc_sk (sk) ((struct tipc_sock *)(sk)) -#define tipc_sk_port (sk) ((struct tipc_port *)(tipc_sk(sk)->p)) +#define tipc_sk_port (sk) (tipc_sk(sk)->p)#define tipc_rx_ready (sock) (!skb_queue_empty(&sock->sk->sk_receive_queue) || \ (sock->state == SS_DISCONNECTING))
Signature · 1 line
1.7.8.111.gad25c.dirty
From: Joe Perches <[email protected]>
Date: Sun, 3 Jun 2012 20:41:40 -0700
Quoted 20 lines
Adding casts of objects to the same type is unnecessary and confusing for a human reader.
For example, this cast:
int y; int *p = (int *)&y;I used the coccinelle script below to find and remove these unnecessary casts. I manually removed the conversions this script produces of casts with
__forceand__user.@@
type T;
T *p;
@@(quoted diff) +1
-1- (T *)p + p
Quoted 1 line
Signed-off-by Joe Perches <[email protected]>
Applied to net-next, thanks Joe.
Quoted 3 lines · David Miller
From: Joe Perches <[email protected]>
Quoted 2 lines
Adding casts of objects to the same type is unnecessary and confusing for a human reader.
[]
Quoted 4 lines
Quoted 4 lines
I used the coccinelle script below to find and remove these unnecessary casts. I manually removed the conversions this script produces of casts with
__forceand__user.
Quoted 8 lines
Review
Quoted 7 lines
@@
type T;
T *p;
@@(quoted diff) +1
-1- (T *)p + pApplied to net-next, thanks Joe.
Do you want the same thing for drivers/net?
It's pretty big and might be better broken into
commits by maintainer/directory.
David Miller
maintainerFrom: Joe Perches <[email protected]>
Date: Mon, 04 Jun 2012 08:52:08 -0700
Quoted 14 lines · David Miller
Quoted 3 lines
From: Joe Perches <[email protected]>
Quoted 2 lines
Adding casts of objects to the same type is unnecessary and confusing for a human reader.
[]
Quoted 9 lines
Quoted 9 lines
I used the coccinelle script below to find and remove these unnecessary casts. I manually removed the conversions this script produces of casts with
__forceand__user.@@
type T;
T *p;
@@
Quoted 8 lines
Quoted 3 lines
Review
Quoted 2 lines
(quoted diff) +1
-1- (T *)p + pApplied to net-next, thanks Joe.
Do you want the same thing for
drivers/net?It's pretty big and might be better broken into
commits by maintainer/directory.
I don't see any value beyond perhaps splitting it into drivers/net/ethernet, drivers/net/wireless, and "rest".
Quoted 11 lines · Joe Perches
Adding casts of objects to the same type is unnecessary and confusing for a human reader.
For example, this cast:
int y; int *p = (int *)&y;I used the coccinelle script below to find and remove these unnecessary casts. I manually removed the conversions this script produces of casts with
__forceand__user.
[...]
net/9p/client.c p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset, · line 1554
Quoted 13 lines
net/9p/client.c +1
-1@@ -1548,7 +1548,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset, kernel_buf =1 ; indata = data; }else - indata = (char *)udata; + indata = udata;/* * response header len is 11 * PDU Header(7) + IO Size (4)
[...]
This one is casting char __user * to char *. We need a cast to let sparse know this is deliberate, though presumably we need __force as well.
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
PATCH 1/1 net/9p: Add __force to cast of __user pointer
A recent commit that removed unnecessary casts of pointers to the same type uncovered a missing __force cast.
Add it.
Reported by: Ben Hutchings <[email protected]>
--- net/9p/client.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/9p/client.c +1 -1
@@ -1548,7 +1548,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset, kernel_buf =1 ; indata = data; }else - indata = udata; + indata = (__force char *)udata;/* * response header len is 11 * PDU Header(7) + IO Size (4)
Re: [PATCH] net/9p: Add __force to cast of __user pointer
From: Joe Perches <[email protected]>
Date: Mon, 04 Jun 2012 10:16:14 -0700
Quoted 7 lines
A recent commit that removed unnecessary casts of pointers to the same type uncovered a missing
__forcecast.Add it.
Reported by: Ben Hutchings <[email protected]>
Signed-off-by Joe Perches <[email protected]>
Applied.