The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Alan Cox <alan@linux.intel.com>
To: greg@kroah.com, linux-kernel@vger.kernel.org
Subject: [PATCH 10/12] moxa: Fix modem op locking
Date: Wed, 18 Nov 2009 14:16:46 +0000	[thread overview]
Message-ID: <20091118141639.3346.67675.stgit@localhost.localdomain> (raw)
In-Reply-To: <20091118141354.3346.16910.stgit@localhost.localdomain>

This is overkill and mostly not needed

Signed-off-by: Alan Cox <alan@linux.intel.com>
---

 drivers/char/moxa.c |   25 ++++++++++---------------
 1 files changed, 10 insertions(+), 15 deletions(-)


diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index b640409..f9816e6 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -139,7 +139,7 @@ struct moxa_port {
 	int cflag;
 	unsigned long statusflags;
 
-	u8 DCDState;
+	u8 DCDState;		/* Protected by the port lock */
 	u8 lineCtrl;
 	u8 lowChkFlag;
 };
@@ -1141,9 +1141,9 @@ static int moxa_carrier_raised(struct tty_port *port)
 	struct moxa_port *ch = container_of(port, struct moxa_port, port);
 	int dcd;
 
-	spin_lock_bh(&moxa_lock);
+	spin_lock_irq(&port->lock);
 	dcd = ch->DCDState;
-	spin_unlock_bh(&moxa_lock);
+	spin_unlock_irq(&port->lock);
 	return dcd;
 }
 
@@ -1267,16 +1267,9 @@ static int moxa_chars_in_buffer(struct tty_struct *tty)
 
 static int moxa_tiocmget(struct tty_struct *tty, struct file *file)
 {
-	struct moxa_port *ch;
+	struct moxa_port *ch = tty->driver_data;
 	int flag = 0, dtr, rts;
 
-	mutex_lock(&moxa_openlock);
-	ch = tty->driver_data;
-	if (!ch) {
-		mutex_unlock(&moxa_openlock);
-		return -EINVAL;
-	}
-
 	MoxaPortGetLineOut(ch, &dtr, &rts);
 	if (dtr)
 		flag |= TIOCM_DTR;
@@ -1289,7 +1282,6 @@ static int moxa_tiocmget(struct tty_struct *tty, struct file *file)
 		flag |= TIOCM_DSR;
 	if (dtr & 4)
 		flag |= TIOCM_CD;
-	mutex_unlock(&moxa_openlock);
 	return flag;
 }
 
@@ -1368,15 +1360,20 @@ static void moxa_hangup(struct tty_struct *tty)
 static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
 {
 	struct tty_struct *tty;
+	unsigned long flags;
 	dcd = !!dcd;
 
+	spin_lock_irqsave(&p->port.lock, flags);
 	if (dcd != p->DCDState) {
+        	p->DCDState = dcd;
+        	spin_unlock_irqrestore(&p->port.lock, flags);
 		tty = tty_port_tty_get(&p->port);
 		if (tty && C_CLOCAL(tty) && !dcd)
 			tty_hangup(tty);
 		tty_kref_put(tty);
 	}
-	p->DCDState = dcd;
+	else
+		spin_unlock_irqrestore(&p->port.lock, flags);
 }
 
 static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
@@ -1878,9 +1875,7 @@ static int MoxaPortLineStatus(struct moxa_port *port)
 	val &= 0x0B;
 	if (val & 8)
 		val |= 4;
-	spin_lock_bh(&moxa_lock);
 	moxa_new_dcdstate(port, val & 8);
-	spin_unlock_bh(&moxa_lock);
 	val &= 7;
 	return val;
 }


  parent reply	other threads:[~2009-11-18 14:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-18 14:14 [PATCH 00/12] Series short description Alan Cox
2009-11-18 14:14 ` [PATCH 01/12] isicom: switch to the new tty_port_open helper Alan Cox
2009-11-18 14:14 ` [PATCH 02/12] isicom: sort out the board init logic Alan Cox
2009-11-18 14:15 ` [PATCH 03/12] mxser: use the tty_port_open method Alan Cox
2009-11-18 14:15 ` [PATCH 04/12] mxser: Use the new locking rules to fix setserial properly Alan Cox
2009-11-20 12:08   ` Dan Carpenter
2009-11-18 14:15 ` [PATCH 05/12] isicom: fix deadlock on shutdown Alan Cox
2009-11-18 14:15 ` [PATCH 06/12] moxa: Use more tty_port ops Alan Cox
2009-11-18 14:15 ` [PATCH 07/12] moxa: rework the locking a bit Alan Cox
2009-11-18 14:16 ` [PATCH 08/12] Locking clean up Alan Cox
2009-11-18 14:16 ` [PATCH 09/12] moxa: Kill off the throttle method Alan Cox
2009-11-18 14:16 ` Alan Cox [this message]
2009-11-18 14:16 ` [PATCH 11/12] moxa: Kill the use of lock_kernel Alan Cox
2009-11-18 14:17 ` [PATCH 12/12] moxa: split open lock Alan Cox

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=20091118141639.3346.67675.stgit@localhost.localdomain \
    --to=alan@linux.intel.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@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