netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dean Jenkins <Dean_Jenkins@mentor.com>
To: <netdev@vger.kernel.org>
Cc: <linux-usb@vger.kernel.org>, <ben.hutchings@codethink.co.uk>,
	<davem@davemloft.net>, <bjorn@mork.no>, <linux@davidrobins.net>,
	Mark Craske <Mark_Craske@mentor.com>,
	Dean Jenkins <Dean_Jenkins@mentor.com>
Subject: [PATCH v1 3/5] asix: Simplify asix_rx_fixup_internal() netdev alloc
Date: Fri, 2 Oct 2015 14:29:06 +0100	[thread overview]
Message-ID: <1443792548-2025-4-git-send-email-Dean_Jenkins@mentor.com> (raw)
In-Reply-To: <1443792548-2025-1-git-send-email-Dean_Jenkins@mentor.com>

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>
---
 drivers/net/usb/asix_common.c |   16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c
index 89efd6a..6a8eddf 100644
--- a/drivers/net/usb/asix_common.c
+++ b/drivers/net/usb/asix_common.c
@@ -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) {
-- 
1.7.9.5

  reply	other threads:[~2015-10-02 13:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-02 13:29 [PATCH v2 0/5] Improve ASIX RX memory allocation error handling Dean Jenkins
2015-10-02 13:29 ` Dean Jenkins [this message]
2015-10-02 13:29 ` [PATCH v1 4/5] asix: On RX avoid creating bad Ethernet frames Dean Jenkins
     [not found] ` <1443792548-2025-1-git-send-email-Dean_Jenkins-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-10-02 13:29   ` [PATCH v1 1/5] asix: Rename remaining and size for clarity Dean Jenkins
2015-10-02 13:29   ` [PATCH v1 2/5] asix: Tidy-up 32-bit header word synchronisation Dean Jenkins
2015-10-02 13:29   ` [PATCH v1 5/5] asix: Continue processing URB if no RX netdev buffer Dean Jenkins
2015-10-05 13:59   ` [PATCH v2 0/5] Improve ASIX RX memory allocation error handling David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443792548-2025-4-git-send-email-Dean_Jenkins@mentor.com \
    --to=dean_jenkins@mentor.com \
    --cc=Mark_Craske@mentor.com \
    --cc=ben.hutchings@codethink.co.uk \
    --cc=bjorn@mork.no \
    --cc=davem@davemloft.net \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@davidrobins.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).