[NETLINK]: Possible cleanups.
[powerpc.git] / net / core / datagram.c
index aecddcc..e1afa76 100644 (file)
@@ -247,8 +247,8 @@ EXPORT_SYMBOL(skb_kill_datagram);
 int skb_copy_datagram_iovec(const struct sk_buff *skb, int offset,
                            struct iovec *to, int len)
 {
-       int start = skb_headlen(skb);
-       int i, copy = start - offset;
+       int end = skb_headlen(skb);
+       int i, copy = end - offset;
 
        /* Copy header. */
        if (copy > 0) {
@@ -263,11 +263,9 @@ int skb_copy_datagram_iovec(const struct sk_buff *skb, int offset,
 
        /* Copy paged appendix. Hmm... why does this look so complicated? */
        for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
-               int end;
+               BUG_TRAP(len >= 0);
 
-               BUG_TRAP(start <= offset + len);
-
-               end = start + skb_shinfo(skb)->frags[i].size;
+               end = offset + skb_shinfo(skb)->frags[i].size;
                if ((copy = end - offset) > 0) {
                        int err;
                        u8  *vaddr;
@@ -277,8 +275,8 @@ int skb_copy_datagram_iovec(const struct sk_buff *skb, int offset,
                        if (copy > len)
                                copy = len;
                        vaddr = kmap(page);
-                       err = memcpy_toiovec(to, vaddr + frag->page_offset +
-                                            offset - start, copy);
+                       err = memcpy_toiovec(to, vaddr + frag->page_offset,
+                                            copy);
                        kunmap(page);
                        if (err)
                                goto fault;
@@ -286,30 +284,24 @@ int skb_copy_datagram_iovec(const struct sk_buff *skb, int offset,
                                return 0;
                        offset += copy;
                }
-               start = end;
        }
 
        if (skb_shinfo(skb)->frag_list) {
                struct sk_buff *list = skb_shinfo(skb)->frag_list;
 
                for (; list; list = list->next) {
-                       int end;
-
-                       BUG_TRAP(start <= offset + len);
+                       BUG_TRAP(len >= 0);
 
-                       end = start + list->len;
+                       end = offset + list->len;
                        if ((copy = end - offset) > 0) {
                                if (copy > len)
                                        copy = len;
-                               if (skb_copy_datagram_iovec(list,
-                                                           offset - start,
-                                                           to, copy))
+                               if (skb_copy_datagram_iovec(list, 0, to, copy))
                                        goto fault;
                                if ((len -= copy) == 0)
                                        return 0;
                                offset += copy;
                        }
-                       start = end;
                }
        }
        if (!len)
@@ -321,11 +313,11 @@ fault:
 
 static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset,
                                      u8 __user *to, int len,
-                                     unsigned int *csump)
+                                     __wsum *csump)
 {
-       int start = skb_headlen(skb);
+       int end = skb_headlen(skb);
        int pos = 0;
-       int i, copy = start - offset;
+       int i, copy = end - offset;
 
        /* Copy header. */
        if (copy > 0) {
@@ -344,13 +336,11 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset,
        }
 
        for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
-               int end;
+               BUG_TRAP(len >= 0);
 
-               BUG_TRAP(start <= offset + len);
-
-               end = start + skb_shinfo(skb)->frags[i].size;
+               end = offset + skb_shinfo(skb)->frags[i].size;
                if ((copy = end - offset) > 0) {
-                       unsigned int csum2;
+                       __wsum csum2;
                        int err = 0;
                        u8  *vaddr;
                        skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
@@ -360,8 +350,7 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset,
                                copy = len;
                        vaddr = kmap(page);
                        csum2 = csum_and_copy_to_user(vaddr +
-                                                       frag->page_offset +
-                                                       offset - start,
+                                                       frag->page_offset,
                                                      to, copy, 0, &err);
                        kunmap(page);
                        if (err)
@@ -373,24 +362,20 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset,
                        to += copy;
                        pos += copy;
                }
-               start = end;
        }
 
        if (skb_shinfo(skb)->frag_list) {
                struct sk_buff *list = skb_shinfo(skb)->frag_list;
 
                for (; list; list=list->next) {
-                       int end;
-
-                       BUG_TRAP(start <= offset + len);
+                       BUG_TRAP(len >= 0);
 
-                       end = start + list->len;
+                       end = offset + list->len;
                        if ((copy = end - offset) > 0) {
-                               unsigned int csum2 = 0;
+                               __wsum csum2 = 0;
                                if (copy > len)
                                        copy = len;
-                               if (skb_copy_and_csum_datagram(list,
-                                                              offset - start,
+                               if (skb_copy_and_csum_datagram(list, 0,
                                                               to, copy,
                                                               &csum2))
                                        goto fault;
@@ -401,7 +386,6 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset,
                                to += copy;
                                pos += copy;
                        }
-                       start = end;
                }
        }
        if (!len)
@@ -411,18 +395,24 @@ fault:
        return -EFAULT;
 }
 
-unsigned int __skb_checksum_complete(struct sk_buff *skb)
+__sum16 __skb_checksum_complete_head(struct sk_buff *skb, int len)
 {
-       unsigned int sum;
+       __sum16 sum;
 
-       sum = (u16)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum));
+       sum = csum_fold(skb_checksum(skb, 0, len, skb->csum));
        if (likely(!sum)) {
-               if (unlikely(skb->ip_summed == CHECKSUM_HW))
+               if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE))
                        netdev_rx_csum_fault(skb->dev);
                skb->ip_summed = CHECKSUM_UNNECESSARY;
        }
        return sum;
 }
+EXPORT_SYMBOL(__skb_checksum_complete_head);
+
+__sum16 __skb_checksum_complete(struct sk_buff *skb)
+{
+       return __skb_checksum_complete_head(skb, skb->len);
+}
 EXPORT_SYMBOL(__skb_checksum_complete);
 
 /**
@@ -430,7 +420,7 @@ EXPORT_SYMBOL(__skb_checksum_complete);
  *     @skb: skbuff
  *     @hlen: hardware length
  *     @iov: io vector
- * 
+ *
  *     Caller _must_ check that skb will fit to this iovec.
  *
  *     Returns: 0       - success.
@@ -441,7 +431,7 @@ EXPORT_SYMBOL(__skb_checksum_complete);
 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
                                     int hlen, struct iovec *iov)
 {
-       unsigned int csum;
+       __wsum csum;
        int chunk = skb->len - hlen;
 
        /* Skip filled elements.
@@ -460,9 +450,9 @@ int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
                if (skb_copy_and_csum_datagram(skb, hlen, iov->iov_base,
                                               chunk, &csum))
                        goto fault;
-               if ((unsigned short)csum_fold(csum))
+               if (csum_fold(csum))
                        goto csum_error;
-               if (unlikely(skb->ip_summed == CHECKSUM_HW))
+               if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE))
                        netdev_rx_csum_fault(skb->dev);
                iov->iov_len -= chunk;
                iov->iov_base += chunk;