Skip to content

Commit

Permalink
asix: Simplify asix_rx_fixup_internal() netdev alloc
Browse files Browse the repository at this point in the history
The code is checking that the Ethernet frame will fit into a
netdev allocated socket buffer within the constraints of MTU size,
Ethernet header length plus VLAN header length.

The original code was checking rx->remaining each loop of the while
loop that processes multiple Ethernet frames per URB and/or Ethernet
frames that span across URBs. rx->remaining decreases per while loop
so there is no point in potentially checking multiple times that the
Ethernet frame (remaining part) will fit into the netdev socket buffer.

The modification checks that the size of the Ethernet frame will fit
the netdev socket buffer before allocating the netdev socket buffer.
This avoids grabbing memory and then deciding that the Ethernet frame
is too big and then freeing the memory.

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>
  • Loading branch information
Dean Jenkins authored and David S. Miller committed Oct 5, 2015
1 parent 3bfc69a commit 9a5ccd8
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions drivers/net/usb/asix_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,17 @@ int asix_rx_fixup_internal(struct usbnet *dev, struct sk_buff *skb,
rx->header, offset);
return 0;
}
if (size > dev->net->mtu + ETH_HLEN + VLAN_HLEN) {
netdev_err(dev->net, "asix_rx_fixup() Bad RX Length %d\n",
size);
return 0;
}

rx->ax_skb = netdev_alloc_skb_ip_align(dev->net, size);
if (!rx->ax_skb)
return 0;
rx->remaining = size;
}

if (rx->remaining > dev->net->mtu + ETH_HLEN + VLAN_HLEN) {
netdev_err(dev->net, "asix_rx_fixup() Bad RX Length %d\n",
rx->remaining);
kfree_skb(rx->ax_skb);
rx->ax_skb = NULL;
rx->remaining = 0;
return 0;
rx->remaining = size;
}

if (rx->remaining > skb->len - offset) {
Expand Down

0 comments on commit 9a5ccd8

Please sign in to comment.