linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
To: linux-usb@vger.kernel.org
Cc: Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Ladislav Michl <ladis@linux-mips.org>
Subject: [PATCH v4 1/6] usb: gadget: u_serial: add missing port entry locking
Date: Mon, 22 Jul 2019 17:14:38 +0200	[thread overview]
Message-ID: <136348ea5b8eaee8d45fb4beb9b15c832243bd5b.1563808218.git.mirq-linux@rere.qmqm.pl> (raw)
In-Reply-To: <cover.1563808218.git.mirq-linux@rere.qmqm.pl>

gserial_alloc_line() misses locking (for a release barrier) while
resetting port entry on TTY allocation failure. Fix this.

Cc: stable@vger.kernel.org
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Ladislav Michl <ladis@linux-mips.org>

---
  v4: no changes
  v3: cc-stable
  v2: no changes

---
 drivers/usb/gadget/function/u_serial.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index 65f634ec7fc2..bb1e2e1d0076 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -1239,8 +1239,10 @@ int gserial_alloc_line(unsigned char *line_num)
 				__func__, port_num, PTR_ERR(tty_dev));
 
 		ret = PTR_ERR(tty_dev);
+		mutex_lock(&ports[port_num].lock);
 		port = ports[port_num].port;
 		ports[port_num].port = NULL;
+		mutex_unlock(&ports[port_num].lock);
 		gserial_free_port(port);
 		goto err;
 	}
-- 
2.20.1


  parent reply	other threads:[~2019-07-22 15:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-22 15:14 [PATCH v4 0/6] usb: gadget: u_serial: console improvements Michał Mirosław
2019-07-22 15:14 ` [PATCH v4 2/6] usb: gadget: u_serial: reimplement console support Michał Mirosław
2019-07-22 15:14 ` [PATCH v4 3/6] usb: gadget: u_serial: make OBEX port not a console Michał Mirosław
2019-07-22 15:14 ` Michał Mirosław [this message]
2019-07-22 15:14 ` [PATCH v4 5/6] usb: gadget: u_serial: diagnose missed console messages Michał Mirosław
2019-07-22 15:14 ` [PATCH v4 6/6] USB: gadget: legacy/serial: allow dynamic removal Michał Mirosław
2019-07-22 15:14 ` [PATCH v4 4/6] usb: gadget: u_serial: allow more console gadget ports Michał Mirosław

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=136348ea5b8eaee8d45fb4beb9b15c832243bd5b.1563808218.git.mirq-linux@rere.qmqm.pl \
    --to=mirq-linux@rere.qmqm.pl \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ladis@linux-mips.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;
as well as URLs for NNTP newsgroup(s).