For the quite common 'skb->h.raw - skb->data' sequence.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
        u8 css, cso;
 
        if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
-               cso = skb->h.raw - skb->data;
-               css = (skb->h.raw + skb->csum_offset) - skb->data;
+               cso = skb_transport_offset(skb);
+               css = cso + skb->csum;
                if (unlikely(cso & 0x1)) {
                        printk(KERN_DEBUG "%s: payload offset != even number\n",
                                atl1_driver_name);
 
        if (tcp_seg) {
                /* TSO/GSO */
-               proto_hdr_len =
-                   ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
+               proto_hdr_len = (skb_transport_offset(skb) +
+                                (skb->h.th->doff << 2));
                buffer_info->length = proto_hdr_len;
                page = virt_to_page(skb->data);
                offset = (unsigned long)skb->data & ~PAGE_MASK;
        mss = skb_shinfo(skb)->gso_size;
        if (mss) {
                if (skb->protocol == htons(ETH_P_IP)) {
-                       proto_hdr_len = ((skb->h.raw - skb->data) +
+                       proto_hdr_len = (skb_transport_offset(skb) +
                                         (skb->h.th->doff << 2));
                        if (unlikely(proto_hdr_len > len)) {
                                dev_kfree_skb_any(skb);
 
 
        ctrl = 0;
        if (skb->ip_summed == CHECKSUM_PARTIAL) {
-               u64 csum_start_off, csum_stuff_off;
-
-               csum_start_off = (u64) (skb->h.raw - skb->data);
-               csum_stuff_off = csum_start_off + skb->csum_offset;
+               const u64 csum_start_off = skb_transport_offset(skb);
+               const u64 csum_stuff_off = csum_start_off + skb->csum_offset;
 
                ctrl =  TX_DESC_CSUM_EN |
                        CAS_BASE(TX_DESC_CSUM_START, csum_start_off) |
 
        /* Only TX_DATA builds SGLs */
 
        from = (struct work_request_hdr *)skb->data;
-       memcpy(&d->flit[1], &from[1], skb->h.raw - skb->data - sizeof(*from));
+       memcpy(&d->flit[1], &from[1],
+              skb_transport_offset(skb) - sizeof(*from));
 
-       flits = (skb->h.raw - skb->data) / 8;
+       flits = skb_transport_offset(skb) / 8;
        sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl;
        sgl_flits = make_sgl(skb, sgp, skb->h.raw, skb->tail - skb->h.raw,
                             adap->pdev);
        if (skb->len <= WR_LEN && cnt == 0)
                return 1;       /* packet fits as immediate data */
 
-       flits = (skb->h.raw - skb->data) / 8;   /* headers */
+       flits = skb_transport_offset(skb) / 8;  /* headers */
        if (skb->tail != skb->h.raw)
                cnt++;
        return flits_to_desc(flits + sgl_len(cnt));
 
                                return err;
                }
 
-               hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
+               hdr_len = (skb_transport_offset(skb) + (skb->h.th->doff << 2));
                mss = skb_shinfo(skb)->gso_size;
                if (skb->protocol == htons(ETH_P_IP)) {
                        struct iphdr *iph = ip_hdr(skb);
                                                              iph->daddr, 0,
                                                              IPPROTO_TCP, 0);
                        cmd_length = E1000_TXD_CMD_IP;
-                       ipcse = skb->h.raw - skb->data - 1;
+                       ipcse = skb_transport_offset(skb) - 1;
                } else if (skb->protocol == htons(ETH_P_IPV6)) {
                        ipv6_hdr(skb)->payload_len = 0;
                        skb->h.th->check =
                }
                ipcss = skb_network_offset(skb);
                ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
-               tucss = skb->h.raw - skb->data;
+               tucss = skb_transport_offset(skb);
                tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
                tucse = 0;
 
        uint8_t css;
 
        if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
-               css = skb->h.raw - skb->data;
+               css = skb_transport_offset(skb);
 
                i = tx_ring->next_to_use;
                buffer_info = &tx_ring->buffer_info[i];
                /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
                * points to just header, pull a few bytes of payload from
                * frags into skb->data */
-               hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
+               hdr_len = (skb_transport_offset(skb) + (skb->h.th->doff << 2));
                if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
                        switch (adapter->hw.mac_type) {
                                unsigned int pull_size;
 
                                return err;
                }
 
-               hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
+               hdr_len = (skb_transport_offset(skb) + (skb->h.th->doff << 2));
                mss = skb_shinfo(skb)->gso_size;
                iph = ip_hdr(skb);
                iph->tot_len = 0;
                                                      0, IPPROTO_TCP, 0);
                ipcss = skb_network_offset(skb);
                ipcso = (void *)&(iph->check) - (void *)skb->data;
-               ipcse = skb->h.raw - skb->data - 1;
-               tucss = skb->h.raw - skb->data;
+               ipcse = skb_transport_offset(skb) - 1;
+               tucss = skb_transport_offset(skb);
                tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
                tucse = 0;
 
 
        if(likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
                struct ixgb_buffer *buffer_info;
-               css = skb->h.raw - skb->data;
+               css = skb_transport_offset(skb);
                cso = css + skb->csum_offset;
 
                i = adapter->tx_ring.next_to_use;
 
        odd_flag = 0;
        flags = (MXGEFW_FLAGS_NO_TSO | MXGEFW_FLAGS_FIRST);
        if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
-               cksum_offset = (skb->h.raw - skb->data);
+               cksum_offset = skb_transport_offset(skb);
                pseudo_hdr_offset = cksum_offset + skb->csum_offset;
                /* If the headers are excessively large, then we must
                 * fall back to a software checksum */
                 * send loop that we are still in the
                 * header portion of the TSO packet.
                 * TSO header must be at most 134 bytes long */
-               cum_len = -((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
+               cum_len = -(skb_transport_offset(skb) +
+                           (skb->h.th->doff << 2));
 
                /* for TSO, pseudo_hdr_offset holds mss.
                 * The firmware figures out where to put
 
                }
        }
        adapter->stats.xmitcsummed++;
-       desc->tcp_hdr_offset = skb->h.raw - skb->data;
+       desc->tcp_hdr_offset = skb_transport_offset(skb);
        desc->ip_hdr_offset = skb_network_offset(skb);
 }
 
 
        pTxd->pMBuf     = pMessage;
 
        if (pMessage->ip_summed == CHECKSUM_PARTIAL) {
-               u16 hdrlen = pMessage->h.raw - pMessage->data;
+               u16 hdrlen = skb_transport_offset(pMessage);
                u16 offset = hdrlen + pMessage->csum_offset;
 
                if ((pMessage->h.ipiph->protocol == IPPROTO_UDP ) &&
        ** Does the HW need to evaluate checksum for TCP or UDP packets? 
        */
        if (pMessage->ip_summed == CHECKSUM_PARTIAL) {
-               u16 hdrlen = pMessage->h.raw - pMessage->data;
+               u16 hdrlen = skb_transport_offset(pMessage);
                u16 offset = hdrlen + pMessage->csum_offset;
 
                Control = BMU_STFWD;
 
        td->dma_hi = map >> 32;
 
        if (skb->ip_summed == CHECKSUM_PARTIAL) {
-               int offset = skb->h.raw - skb->data;
+               const int offset = skb_transport_offset(skb);
 
                /* This seems backwards, but it is what the sk98lin
                 * does.  Looks like hardware is wrong?
 
 
        /* Handle TCP checksum offload */
        if (skb->ip_summed == CHECKSUM_PARTIAL) {
-               unsigned offset = skb->h.raw - skb->data;
+               const unsigned offset = skb_transport_offset(skb);
                u32 tcpsum;
 
                tcpsum = offset << 16;          /* sum start */
 
 
        ctrl = 0;
        if (skb->ip_summed == CHECKSUM_PARTIAL) {
-               u64 csum_start_off, csum_stuff_off;
-
-               csum_start_off = (u64) (skb->h.raw - skb->data);
-               csum_stuff_off = csum_start_off + skb->csum_offset;
+               const u64 csum_start_off = skb_transport_offset(skb);
+               const u64 csum_stuff_off = csum_start_off + skb->csum_offset;
 
                ctrl = (TXDCTRL_CENAB |
                        (csum_start_off << 15) |
 
 
        tx_flags = TXFLAG_OWN;
        if (skb->ip_summed == CHECKSUM_PARTIAL) {
-               u32 csum_start_off, csum_stuff_off;
-
-               csum_start_off = (u32) (skb->h.raw - skb->data);
-               csum_stuff_off = csum_start_off + skb->csum_offset;
+               const u32 csum_start_off = skb_transport_offset(skb);
+               const u32 csum_stuff_off = csum_start_off + skb->csum_offset;
 
                tx_flags = (TXFLAG_OWN | TXFLAG_CSENABLE |
                            ((csum_start_off << 14) & TXFLAG_CSBUFBEGIN) |
 
        skb->h.raw = skb->data;
 }
 
+static inline int skb_transport_offset(const struct sk_buff *skb)
+{
+       return skb->h.raw - skb->data;
+}
+
 static inline unsigned char *skb_network_header(const struct sk_buff *skb)
 {
        return skb->nh.raw;
 
 
 static inline __wsum udplite_csum_outgoing(struct sock *sk, struct sk_buff *skb)
 {
-       int off, len, cscov = udplite_sender_cscov(udp_sk(sk), skb->h.uh);
+       int cscov = udplite_sender_cscov(udp_sk(sk), skb->h.uh);
        __wsum csum = 0;
 
        skb->ip_summed = CHECKSUM_NONE;     /* no HW support for checksumming */
 
        skb_queue_walk(&sk->sk_write_queue, skb) {
-               off = skb->h.raw - skb->data;
-               len = skb->len - off;
+               const int off = skb_transport_offset(skb);
+               const int len = skb->len - off;
 
                csum = skb_checksum(skb, off, (cscov > len)? len : cscov, csum);
 
 
 int skb_checksum_help(struct sk_buff *skb)
 {
        __wsum csum;
-       int ret = 0, offset = skb->h.raw - skb->data;
+       int ret = 0, offset = skb_transport_offset(skb);
 
        if (skb->ip_summed == CHECKSUM_COMPLETE)
                goto out_set_summed;
 
        long csstart;
 
        if (skb->ip_summed == CHECKSUM_PARTIAL)
-               csstart = skb->h.raw - skb->data;
+               csstart = skb_transport_offset(skb);
        else
                csstart = skb_headlen(skb);
 
 
        int nfrags;
 
        /* Strip IP+ESP header. */
-       __skb_pull(skb, skb->h.raw - skb->data);
+       __skb_pull(skb, skb_transport_offset(skb));
        /* Now skb is pure payload to encrypt */
 
        err = -ENOMEM;
 
                 * fragments on the socket so that all csums of sk_buffs
                 * should be together
                 */
-               offset = skb->h.raw - skb->data;
+               offset = skb_transport_offset(skb);
                skb->csum = skb_checksum(skb, offset, skb->len - offset, 0);
 
                skb->ip_summed = CHECKSUM_NONE;
 
 static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
 {
        int err;
-       int hdr_len;
        struct ipv6hdr *top_iph;
        struct ipv6_esp_hdr *esph;
        struct crypto_blkcipher *tfm;
        struct blkcipher_desc desc;
-       struct esp_data *esp;
        struct sk_buff *trailer;
        int blksize;
        int clen;
        int alen;
        int nfrags;
-
-       esp = x->data;
-       hdr_len = skb->h.raw - skb->data +
-                 sizeof(*esph) + esp->conf.ivlen;
+       struct esp_data *esp = x->data;
+       int hdr_len = (skb_transport_offset(skb) +
+                      sizeof(*esph) + esp->conf.ivlen);
 
        /* Strip IP+ESP header. */
        __skb_pull(skb, hdr_len);
 
        int off = skb->h.raw - skb->nh.raw;
        int len = ((skb->h.raw[1]+1)<<3);
 
-       if ((skb->h.raw + len) - skb->data > skb_headlen(skb))
+       if (skb_transport_offset(skb) + len > skb_headlen(skb))
                goto bad;
 
        off += 2;
 #endif
        struct dst_entry *dst;
 
-       if (!pskb_may_pull(skb, (skb->h.raw-skb->data)+8) ||
-           !pskb_may_pull(skb, (skb->h.raw-skb->data)+((skb->h.raw[1]+1)<<3))) {
+       if (!pskb_may_pull(skb, skb_transport_offset(skb) + 8) ||
+           !pskb_may_pull(skb, (skb_transport_offset(skb) +
+                                ((skb->h.raw[1] + 1) << 3)))) {
                IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
                                 IPSTATS_MIB_INHDRERRORS);
                kfree_skb(skb);
 
        in6_dev_put(idev);
 
-       if (!pskb_may_pull(skb, (skb->h.raw-skb->data)+8) ||
-           !pskb_may_pull(skb, (skb->h.raw-skb->data)+((skb->h.raw[1]+1)<<3))) {
+       if (!pskb_may_pull(skb, skb_transport_offset(skb) + 8) ||
+           !pskb_may_pull(skb, (skb_transport_offset(skb) +
+                                ((skb->h.raw[1] + 1) << 3)))) {
                IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
                                 IPSTATS_MIB_INHDRERRORS);
                kfree_skb(skb);
 
        rcu_read_lock();
 resubmit:
        idev = ip6_dst_idev(skb->dst);
-       if (!pskb_pull(skb, skb->h.raw - skb->data))
+       if (!pskb_pull(skb, skb_transport_offset(skb)))
                goto discard;
        nhoff = IP6CB(skb)->nhoff;
        nexthdr = skb_network_header(skb)[nhoff];
 
 {
        int err;
        struct ipv6hdr *top_iph;
-       int hdr_len;
        struct ipv6_comp_hdr *ipch;
        struct ipcomp_data *ipcd = x->data;
        int plen, dlen;
        u8 *start, *scratch;
        struct crypto_comp *tfm;
        int cpu;
-
-       hdr_len = skb->h.raw - skb->data;
+       int hdr_len = skb_transport_offset(skb);
 
        /* check whether datagram len is larger than threshold */
        if ((skb->len - hdr_len) < ipcd->threshold) {
 
 {
        struct ip6_mh *mh;
 
-       if (!pskb_may_pull(skb, (skb->h.raw - skb->data) + 8) ||
-           !pskb_may_pull(skb, (skb->h.raw - skb->data) + ((skb->h.raw[1] + 1) << 3)))
+       if (!pskb_may_pull(skb, (skb_transport_offset(skb)) + 8) ||
+           !pskb_may_pull(skb, (skb_transport_offset(skb) +
+                                ((skb->h.raw[1] + 1) << 3))))
                return -1;
 
        mh = (struct ip6_mh *)skb->h.raw;
 
                        if (csum_skb)
                                continue;
 
-                       len = skb->len - (skb->h.raw - skb->data);
+                       len = skb->len - skb_transport_offset(skb);
                        if (offset >= len) {
                                offset -= len;
                                continue;
                skb = csum_skb;
        }
 
-       offset += skb->h.raw - skb->data;
+       offset += skb_transport_offset(skb);
        if (skb_copy_bits(skb, offset, &csum, 2))
                BUG();
 
 
                icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, skb->h.raw-skb->nh.raw);
                return -1;
        }
-       if (!pskb_may_pull(skb, (skb->h.raw-skb->data)+sizeof(struct frag_hdr))) {
+       if (!pskb_may_pull(skb, (skb_transport_offset(skb) +
+                                sizeof(struct frag_hdr)))) {
                IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_INHDRERRORS);
                icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, skb->h.raw-skb->nh.raw);
                return -1;
 
        sh = (struct sctphdr *) skb->h.raw;
 
        /* Pull up the IP and SCTP headers. */
-       __skb_pull(skb, skb->h.raw - skb->data);
+       __skb_pull(skb, skb_transport_offset(skb));
        if (skb->len < sizeof(struct sctphdr))
                goto discard_it;
        if ((skb->ip_summed != CHECKSUM_UNNECESSARY) &&