public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Zhang, Yanmin" <yanmin_zhang@linux.intel.com>
To: linux-kernel@vger.kernel.org, xinhuix.pan@intel.com,
	gregkh@linuxfoundation.org, alan@linux.intel.com
Subject: [PATCH V2 2/3] cdc-acm: call usb_autopm_get_interface_upgrade in acm_tty_write
Date: Wed, 27 May 2015 10:49:48 +0800	[thread overview]
Message-ID: <556530CC.90906@linux.intel.com> (raw)

acm device might be used as ldisc device by n_gsm driver.
gsmtty_write and other gsm functions calls acm_tty_write
indirectly while they holds spinlocks.

Meanwhile, application might access ACM tty device directly.

Here we choose to call usb_autopm_get_interface_upgrade instead of
usb_autopm_get_interface_async to make sure above 2 scenarios can
work well.

Signed-off-by: Zhang Yanmin <yanmin.zhang@intel.com>

---

 drivers/usb/class/cdc-acm.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 5c8f581..6ad85a3 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -689,10 +689,15 @@ static int acm_tty_write(struct tty_struct *tty,
 
     dev_vdbg(&acm->data->dev, "%s - count %d\n", __func__, count);
 
+    stat = usb_autopm_get_interface_upgrade(acm->control);
+    if (stat)
+        return stat;
+
     spin_lock_irqsave(&acm->write_lock, flags);
     wbn = acm_wb_alloc(acm);
     if (wbn < 0) {
         spin_unlock_irqrestore(&acm->write_lock, flags);
+        usb_autopm_put_interface(acm->control);
         return 0;
     }
     wb = &acm->wb[wbn];
@@ -700,6 +705,7 @@ static int acm_tty_write(struct tty_struct *tty,
     if (!acm->dev) {
         wb->use = 0;
         spin_unlock_irqrestore(&acm->write_lock, flags);
+        usb_autopm_put_interface(acm->control);
         return -ENODEV;
     }
 
@@ -708,13 +714,6 @@ static int acm_tty_write(struct tty_struct *tty,
     memcpy(wb->buf, buf, count);
     wb->len = count;
 
-    stat = usb_autopm_get_interface_async(acm->control);
-    if (stat) {
-        wb->use = 0;
-        spin_unlock_irqrestore(&acm->write_lock, flags);
-        return stat;
-    }
-
     if (acm->susp_count) {
         usb_anchor_urb(wb->urb, &acm->delayed);
         spin_unlock_irqrestore(&acm->write_lock, flags);
-- 
1.9.1


                 reply	other threads:[~2015-05-27  2:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=556530CC.90906@linux.intel.com \
    --to=yanmin_zhang@linux.intel.com \
    --cc=alan@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xinhuix.pan@intel.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