asix: Tidy-up 32-bit header word synchronisation
authorDean Jenkins <Dean_Jenkins@mentor.com>
Fri, 2 Oct 2015 13:29:05 +0000 (14:29 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 5 Oct 2015 13:58:40 +0000 (06:58 -0700)
Tidy-up the Data header 32-bit word synchronisation logic in
asix_rx_fixup_internal() by removing redundant logic tests.

The code is looking at the following cases of the Data header
32-bit word that is present before each Ethernet frame:

a) all 32 bits of the Data header word are in the URB socket buffer
b) first 16 bits of the Data header word are at the end of the URB
   socket buffer
c) last 16 bits of the Data header word are at the start of the URB
   socket buffer eg. split_head = true

Note that the lifetime of rx->split_head exists outside of the
function call and is accessed per processing of each URB. Therefore,
split_head being true acts on the next URB to be processed.

To check for b) the offset will be 16 bits (2 bytes) from the end of
the buffer then indicate split_head is true.
To check for c) split_head must be true because the first 16 bits
have been found.
To check for a) else c)

Note that the || logic of the old code included the state
(skb->len - offset == sizeof(u16) && rx->split_head) which is not
possible because the split_head cannot be true whilst checking for b).
This is because the split_head indicates that the first 16 bits have
been found and that is not possible whilst checking for the first 16
bits. Therefore simplify the logic.

Signed-off-by: Dean Jenkins <Dean_Jenkins@mentor.com>
Signed-off-by: Mark Craske <Mark_Craske@mentor.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/usb/asix_common.c

index 2bd5bdda8c2ea9d927838b06fb1bbb17bef6fbba..89efd6ad9644f65ce0f902aa860279990fb5c444 100644 (file)
@@ -61,21 +61,19 @@ int asix_rx_fixup_internal(struct usbnet *dev, struct sk_buff *skb,
                unsigned char *data;
 
                if (!rx->remaining) {
-                       if ((skb->len - offset == sizeof(u16)) ||
-                           rx->split_head) {
-                               if(!rx->split_head) {
-                                       rx->header = get_unaligned_le16(
-                                                       skb->data + offset);
-                                       rx->split_head = true;
-                                       offset += sizeof(u16);
-                                       break;
-                               } else {
-                                       rx->header |= (get_unaligned_le16(
-                                                       skb->data + offset)
-                                                       << 16);
-                                       rx->split_head = false;
-                                       offset += sizeof(u16);
-                               }
+                       if (skb->len - offset == sizeof(u16)) {
+                               rx->header = get_unaligned_le16(
+                                               skb->data + offset);
+                               rx->split_head = true;
+                               offset += sizeof(u16);
+                               break;
+                       }
+
+                       if (rx->split_head == true) {
+                               rx->header |= (get_unaligned_le16(
+                                               skb->data + offset) << 16);
+                               rx->split_head = false;
+                               offset += sizeof(u16);
                        } else {
                                rx->header = get_unaligned_le32(skb->data +
                                                                offset);