net: Remove casts to same type
authorJoe Perches <joe@perches.com>
Sun, 3 Jun 2012 17:41:40 +0000 (17:41 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 4 Jun 2012 15:45:11 +0000 (11:45 -0400)
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

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
14 files changed:
net/9p/client.c
net/atm/lec.c
net/decnet/dn_nsp_out.c
net/ipv4/af_inet.c
net/ipv4/fib_trie.c
net/ipv4/netfilter/nf_nat_snmp_basic.c
net/ipv6/exthdrs.c
net/irda/irqueue.c
net/l2tp/l2tp_ppp.c
net/mac80211/scan.c
net/netfilter/nf_conntrack_core.c
net/packet/af_packet.c
net/tipc/port.c
net/tipc/socket.c

index a170893d70e0a06b58e478ddba1733cbda696330..5cbea903a5abf3b942fa66733bc56159c3a3580d 100644 (file)
@@ -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)
index 3da125c384eab4381617ff76a9b6521f839bbdeb..2e3d942e77f133eb9197e295d419f7c71c4f8178 100644 (file)
@@ -1604,7 +1604,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);
 
index 564a6ad13ce78d74b8fe3d02f16d6e6b40419817..8a96047c7c94334a217d9f85a7b091545e1e95d0 100644 (file)
@@ -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);
index c8f7aee587d1fde87fe136a8733e0e7556c8ec6e..e4e8e00a2c9104b4495970def34326dd4ab78b75 100644 (file)
@@ -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);
 
index 30b88d7b4bd61a27d396283e97633318d40d436a..18cbc15b20d5cc3dfc10c52ff344fa60a7ed3560 100644 (file)
@@ -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);
index 746edec8b86e156d85a13e4ef51bc7c8609fd49d..bac712293fd693a9f3afdd7f7776e845b17a35ea 100644 (file)
@@ -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;
                }
index 6447dc49429fc13832a8fda9afab5a1ee0b6050e..fa3d9c3280927934bd7b082077674c3c31d4ad4c 100644 (file)
@@ -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);
                }
index f06947c4fa82e59679314b07df2444906e99762f..7152624ed5f18035c2fd223bffd0682697cb86e4 100644 (file)
@@ -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;
index 8ef6b9416cba8937cb1c0c0602ddcbcf2871f1d2..286366ef8930a08981f04952d4459f2b9a413071 100644 (file)
@@ -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))
index 169da0742c817507e09a0119f1d1105077784231..6d90a562669faab8caaf332a9270a99cfc24d588 100644 (file)
@@ -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;
index ac3af97cc468eded7991ca98cd9dd6cec7f4d1cb..95976a593b981f25a7c653cbd2f34ddd1642bdfa 100644 (file)
@@ -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);
        }
index 0f661745df0fb2d52e7e6579da2f4b46c7ab75cb..71ac6559e0c66a47076fe79ce6668f850dbf4aa8 100644 (file)
@@ -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) {
index 2ad37a4db3760163ad8009c402e3e2fee2014998..a1e828989d7a64c591b6ca643b5073653c58d98b 100644 (file)
@@ -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;
 }
index 5577a447f5311b7cb8e7972c6bc2ffa075ba9432..11a863d81421b537610831f9b1ff0d1473e58eb2 100644 (file)
@@ -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))