Commit a808ac0c authored by Alan Cox's avatar Alan Cox Committed by Greg Kroah-Hartman

tty: moxa: Locking clean up

- The open lock is needed to fix up the case of a board reset occuring during
  tty open but too early for a sane hangup response.
- The lock can however got for other cases
- Use the port mutex for get/setserial
- Fix up the confused lack of locking on the THROTTLE and other bits in the
  private flags. Just use set/test/clear bit and it covers the cases we need
Signed-off-by: default avatarAlan Cox <alan@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent f5c5a36d
...@@ -151,10 +151,10 @@ struct mon_str { ...@@ -151,10 +151,10 @@ struct mon_str {
}; };
/* statusflags */ /* statusflags */
#define TXSTOPPED 0x1 #define TXSTOPPED 1
#define LOWWAIT 0x2 #define LOWWAIT 2
#define EMPTYWAIT 0x4 #define EMPTYWAIT 3
#define THROTTLE 0x8 #define THROTTLE 4
#define SERIAL_DO_RESTART #define SERIAL_DO_RESTART
...@@ -235,6 +235,8 @@ static void MoxaSetFifo(struct moxa_port *port, int enable); ...@@ -235,6 +235,8 @@ static void MoxaSetFifo(struct moxa_port *port, int enable);
* I/O functions * I/O functions
*/ */
static DEFINE_SPINLOCK(moxafunc_lock);
static void moxa_wait_finish(void __iomem *ofsAddr) static void moxa_wait_finish(void __iomem *ofsAddr)
{ {
unsigned long end = jiffies + moxaFuncTout; unsigned long end = jiffies + moxaFuncTout;
...@@ -381,14 +383,14 @@ copy: ...@@ -381,14 +383,14 @@ copy:
break; break;
} }
case TIOCGSERIAL: case TIOCGSERIAL:
mutex_lock(&moxa_openlock); mutex_lock(&ch->port.mutex);
ret = moxa_get_serial_info(ch, argp); ret = moxa_get_serial_info(ch, argp);
mutex_unlock(&moxa_openlock); mutex_unlock(&ch->port.mutex);
break; break;
case TIOCSSERIAL: case TIOCSSERIAL:
mutex_lock(&moxa_openlock); mutex_lock(&ch->port.mutex);
ret = moxa_set_serial_info(ch, argp); ret = moxa_set_serial_info(ch, argp);
mutex_unlock(&moxa_openlock); mutex_unlock(&ch->port.mutex);
break; break;
default: default:
ret = -ENOIOCTLCMD; ret = -ENOIOCTLCMD;
...@@ -433,7 +435,6 @@ static const struct tty_port_operations moxa_port_ops = { ...@@ -433,7 +435,6 @@ static const struct tty_port_operations moxa_port_ops = {
static struct tty_driver *moxaDriver; static struct tty_driver *moxaDriver;
static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0); static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0);
static DEFINE_SPINLOCK(moxa_lock); static DEFINE_SPINLOCK(moxa_lock);
static DEFINE_SPINLOCK(moxafunc_lock);
/* /*
* HW init * HW init
...@@ -1208,9 +1209,7 @@ static void moxa_close(struct tty_struct *tty, struct file *filp) ...@@ -1208,9 +1209,7 @@ static void moxa_close(struct tty_struct *tty, struct file *filp)
{ {
struct moxa_port *ch = tty->driver_data; struct moxa_port *ch = tty->driver_data;
ch->cflag = tty->termios->c_cflag; ch->cflag = tty->termios->c_cflag;
mutex_lock(&moxa_openlock);
tty_port_close(&ch->port, tty, filp); tty_port_close(&ch->port, tty, filp);
mutex_unlock(&moxa_openlock);
} }
static int moxa_write(struct tty_struct *tty, static int moxa_write(struct tty_struct *tty,
...@@ -1226,7 +1225,7 @@ static int moxa_write(struct tty_struct *tty, ...@@ -1226,7 +1225,7 @@ static int moxa_write(struct tty_struct *tty,
len = MoxaPortWriteData(tty, buf, count); len = MoxaPortWriteData(tty, buf, count);
spin_unlock_bh(&moxa_lock); spin_unlock_bh(&moxa_lock);
ch->statusflags |= LOWWAIT; set_bit(LOWWAIT, &ch->statusflags);
return len; return len;
} }
...@@ -1264,7 +1263,7 @@ static int moxa_chars_in_buffer(struct tty_struct *tty) ...@@ -1264,7 +1263,7 @@ static int moxa_chars_in_buffer(struct tty_struct *tty)
* Make it possible to wakeup anything waiting for output * Make it possible to wakeup anything waiting for output
* in tty_ioctl.c, etc. * in tty_ioctl.c, etc.
*/ */
if (!(ch->statusflags & EMPTYWAIT)) if (!test_bit(EMPTYWAIT, &ch->statusflags))
moxa_setup_empty_event(tty); moxa_setup_empty_event(tty);
} }
unlock_kernel(); unlock_kernel();
...@@ -1332,14 +1331,14 @@ static void moxa_throttle(struct tty_struct *tty) ...@@ -1332,14 +1331,14 @@ static void moxa_throttle(struct tty_struct *tty)
{ {
struct moxa_port *ch = tty->driver_data; struct moxa_port *ch = tty->driver_data;
ch->statusflags |= THROTTLE; set_bit(THROTTLE, &ch->statusflags);
} }
static void moxa_unthrottle(struct tty_struct *tty) static void moxa_unthrottle(struct tty_struct *tty)
{ {
struct moxa_port *ch = tty->driver_data; struct moxa_port *ch = tty->driver_data;
ch->statusflags &= ~THROTTLE; clear_bit(THROTTLE, &ch->statusflags);
} }
static void moxa_set_termios(struct tty_struct *tty, static void moxa_set_termios(struct tty_struct *tty,
...@@ -1361,7 +1360,7 @@ static void moxa_stop(struct tty_struct *tty) ...@@ -1361,7 +1360,7 @@ static void moxa_stop(struct tty_struct *tty)
if (ch == NULL) if (ch == NULL)
return; return;
MoxaPortTxDisable(ch); MoxaPortTxDisable(ch);
ch->statusflags |= TXSTOPPED; set_bit(TXSTOPPED, &ch->statusflags);
} }
...@@ -1376,17 +1375,13 @@ static void moxa_start(struct tty_struct *tty) ...@@ -1376,17 +1375,13 @@ static void moxa_start(struct tty_struct *tty)
return; return;
MoxaPortTxEnable(ch); MoxaPortTxEnable(ch);
ch->statusflags &= ~TXSTOPPED; clear_bit(TXSTOPPED, &ch->statusflags);
} }
static void moxa_hangup(struct tty_struct *tty) static void moxa_hangup(struct tty_struct *tty)
{ {
struct moxa_port *ch; struct moxa_port *ch = tty->driver_data;
mutex_lock(&moxa_openlock);
ch = tty->driver_data;
tty_port_hangup(&ch->port); tty_port_hangup(&ch->port);
mutex_unlock(&moxa_openlock);
} }
static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd) static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
...@@ -1412,24 +1407,24 @@ static int moxa_poll_port(struct moxa_port *p, unsigned int handle, ...@@ -1412,24 +1407,24 @@ static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
u16 intr; u16 intr;
if (tty) { if (tty) {
if ((p->statusflags & EMPTYWAIT) && if (test_bit(EMPTYWAIT, &p->statusflags) &&
MoxaPortTxQueue(p) == 0) { MoxaPortTxQueue(p) == 0) {
p->statusflags &= ~EMPTYWAIT; clear_bit(EMPTYWAIT, &p->statusflags);
tty_wakeup(tty); tty_wakeup(tty);
} }
if ((p->statusflags & LOWWAIT) && !tty->stopped && if (test_bit(LOWWAIT, &p->statusflags) && !tty->stopped &&
MoxaPortTxQueue(p) <= WAKEUP_CHARS) { MoxaPortTxQueue(p) <= WAKEUP_CHARS) {
p->statusflags &= ~LOWWAIT; clear_bit(LOWWAIT, &p->statusflags);
tty_wakeup(tty); tty_wakeup(tty);
} }
if (inited && !(p->statusflags & THROTTLE) && if (inited && !test_bit(THROTTLE, &p->statusflags) &&
MoxaPortRxQueue(p) > 0) { /* RX */ MoxaPortRxQueue(p) > 0) { /* RX */
MoxaPortReadData(p); MoxaPortReadData(p);
tty_schedule_flip(tty); tty_schedule_flip(tty);
} }
} else { } else {
p->statusflags &= ~EMPTYWAIT; clear_bit(EMPTYWAIT, &p->statusflags);
MoxaPortFlushData(p, 0); /* flush RX */ MoxaPortFlushData(p, 0); /* flush RX */
} }
...@@ -1533,10 +1528,7 @@ static void moxa_set_tty_param(struct tty_struct *tty, struct ktermios *old_term ...@@ -1533,10 +1528,7 @@ static void moxa_set_tty_param(struct tty_struct *tty, struct ktermios *old_term
static void moxa_setup_empty_event(struct tty_struct *tty) static void moxa_setup_empty_event(struct tty_struct *tty)
{ {
struct moxa_port *ch = tty->driver_data; struct moxa_port *ch = tty->driver_data;
set_bit(EMPTYWAIT, &ch->statusflags);
spin_lock_bh(&moxa_lock);
ch->statusflags |= EMPTYWAIT;
spin_unlock_bh(&moxa_lock);
} }
/***************************************************************************** /*****************************************************************************
...@@ -1845,7 +1837,7 @@ static int MoxaPortSetTermio(struct moxa_port *port, struct ktermios *termio, ...@@ -1845,7 +1837,7 @@ static int MoxaPortSetTermio(struct moxa_port *port, struct ktermios *termio,
writeb(termio->c_cc[VSTOP], ofsAddr + FuncArg1); writeb(termio->c_cc[VSTOP], ofsAddr + FuncArg1);
writeb(FC_SetXonXoff, ofsAddr + FuncCode); writeb(FC_SetXonXoff, ofsAddr + FuncCode);
moxa_wait_finish(ofsAddr); moxa_wait_finish(ofsAddr);
spin_unlock_irqrestore(&moxafunc_lock); spin_unlock_irq(&moxafunc_lock);
} }
return baud; return baud;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment