All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/1] usb: gadget: f_fs: Stop ffs_closed NULL pointers
       [not found] <Harish Jenny K N <harish_kandiga@mentor.com>
@ 2016-09-08  9:18 ` 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
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: Harish Jenny K N @ 2016-09-08  9:18 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: linux-usb, Greg Kroah-Hartman, linux-kernel, Jim Baxter

This patchset fixes the crash in ffs_closed during a disconnect 
of a USB composite FFS session. The issue was caused by the use 
of an outdated pointer in ffs_closed which had been deleted and 
not Nulled.

Note: Testing has only been done on an ARM i.MX6 based platform.

Jim Baxter (1):
  usb: gadget: f_fs: Stop ffs_closed NULL pointers.

 drivers/usb/gadget/function/f_fs.c |    5 +++++
 1 file changed, 5 insertions(+)

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v1 1/1] usb: gadget: f_fs: Stop ffs_closed NULL pointers.
  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   ` Harish Jenny K N
  0 siblings, 0 replies; 16+ messages in thread
From: Harish Jenny K N @ 2016-09-08  9:18 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: linux-usb, Greg Kroah-Hartman, linux-kernel, Jim Baxter

From: Jim Baxter <jim_baxter@mentor.com>

The struct ffs_data::private_data has a pointer to
ffs_dev stored in it during the ffs_fs_mount() function
however it is not cleared when the ffs_dev is freed
later which causes the ffs_closed function to crash
with "Unable to handle kernel NULL pointer dereference"
error when using the data in ffs_data::private_data.

This clears this pointer during the ffs_free_dev clean
up function.

Signed-off-by: Jim Baxter <jim_baxter@mentor.com>
Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
---
 drivers/usb/gadget/function/f_fs.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 5c8429f..b309650 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -3470,6 +3470,11 @@ static void _ffs_free_dev(struct ffs_dev *dev)
 	list_del(&dev->entry);
 	if (dev->name_allocated)
 		kfree(dev->name);
+
+	/* Clear the private_data pointer to stop incorrect dev access */
+	if (dev->ffs_data)
+		dev->ffs_data->private_data = NULL;
+
 	kfree(dev);
 	if (list_empty(&ffs_devices))
 		functionfs_cleanup();
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 0/2] usb: gadget: NCM: NULL pointer dereference in eth_start_xmit
       [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-09  9:30 ` 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-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-19  8:05 ` [PATCH v2 0/3] Usb gadget ncm code cleanup Harish Jenny K N
  3 siblings, 2 replies; 16+ messages in thread
From: Harish Jenny K N @ 2016-09-09  9:30 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: linux-usb, Greg Kroah-Hartman, linux-kernel, Jim Baxter, harish_kandiga

This patchset incorporates findings from https://lkml.org/lkml/2016/4/25/690

When submitting patch https://lkml.org/lkml/2016/4/25/594, few observations from
Alan from https://lkml.org/lkml/2016/4/25/690 needed to be incorporated.

We find that the changes are already taken to linux-next repo by another commit 
88c09eacf560c3303d0ee8cf91b8b7ff7f000350. 

Hence this  patchset only adds the remaining findings. 

Harish Jenny K N (2):
  usb: gadget: u_ether: fix another dereference after null check
  usb: gadget: NCM: Protect dev->port_usb using dev->lock

 drivers/usb/gadget/function/u_ether.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v1 1/2] usb: gadget: u_ether: fix another dereference after null check
  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   ` 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
  1 sibling, 1 reply; 16+ messages in thread
From: Harish Jenny K N @ 2016-09-09  9:30 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: linux-usb, Greg Kroah-Hartman, linux-kernel, Jim Baxter, harish_kandiga

dev->port_usb is checked for null pointer previously, so dev->port_usb
might be null during no zlp check, fix it by adding null pointer check.

Acked-by: Jim Baxter <jim_baxter@mentor.com>
Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
---
 drivers/usb/gadget/function/u_ether.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index 3be4b93..9c8c9ed 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -571,7 +571,8 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
 	req->complete = tx_complete;
 
 	/* NCM requires no zlp if transfer is dwNtbInMaxSize */
-	if (dev->port_usb->is_fixed &&
+	if (dev->port_usb &&
+	    dev->port_usb->is_fixed &&
 	    length == dev->port_usb->fixed_in_len &&
 	    (length % in->maxpacket) == 0)
 		req->zero = 0;
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 2/2] usb: gadget: NCM: Protect dev->port_usb using dev->lock
  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-09  9:30   ` Harish Jenny K N
  1 sibling, 0 replies; 16+ messages in thread
From: Harish Jenny K N @ 2016-09-09  9:30 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: linux-usb, Greg Kroah-Hartman, linux-kernel, Jim Baxter, harish_kandiga

This commit incorporates findings from
https://lkml.org/lkml/2016/4/25/594

The function has been modified to make sure we hold
the dev lock when accessing the net device pointer.

Acked-by: Jim Baxter <jim_baxter@mentor.com>
Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
---
 drivers/usb/gadget/function/u_ether.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index 9c8c9ed..8cb0803 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -553,14 +553,16 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
 		spin_lock_irqsave(&dev->lock, flags);
 		if (dev->port_usb)
 			skb = dev->wrap(dev->port_usb, skb);
-		spin_unlock_irqrestore(&dev->lock, flags);
 		if (!skb) {
 			/* Multi frame CDC protocols may store the frame for
 			 * later which is not a dropped frame.
 			 */
 			if (dev->port_usb &&
-					dev->port_usb->supports_multi_frame)
+					dev->port_usb->supports_multi_frame) {
+				spin_unlock_irqrestore(&dev->lock, flags);
 				goto multiframe;
+			}
+			spin_unlock_irqrestore(&dev->lock, flags);
 			goto drop;
 		}
 	}
@@ -578,6 +580,7 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
 		req->zero = 0;
 	else
 		req->zero = 1;
+	spin_unlock_irqrestore(&dev->lock, flags);
 
 	/* use zlp framing on tx for strict CDC-Ether conformance,
 	 * though any robust network rx path ignores extra padding.
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v1 1/2] usb: gadget: u_ether: fix another dereference after null check
  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
  0 siblings, 0 replies; 16+ messages in thread
From: Peter Chen @ 2016-09-10  3:39 UTC (permalink / raw)
  To: Harish Jenny K N
  Cc: Felipe Balbi, linux-usb, Greg Kroah-Hartman, linux-kernel, Jim Baxter

On Fri, Sep 09, 2016 at 11:30:41AM +0200, Harish Jenny K N wrote:
> dev->port_usb is checked for null pointer previously, so dev->port_usb
> might be null during no zlp check, fix it by adding null pointer check.
> 
> Acked-by: Jim Baxter <jim_baxter@mentor.com>
> Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
> ---
>  drivers/usb/gadget/function/u_ether.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
> index 3be4b93..9c8c9ed 100644
> --- a/drivers/usb/gadget/function/u_ether.c
> +++ b/drivers/usb/gadget/function/u_ether.c
> @@ -571,7 +571,8 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
>  	req->complete = tx_complete;
>  
>  	/* NCM requires no zlp if transfer is dwNtbInMaxSize */
> -	if (dev->port_usb->is_fixed &&
> +	if (dev->port_usb &&
> +	    dev->port_usb->is_fixed &&
>  	    length == dev->port_usb->fixed_in_len &&
>  	    (length % in->maxpacket) == 0)
>  		req->zero = 0;

Acked-by: Peter Chen <peter.chen@nxp.com>

-- 

Best Regards,
Peter Chen

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v1 0/3] Usb gadget ncm code cleanup
       [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-09  9:30 ` [PATCH v1 0/2] usb: gadget: NCM: NULL pointer dereference in eth_start_xmit Harish Jenny K N
@ 2016-09-15 14:22 ` 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
                     ` (2 more replies)
  2016-09-19  8:05 ` [PATCH v2 0/3] Usb gadget ncm code cleanup Harish Jenny K N
  3 siblings, 3 replies; 16+ messages in thread
From: Harish Jenny K N @ 2016-09-15 14:22 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: linux-usb, Greg Kroah-Hartman, linux-kernel, Jim Baxter,
	harish_kandiga, tpolle

This patchset consists of some code cleanup in usb gadget ncm code.

Note: Testing has only been done on an ARM i.MX6 based platform.

Torsten Polle (3):
  usb: gadget: NCM: link socket buffers to the device for tx packets
  usb: gadget: NCM: link socket buffers to the device for received
    packets
  usb: gadget: NCM: differentiate consumed packets from dropped packets

 drivers/usb/gadget/function/f_ncm.c   |   11 +++++++----
 drivers/usb/gadget/function/u_ether.c |    5 +++--
 2 files changed, 10 insertions(+), 6 deletions(-)

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v1 1/3] usb: gadget: NCM: link socket buffers to the device for tx packets
  2016-09-15 14:22 ` [PATCH v1 0/3] Usb gadget ncm code cleanup Harish Jenny K N
@ 2016-09-15 14:22   ` 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 14:22   ` [PATCH v1 3/3] usb: gadget: NCM: differentiate consumed packets from dropped packets Harish Jenny K N
  2 siblings, 0 replies; 16+ messages in thread
From: Harish Jenny K N @ 2016-09-15 14:22 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: linux-usb, Greg Kroah-Hartman, linux-kernel, Jim Baxter,
	harish_kandiga, tpolle

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

Socket buffers should be linked to the (network) device that allocated
the buffers.

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 |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c
index 6396037..b6771ad 100644
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -1078,6 +1078,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 			if (!ncm->skb_tx_data)
 				goto err;
 
+			ncm->skb_tx_data->dev = ncm->netdev;
 			ntb_data = (void *) skb_put(ncm->skb_tx_data, ncb_len);
 			memset(ntb_data, 0, ncb_len);
 			/* dwSignature */
@@ -1096,6 +1097,8 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 						    GFP_ATOMIC);
 			if (!ncm->skb_tx_ndp)
 				goto err;
+
+			ncm->skb_tx_ndp->dev = ncm->netdev;
 			ntb_ndp = (void *) skb_put(ncm->skb_tx_ndp,
 						    opts->ndp_size);
 			memset(ntb_ndp, 0, ncb_len);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 2/3] usb: gadget: NCM: link socket buffers to the device for received packets
  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   ` Harish Jenny K N
  2016-09-15 18:35     ` Yauheni Kaliuta
  2016-09-15 14:22   ` [PATCH v1 3/3] usb: gadget: NCM: differentiate consumed packets from dropped packets Harish Jenny K N
  2 siblings, 1 reply; 16+ messages in thread
From: Harish Jenny K N @ 2016-09-15 14:22 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: linux-usb, Greg Kroah-Hartman, linux-kernel, Jim Baxter,
	harish_kandiga, tpolle

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

Socket buffers should be linked to the (network) device that allocated
the buffers. __netdev_alloc_skb performs this task.

Signed-off-by: Torsten Polle <tpolle@de.adit-jv.com>
Signed-off-by: Jim Baxter <jim_baxter@mentor.com>
Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
---
 drivers/usb/gadget/function/u_ether.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index 8cb0803..d8593c7 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -224,7 +224,7 @@ static void defer_kevent(struct eth_dev *dev, int flag)
 	if (dev->port_usb->is_fixed)
 		size = max_t(size_t, size, dev->port_usb->fixed_out_len);
 
-	skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags);
+	skb = __netdev_alloc_skb(dev->net, size + NET_IP_ALIGN, gfp_flags);
 	if (skb == NULL) {
 		DBG(dev, "no rx skb\n");
 		goto enomem;
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 3/3] usb: gadget: NCM: differentiate consumed packets from dropped packets
  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 14:22   ` Harish Jenny K N
  2 siblings, 0 replies; 16+ messages in thread
From: Harish Jenny K N @ 2016-09-15 14:22 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: linux-usb, Greg Kroah-Hartman, linux-kernel, Jim Baxter,
	harish_kandiga, tpolle

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

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v1 2/3] usb: gadget: NCM: link socket buffers to the device for received packets
  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
  0 siblings, 1 reply; 16+ messages in thread
From: Yauheni Kaliuta @ 2016-09-15 18:35 UTC (permalink / raw)
  To: Harish Jenny K N
  Cc: Felipe Balbi, linux-usb, Greg Kroah-Hartman, linux-kernel,
	Jim Baxter, tpolle

Hi, Harish!

>>>>> On Thu, 15 Sep 2016 16:22:57 +0200, Harish Jenny K N  wrote:

 > diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
                                           ^^^^^^^
Is subject a bit misleading, it's more generic, then NCM?

-- 
WBR,
Yauheni Kaliuta

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v1 2/3] usb: gadget: NCM: link socket buffers to the device for received packets
  2016-09-15 18:35     ` Yauheni Kaliuta
@ 2016-09-16  9:54       ` Harish Jenny K N
  0 siblings, 0 replies; 16+ messages in thread
From: Harish Jenny K N @ 2016-09-16  9:54 UTC (permalink / raw)
  To: Yauheni Kaliuta
  Cc: Felipe Balbi, linux-usb, Greg Kroah-Hartman, linux-kernel,
	Jim Baxter, tpolle


>>>>> On Thursday 15 September 2016 08:35 PM, Yauheni Kaliuta wrote:

>Is subject a bit misleading, it's more generic, then NCM?

Agreed. I will submit v2 patchset.

WBR,
Harish Jenny K N

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 0/3] Usb gadget ncm code cleanup
       [not found] <Harish Jenny K N <harish_kandiga@mentor.com>
                   ` (2 preceding siblings ...)
  2016-09-15 14:22 ` [PATCH v1 0/3] Usb gadget ncm code cleanup Harish Jenny K N
@ 2016-09-19  8:05 ` 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
                     ` (2 more replies)
  3 siblings, 3 replies; 16+ messages in thread
From: Harish Jenny K N @ 2016-09-19  8:05 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: linux-usb, Greg Kroah-Hartman, linux-kernel, Jim Baxter,
	harish_kandiga, tpolle

This patchset consists of some code cleanup in usb gadget ncm code.

Note: Testing has only been done on an ARM i.MX6 based platform.

---
Change from v1 to v2
Subject line changed on Patch 2.

Torsten Polle (3):
  usb: gadget: NCM: link socket buffers to the device for tx packets
  usb: gadget: u_ether: link socket buffers to the device for received
    packets
  usb: gadget: NCM: differentiate consumed packets from dropped packets

 drivers/usb/gadget/function/f_ncm.c   |   11 +++++++----
 drivers/usb/gadget/function/u_ether.c |    5 +++--
 2 files changed, 10 insertions(+), 6 deletions(-)

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 1/3] usb: gadget: NCM: link socket buffers to the device for tx packets
  2016-09-19  8:05 ` [PATCH v2 0/3] Usb gadget ncm code cleanup Harish Jenny K N
@ 2016-09-19  8:05   ` 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
  2 siblings, 0 replies; 16+ messages in thread
From: Harish Jenny K N @ 2016-09-19  8:05 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: linux-usb, Greg Kroah-Hartman, linux-kernel, Jim Baxter,
	harish_kandiga, tpolle

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

Socket buffers should be linked to the (network) device that allocated
the buffers.

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 |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c
index 6396037..b6771ad 100644
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -1078,6 +1078,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 			if (!ncm->skb_tx_data)
 				goto err;
 
+			ncm->skb_tx_data->dev = ncm->netdev;
 			ntb_data = (void *) skb_put(ncm->skb_tx_data, ncb_len);
 			memset(ntb_data, 0, ncb_len);
 			/* dwSignature */
@@ -1096,6 +1097,8 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 						    GFP_ATOMIC);
 			if (!ncm->skb_tx_ndp)
 				goto err;
+
+			ncm->skb_tx_ndp->dev = ncm->netdev;
 			ntb_ndp = (void *) skb_put(ncm->skb_tx_ndp,
 						    opts->ndp_size);
 			memset(ntb_ndp, 0, ncb_len);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 2/3] usb: gadget: u_ether: link socket buffers to the device for received packets
  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   ` 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
  2 siblings, 0 replies; 16+ messages in thread
From: Harish Jenny K N @ 2016-09-19  8:05 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: linux-usb, Greg Kroah-Hartman, linux-kernel, Jim Baxter,
	harish_kandiga, tpolle

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

Socket buffers should be linked to the (network) device that allocated
the buffers. __netdev_alloc_skb performs this task.

Signed-off-by: Torsten Polle <tpolle@de.adit-jv.com>
Signed-off-by: Jim Baxter <jim_baxter@mentor.com>
Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
---
Change from v1 to v2
Subject line changed

 drivers/usb/gadget/function/u_ether.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index 8cb0803..d8593c7 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -224,7 +224,7 @@ static void defer_kevent(struct eth_dev *dev, int flag)
 	if (dev->port_usb->is_fixed)
 		size = max_t(size_t, size, dev->port_usb->fixed_out_len);
 
-	skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags);
+	skb = __netdev_alloc_skb(dev->net, size + NET_IP_ALIGN, gfp_flags);
 	if (skb == NULL) {
 		DBG(dev, "no rx skb\n");
 		goto enomem;
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 3/3] usb: gadget: NCM: differentiate consumed packets from dropped packets
  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   ` Harish Jenny K N
  2 siblings, 0 replies; 16+ messages in thread
From: Harish Jenny K N @ 2016-09-19  8:05 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: linux-usb, Greg Kroah-Hartman, linux-kernel, Jim Baxter,
	harish_kandiga, tpolle

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

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-09-19  8:06 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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   ` [PATCH v1 3/3] usb: gadget: NCM: differentiate consumed packets from dropped packets Harish Jenny K N
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.