mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Harish Jenny K N <harish_kandiga@mentor.com>
To: Felipe Balbi <balbi@kernel.org>
Cc: <linux-usb@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	<linux-kernel@vger.kernel.org>,
	Jim Baxter <jim_baxter@mentor.com>, <harish_kandiga@mentor.com>,
	<tpolle@de.adit-jv.com>
Subject: [PATCH v1 3/3] usb: gadget: NCM: differentiate consumed packets from dropped packets
Date: Thu, 15 Sep 2016 16:22:58 +0200	[thread overview]
Message-ID: <1473949378-13692-4-git-send-email-harish_kandiga@mentor.com> (raw)
In-Reply-To: <1473949378-13692-1-git-send-email-harish_kandiga@mentor.com>

From: Torsten Polle <tpolle@de.adit-jv.com>

dev_kfree_skb_any() is used to free packets that are dropped by the
network stack. Therefore the function should not be used for packets
that have been successfully processed by the network stack. Instead
dev_consume_skb_any() has to be used for such consumed packets.

This separation helps to identify dropped packets.

Signed-off-by: Torsten Polle <tpolle@de.adit-jv.com>
Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
---
 drivers/usb/gadget/function/f_ncm.c   |    8 ++++----
 drivers/usb/gadget/function/u_ether.c |    3 ++-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c
index b6771ad..e8008fa 100644
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -998,7 +998,7 @@ static struct sk_buff *package_for_tx(struct f_ncm *ncm)
 	/* Merge the skbs */
 	swap(skb2, ncm->skb_tx_data);
 	if (ncm->skb_tx_data) {
-		dev_kfree_skb_any(ncm->skb_tx_data);
+		dev_consume_skb_any(ncm->skb_tx_data);
 		ncm->skb_tx_data = NULL;
 	}
 
@@ -1009,7 +1009,7 @@ static struct sk_buff *package_for_tx(struct f_ncm *ncm)
 	/* Copy NTB across. */
 	ntb_iter = (void *) skb_put(skb2, ncm->skb_tx_ndp->len);
 	memcpy(ntb_iter, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len);
-	dev_kfree_skb_any(ncm->skb_tx_ndp);
+	dev_consume_skb_any(ncm->skb_tx_ndp);
 	ncm->skb_tx_ndp = NULL;
 
 	/* Insert zero'd datagram. */
@@ -1136,7 +1136,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 		memset(ntb_data, 0, dgram_pad);
 		ntb_data = (void *) skb_put(ncm->skb_tx_data, skb->len);
 		memcpy(ntb_data, skb->data, skb->len);
-		dev_kfree_skb_any(skb);
+		dev_consume_skb_any(skb);
 		skb = NULL;
 
 	} else if (ncm->skb_tx_data && ncm->timer_force_tx) {
@@ -1332,7 +1332,7 @@ static int ncm_unwrap_ntb(struct gether *port,
 		} while (ndp_len > 2 * (opts->dgram_item_len * 2));
 	} while (ndp_index);
 
-	dev_kfree_skb_any(skb);
+	dev_consume_skb_any(skb);
 
 	VDBG(port->func.config->cdev,
 	     "Parsed NTB with %d frames\n", dgram_counter);
diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index d8593c7..8a6be06 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -455,16 +455,17 @@ static void tx_complete(struct usb_ep *ep, struct usb_request *req)
 		/* FALLTHROUGH */
 	case -ECONNRESET:		/* unlink */
 	case -ESHUTDOWN:		/* disconnect etc */
+		dev_kfree_skb_any(skb);
 		break;
 	case 0:
 		dev->net->stats.tx_bytes += skb->len;
+		dev_consume_skb_any(skb);
 	}
 	dev->net->stats.tx_packets++;
 
 	spin_lock(&dev->req_lock);
 	list_add(&req->list, &dev->tx_reqs);
 	spin_unlock(&dev->req_lock);
-	dev_kfree_skb_any(skb);
 
 	atomic_dec(&dev->tx_qlen);
 	if (netif_carrier_ok(dev->net))
-- 
1.7.9.5

  parent reply	other threads:[~2016-09-15 14:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Harish Jenny K N <harish_kandiga@mentor.com>
2016-09-08  9:18 ` [PATCH v1 0/1] usb: gadget: f_fs: Stop ffs_closed NULL pointers Harish Jenny K N
2016-09-08  9:18   ` [PATCH v1 1/1] " Harish Jenny K N
2016-09-09  9:30 ` [PATCH v1 0/2] usb: gadget: NCM: NULL pointer dereference in eth_start_xmit Harish Jenny K N
2016-09-09  9:30   ` [PATCH v1 1/2] usb: gadget: u_ether: fix another dereference after null check Harish Jenny K N
2016-09-10  3:39     ` Peter Chen
2016-09-09  9:30   ` [PATCH v1 2/2] usb: gadget: NCM: Protect dev->port_usb using dev->lock Harish Jenny K N
2016-09-15 14:22 ` [PATCH v1 0/3] Usb gadget ncm code cleanup Harish Jenny K N
2016-09-15 14:22   ` [PATCH v1 1/3] usb: gadget: NCM: link socket buffers to the device for tx packets Harish Jenny K N
2016-09-15 14:22   ` [PATCH v1 2/3] usb: gadget: NCM: link socket buffers to the device for received packets Harish Jenny K N
2016-09-15 18:35     ` Yauheni Kaliuta
2016-09-16  9:54       ` Harish Jenny K N
2016-09-15 14:22   ` Harish Jenny K N [this message]
2016-09-19  8:05 ` [PATCH v2 0/3] Usb gadget ncm code cleanup Harish Jenny K N
2016-09-19  8:05   ` [PATCH v2 1/3] usb: gadget: NCM: link socket buffers to the device for tx packets Harish Jenny K N
2016-09-19  8:05   ` [PATCH v2 2/3] usb: gadget: u_ether: link socket buffers to the device for received packets Harish Jenny K N
2016-09-19  8:05   ` [PATCH v2 3/3] usb: gadget: NCM: differentiate consumed packets from dropped packets Harish Jenny K N

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=1473949378-13692-4-git-send-email-harish_kandiga@mentor.com \
    --to=harish_kandiga@mentor.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jim_baxter@mentor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=tpolle@de.adit-jv.com \
    /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

all inboxes | Powered by JetHome®