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>
Subject: [PATCH v1 2/2] usb: gadget: NCM: Protect dev->port_usb using dev->lock
Date: Fri, 9 Sep 2016 11:30:42 +0200	[thread overview]
Message-ID: <1473413442-2377-3-git-send-email-harish_kandiga@mentor.com> (raw)
In-Reply-To: <1473413442-2377-1-git-send-email-harish_kandiga@mentor.com>

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

  parent reply	other threads:[~2016-09-09  9:31 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   ` Harish Jenny K N [this message]
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

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=1473413442-2377-3-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 \
    /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®