TTY: ircomm, define local tty_port
In some functions we use tty_port heavily. So let us have a local pointer to that variable instead of having self->port all over the code. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Cc: Samuel Ortiz <samuel@sortiz.org> Cc: netdev@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
62f228acb8
commit
38c58032f0
|
@ -244,6 +244,7 @@ err:
|
||||||
static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
|
static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
|
||||||
struct tty_struct *tty, struct file *filp)
|
struct tty_struct *tty, struct file *filp)
|
||||||
{
|
{
|
||||||
|
struct tty_port *port = &self->port;
|
||||||
DECLARE_WAITQUEUE(wait, current);
|
DECLARE_WAITQUEUE(wait, current);
|
||||||
int retval;
|
int retval;
|
||||||
int do_clocal = 0, extra_count = 0;
|
int do_clocal = 0, extra_count = 0;
|
||||||
|
@ -257,7 +258,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
|
||||||
*/
|
*/
|
||||||
if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
|
if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
|
||||||
/* nonblock mode is set or port is not enabled */
|
/* nonblock mode is set or port is not enabled */
|
||||||
self->port.flags |= ASYNC_NORMAL_ACTIVE;
|
port->flags |= ASYNC_NORMAL_ACTIVE;
|
||||||
IRDA_DEBUG(1, "%s(), O_NONBLOCK requested!\n", __func__ );
|
IRDA_DEBUG(1, "%s(), O_NONBLOCK requested!\n", __func__ );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -269,24 +270,24 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
|
||||||
|
|
||||||
/* Wait for carrier detect and the line to become
|
/* Wait for carrier detect and the line to become
|
||||||
* free (i.e., not in use by the callout). While we are in
|
* free (i.e., not in use by the callout). While we are in
|
||||||
* this loop, self->port.count is dropped by one, so that
|
* this loop, port->count is dropped by one, so that
|
||||||
* mgsl_close() knows when to free things. We restore it upon
|
* mgsl_close() knows when to free things. We restore it upon
|
||||||
* exit, either normal or abnormal.
|
* exit, either normal or abnormal.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
add_wait_queue(&self->port.open_wait, &wait);
|
add_wait_queue(&port->open_wait, &wait);
|
||||||
|
|
||||||
IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
|
IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
|
||||||
__FILE__, __LINE__, tty->driver->name, self->port.count);
|
__FILE__, __LINE__, tty->driver->name, port->count);
|
||||||
|
|
||||||
spin_lock_irqsave(&self->port.lock, flags);
|
spin_lock_irqsave(&port->lock, flags);
|
||||||
if (!tty_hung_up_p(filp)) {
|
if (!tty_hung_up_p(filp)) {
|
||||||
extra_count = 1;
|
extra_count = 1;
|
||||||
self->port.count--;
|
port->count--;
|
||||||
}
|
}
|
||||||
spin_unlock_irqrestore(&self->port.lock, flags);
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
self->port.blocked_open++;
|
port->blocked_open++;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (tty->termios->c_cflag & CBAUD) {
|
if (tty->termios->c_cflag & CBAUD) {
|
||||||
|
@ -302,8 +303,8 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
|
||||||
current->state = TASK_INTERRUPTIBLE;
|
current->state = TASK_INTERRUPTIBLE;
|
||||||
|
|
||||||
if (tty_hung_up_p(filp) ||
|
if (tty_hung_up_p(filp) ||
|
||||||
!test_bit(ASYNCB_INITIALIZED, &self->port.flags)) {
|
!test_bit(ASYNCB_INITIALIZED, &port->flags)) {
|
||||||
retval = (self->port.flags & ASYNC_HUP_NOTIFY) ?
|
retval = (port->flags & ASYNC_HUP_NOTIFY) ?
|
||||||
-EAGAIN : -ERESTARTSYS;
|
-EAGAIN : -ERESTARTSYS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -313,7 +314,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
|
||||||
* specified, we cannot return before the IrCOMM link is
|
* specified, we cannot return before the IrCOMM link is
|
||||||
* ready
|
* ready
|
||||||
*/
|
*/
|
||||||
if (!test_bit(ASYNCB_CLOSING, &self->port.flags) &&
|
if (!test_bit(ASYNCB_CLOSING, &port->flags) &&
|
||||||
(do_clocal || (self->settings.dce & IRCOMM_CD)) &&
|
(do_clocal || (self->settings.dce & IRCOMM_CD)) &&
|
||||||
self->state == IRCOMM_TTY_READY)
|
self->state == IRCOMM_TTY_READY)
|
||||||
{
|
{
|
||||||
|
@ -326,27 +327,27 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
|
IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
|
||||||
__FILE__, __LINE__, tty->driver->name, self->port.count);
|
__FILE__, __LINE__, tty->driver->name, port->count);
|
||||||
|
|
||||||
schedule();
|
schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
__set_current_state(TASK_RUNNING);
|
__set_current_state(TASK_RUNNING);
|
||||||
remove_wait_queue(&self->port.open_wait, &wait);
|
remove_wait_queue(&port->open_wait, &wait);
|
||||||
|
|
||||||
if (extra_count) {
|
if (extra_count) {
|
||||||
/* ++ is not atomic, so this should be protected - Jean II */
|
/* ++ is not atomic, so this should be protected - Jean II */
|
||||||
spin_lock_irqsave(&self->port.lock, flags);
|
spin_lock_irqsave(&port->lock, flags);
|
||||||
self->port.count++;
|
port->count++;
|
||||||
spin_unlock_irqrestore(&self->port.lock, flags);
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
}
|
}
|
||||||
self->port.blocked_open--;
|
port->blocked_open--;
|
||||||
|
|
||||||
IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
|
IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
|
||||||
__FILE__, __LINE__, tty->driver->name, self->port.count);
|
__FILE__, __LINE__, tty->driver->name, port->count);
|
||||||
|
|
||||||
if (!retval)
|
if (!retval)
|
||||||
self->port.flags |= ASYNC_NORMAL_ACTIVE;
|
port->flags |= ASYNC_NORMAL_ACTIVE;
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -484,6 +485,7 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
|
||||||
static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
|
static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
|
||||||
{
|
{
|
||||||
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
||||||
|
struct tty_port *port = &self->port;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
IRDA_DEBUG(0, "%s()\n", __func__ );
|
IRDA_DEBUG(0, "%s()\n", __func__ );
|
||||||
|
@ -491,16 +493,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
|
||||||
IRDA_ASSERT(self != NULL, return;);
|
IRDA_ASSERT(self != NULL, return;);
|
||||||
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
|
||||||
|
|
||||||
spin_lock_irqsave(&self->port.lock, flags);
|
spin_lock_irqsave(&port->lock, flags);
|
||||||
|
|
||||||
if (tty_hung_up_p(filp)) {
|
if (tty_hung_up_p(filp)) {
|
||||||
spin_unlock_irqrestore(&self->port.lock, flags);
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
|
|
||||||
IRDA_DEBUG(0, "%s(), returning 1\n", __func__ );
|
IRDA_DEBUG(0, "%s(), returning 1\n", __func__ );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((tty->count == 1) && (self->port.count != 1)) {
|
if ((tty->count == 1) && (port->count != 1)) {
|
||||||
/*
|
/*
|
||||||
* Uh, oh. tty->count is 1, which means that the tty
|
* Uh, oh. tty->count is 1, which means that the tty
|
||||||
* structure will be freed. state->count should always
|
* structure will be freed. state->count should always
|
||||||
|
@ -510,55 +512,55 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
|
||||||
*/
|
*/
|
||||||
IRDA_DEBUG(0, "%s(), bad serial port count; "
|
IRDA_DEBUG(0, "%s(), bad serial port count; "
|
||||||
"tty->count is 1, state->count is %d\n", __func__ ,
|
"tty->count is 1, state->count is %d\n", __func__ ,
|
||||||
self->port.count);
|
port->count);
|
||||||
self->port.count = 1;
|
port->count = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (--self->port.count < 0) {
|
if (--port->count < 0) {
|
||||||
IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
|
IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
|
||||||
__func__, self->line, self->port.count);
|
__func__, self->line, port->count);
|
||||||
self->port.count = 0;
|
port->count = 0;
|
||||||
}
|
}
|
||||||
if (self->port.count) {
|
if (port->count) {
|
||||||
spin_unlock_irqrestore(&self->port.lock, flags);
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
|
|
||||||
IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
|
IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_bit(ASYNCB_CLOSING, &self->port.flags);
|
set_bit(ASYNCB_CLOSING, &port->flags);
|
||||||
|
|
||||||
spin_unlock_irqrestore(&self->port.lock, flags);
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now we wait for the transmit buffer to clear; and we notify
|
* Now we wait for the transmit buffer to clear; and we notify
|
||||||
* the line discipline to only process XON/XOFF characters.
|
* the line discipline to only process XON/XOFF characters.
|
||||||
*/
|
*/
|
||||||
tty->closing = 1;
|
tty->closing = 1;
|
||||||
if (self->port.closing_wait != ASYNC_CLOSING_WAIT_NONE)
|
if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
|
||||||
tty_wait_until_sent_from_close(tty, self->port.closing_wait);
|
tty_wait_until_sent_from_close(tty, port->closing_wait);
|
||||||
|
|
||||||
ircomm_tty_shutdown(self);
|
ircomm_tty_shutdown(self);
|
||||||
|
|
||||||
tty_driver_flush_buffer(tty);
|
tty_driver_flush_buffer(tty);
|
||||||
tty_ldisc_flush(tty);
|
tty_ldisc_flush(tty);
|
||||||
|
|
||||||
spin_lock_irqsave(&self->port.lock, flags);
|
spin_lock_irqsave(&port->lock, flags);
|
||||||
tty->closing = 0;
|
tty->closing = 0;
|
||||||
|
|
||||||
if (self->port.blocked_open) {
|
if (port->blocked_open) {
|
||||||
if (self->port.close_delay) {
|
if (port->close_delay) {
|
||||||
spin_unlock_irqrestore(&self->port.lock, flags);
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
schedule_timeout_interruptible(self->port.close_delay);
|
schedule_timeout_interruptible(port->close_delay);
|
||||||
spin_lock_irqsave(&self->port.lock, flags);
|
spin_lock_irqsave(&port->lock, flags);
|
||||||
}
|
}
|
||||||
wake_up_interruptible(&self->port.open_wait);
|
wake_up_interruptible(&port->open_wait);
|
||||||
}
|
}
|
||||||
|
|
||||||
self->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
|
port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
|
||||||
spin_unlock_irqrestore(&self->port.lock, flags);
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
wake_up_interruptible(&self->port.close_wait);
|
wake_up_interruptible(&port->close_wait);
|
||||||
tty_port_tty_set(&self->port, NULL);
|
tty_port_tty_set(port, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -991,6 +993,7 @@ static void ircomm_tty_shutdown(struct ircomm_tty_cb *self)
|
||||||
static void ircomm_tty_hangup(struct tty_struct *tty)
|
static void ircomm_tty_hangup(struct tty_struct *tty)
|
||||||
{
|
{
|
||||||
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
||||||
|
struct tty_port *port = &self->port;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
IRDA_DEBUG(0, "%s()\n", __func__ );
|
IRDA_DEBUG(0, "%s()\n", __func__ );
|
||||||
|
@ -1001,17 +1004,17 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
|
||||||
/* ircomm_tty_flush_buffer(tty); */
|
/* ircomm_tty_flush_buffer(tty); */
|
||||||
ircomm_tty_shutdown(self);
|
ircomm_tty_shutdown(self);
|
||||||
|
|
||||||
spin_lock_irqsave(&self->port.lock, flags);
|
spin_lock_irqsave(&port->lock, flags);
|
||||||
self->port.flags &= ~ASYNC_NORMAL_ACTIVE;
|
port->flags &= ~ASYNC_NORMAL_ACTIVE;
|
||||||
if (self->port.tty) {
|
if (port->tty) {
|
||||||
set_bit(TTY_IO_ERROR, &self->port.tty->flags);
|
set_bit(TTY_IO_ERROR, &port->tty->flags);
|
||||||
tty_kref_put(self->port.tty);
|
tty_kref_put(port->tty);
|
||||||
}
|
}
|
||||||
self->port.tty = NULL;
|
port->tty = NULL;
|
||||||
self->port.count = 0;
|
port->count = 0;
|
||||||
spin_unlock_irqrestore(&self->port.lock, flags);
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
|
|
||||||
wake_up_interruptible(&self->port.open_wait);
|
wake_up_interruptible(&port->open_wait);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue