aboutsummaryrefslogtreecommitdiffstats
path: root/net/irda
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2012-06-04 07:35:22 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-06-12 18:50:24 -0400
commit38c58032f07be4dee764baa573b233e9a828c119 (patch)
tree43ed0d519124067ba4406a25448b7083eb8cdd74 /net/irda
parent62f228acb807c370c3b1583bf0f1aa4ab8e19aca (diff)
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>
Diffstat (limited to 'net/irda')
-rw-r--r--net/irda/ircomm/ircomm_tty.c109
1 files changed, 56 insertions, 53 deletions
diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
index 03acc073b8c..199d9cbf994 100644
--- a/net/irda/ircomm/ircomm_tty.c
+++ b/net/irda/ircomm/ircomm_tty.c
@@ -244,6 +244,7 @@ err:
244static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self, 244static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
245 struct tty_struct *tty, struct file *filp) 245 struct tty_struct *tty, struct file *filp)
246{ 246{
247 struct tty_port *port = &self->port;
247 DECLARE_WAITQUEUE(wait, current); 248 DECLARE_WAITQUEUE(wait, current);
248 int retval; 249 int retval;
249 int do_clocal = 0, extra_count = 0; 250 int do_clocal = 0, extra_count = 0;
@@ -257,7 +258,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
257 */ 258 */
258 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){ 259 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
259 /* nonblock mode is set or port is not enabled */ 260 /* nonblock mode is set or port is not enabled */
260 self->port.flags |= ASYNC_NORMAL_ACTIVE; 261 port->flags |= ASYNC_NORMAL_ACTIVE;
261 IRDA_DEBUG(1, "%s(), O_NONBLOCK requested!\n", __func__ ); 262 IRDA_DEBUG(1, "%s(), O_NONBLOCK requested!\n", __func__ );
262 return 0; 263 return 0;
263 } 264 }
@@ -269,24 +270,24 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
269 270
270 /* Wait for carrier detect and the line to become 271 /* Wait for carrier detect and the line to become
271 * free (i.e., not in use by the callout). While we are in 272 * free (i.e., not in use by the callout). While we are in
272 * this loop, self->port.count is dropped by one, so that 273 * this loop, port->count is dropped by one, so that
273 * mgsl_close() knows when to free things. We restore it upon 274 * mgsl_close() knows when to free things. We restore it upon
274 * exit, either normal or abnormal. 275 * exit, either normal or abnormal.
275 */ 276 */
276 277
277 retval = 0; 278 retval = 0;
278 add_wait_queue(&self->port.open_wait, &wait); 279 add_wait_queue(&port->open_wait, &wait);
279 280
280 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n", 281 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
281 __FILE__, __LINE__, tty->driver->name, self->port.count); 282 __FILE__, __LINE__, tty->driver->name, port->count);
282 283
283 spin_lock_irqsave(&self->port.lock, flags); 284 spin_lock_irqsave(&port->lock, flags);
284 if (!tty_hung_up_p(filp)) { 285 if (!tty_hung_up_p(filp)) {
285 extra_count = 1; 286 extra_count = 1;
286 self->port.count--; 287 port->count--;
287 } 288 }
288 spin_unlock_irqrestore(&self->port.lock, flags); 289 spin_unlock_irqrestore(&port->lock, flags);
289 self->port.blocked_open++; 290 port->blocked_open++;
290 291
291 while (1) { 292 while (1) {
292 if (tty->termios->c_cflag & CBAUD) { 293 if (tty->termios->c_cflag & CBAUD) {
@@ -302,8 +303,8 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
302 current->state = TASK_INTERRUPTIBLE; 303 current->state = TASK_INTERRUPTIBLE;
303 304
304 if (tty_hung_up_p(filp) || 305 if (tty_hung_up_p(filp) ||
305 !test_bit(ASYNCB_INITIALIZED, &self->port.flags)) { 306 !test_bit(ASYNCB_INITIALIZED, &port->flags)) {
306 retval = (self->port.flags & ASYNC_HUP_NOTIFY) ? 307 retval = (port->flags & ASYNC_HUP_NOTIFY) ?
307 -EAGAIN : -ERESTARTSYS; 308 -EAGAIN : -ERESTARTSYS;
308 break; 309 break;
309 } 310 }
@@ -313,7 +314,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
313 * specified, we cannot return before the IrCOMM link is 314 * specified, we cannot return before the IrCOMM link is
314 * ready 315 * ready
315 */ 316 */
316 if (!test_bit(ASYNCB_CLOSING, &self->port.flags) && 317 if (!test_bit(ASYNCB_CLOSING, &port->flags) &&
317 (do_clocal || (self->settings.dce & IRCOMM_CD)) && 318 (do_clocal || (self->settings.dce & IRCOMM_CD)) &&
318 self->state == IRCOMM_TTY_READY) 319 self->state == IRCOMM_TTY_READY)
319 { 320 {
@@ -326,27 +327,27 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
326 } 327 }
327 328
328 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n", 329 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
329 __FILE__, __LINE__, tty->driver->name, self->port.count); 330 __FILE__, __LINE__, tty->driver->name, port->count);
330 331
331 schedule(); 332 schedule();
332 } 333 }
333 334
334 __set_current_state(TASK_RUNNING); 335 __set_current_state(TASK_RUNNING);
335 remove_wait_queue(&self->port.open_wait, &wait); 336 remove_wait_queue(&port->open_wait, &wait);
336 337
337 if (extra_count) { 338 if (extra_count) {
338 /* ++ is not atomic, so this should be protected - Jean II */ 339 /* ++ is not atomic, so this should be protected - Jean II */
339 spin_lock_irqsave(&self->port.lock, flags); 340 spin_lock_irqsave(&port->lock, flags);
340 self->port.count++; 341 port->count++;
341 spin_unlock_irqrestore(&self->port.lock, flags); 342 spin_unlock_irqrestore(&port->lock, flags);
342 } 343 }
343 self->port.blocked_open--; 344 port->blocked_open--;
344 345
345 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n", 346 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
346 __FILE__, __LINE__, tty->driver->name, self->port.count); 347 __FILE__, __LINE__, tty->driver->name, port->count);
347 348
348 if (!retval) 349 if (!retval)
349 self->port.flags |= ASYNC_NORMAL_ACTIVE; 350 port->flags |= ASYNC_NORMAL_ACTIVE;
350 351
351 return retval; 352 return retval;
352} 353}
@@ -484,6 +485,7 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
484static void ircomm_tty_close(struct tty_struct *tty, struct file *filp) 485static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
485{ 486{
486 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data; 487 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
488 struct tty_port *port = &self->port;
487 unsigned long flags; 489 unsigned long flags;
488 490
489 IRDA_DEBUG(0, "%s()\n", __func__ ); 491 IRDA_DEBUG(0, "%s()\n", __func__ );
@@ -491,16 +493,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
491 IRDA_ASSERT(self != NULL, return;); 493 IRDA_ASSERT(self != NULL, return;);
492 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); 494 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
493 495
494 spin_lock_irqsave(&self->port.lock, flags); 496 spin_lock_irqsave(&port->lock, flags);
495 497
496 if (tty_hung_up_p(filp)) { 498 if (tty_hung_up_p(filp)) {
497 spin_unlock_irqrestore(&self->port.lock, flags); 499 spin_unlock_irqrestore(&port->lock, flags);
498 500
499 IRDA_DEBUG(0, "%s(), returning 1\n", __func__ ); 501 IRDA_DEBUG(0, "%s(), returning 1\n", __func__ );
500 return; 502 return;
501 } 503 }
502 504
503 if ((tty->count == 1) && (self->port.count != 1)) { 505 if ((tty->count == 1) && (port->count != 1)) {
504 /* 506 /*
505 * Uh, oh. tty->count is 1, which means that the tty 507 * Uh, oh. tty->count is 1, which means that the tty
506 * structure will be freed. state->count should always 508 * structure will be freed. state->count should always
@@ -510,55 +512,55 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
510 */ 512 */
511 IRDA_DEBUG(0, "%s(), bad serial port count; " 513 IRDA_DEBUG(0, "%s(), bad serial port count; "
512 "tty->count is 1, state->count is %d\n", __func__ , 514 "tty->count is 1, state->count is %d\n", __func__ ,
513 self->port.count); 515 port->count);
514 self->port.count = 1; 516 port->count = 1;
515 } 517 }
516 518
517 if (--self->port.count < 0) { 519 if (--port->count < 0) {
518 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n", 520 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
519 __func__, self->line, self->port.count); 521 __func__, self->line, port->count);
520 self->port.count = 0; 522 port->count = 0;
521 } 523 }
522 if (self->port.count) { 524 if (port->count) {
523 spin_unlock_irqrestore(&self->port.lock, flags); 525 spin_unlock_irqrestore(&port->lock, flags);
524 526
525 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ ); 527 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
526 return; 528 return;
527 } 529 }
528 530
529 set_bit(ASYNCB_CLOSING, &self->port.flags); 531 set_bit(ASYNCB_CLOSING, &port->flags);
530 532
531 spin_unlock_irqrestore(&self->port.lock, flags); 533 spin_unlock_irqrestore(&port->lock, flags);
532 534
533 /* 535 /*
534 * Now we wait for the transmit buffer to clear; and we notify 536 * Now we wait for the transmit buffer to clear; and we notify
535 * the line discipline to only process XON/XOFF characters. 537 * the line discipline to only process XON/XOFF characters.
536 */ 538 */
537 tty->closing = 1; 539 tty->closing = 1;
538 if (self->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) 540 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
539 tty_wait_until_sent_from_close(tty, self->port.closing_wait); 541 tty_wait_until_sent_from_close(tty, port->closing_wait);
540 542
541 ircomm_tty_shutdown(self); 543 ircomm_tty_shutdown(self);
542 544
543 tty_driver_flush_buffer(tty); 545 tty_driver_flush_buffer(tty);
544 tty_ldisc_flush(tty); 546 tty_ldisc_flush(tty);
545 547
546 spin_lock_irqsave(&self->port.lock, flags); 548 spin_lock_irqsave(&port->lock, flags);
547 tty->closing = 0; 549 tty->closing = 0;
548 550
549 if (self->port.blocked_open) { 551 if (port->blocked_open) {
550 if (self->port.close_delay) { 552 if (port->close_delay) {
551 spin_unlock_irqrestore(&self->port.lock, flags); 553 spin_unlock_irqrestore(&port->lock, flags);
552 schedule_timeout_interruptible(self->port.close_delay); 554 schedule_timeout_interruptible(port->close_delay);
553 spin_lock_irqsave(&self->port.lock, flags); 555 spin_lock_irqsave(&port->lock, flags);
554 } 556 }
555 wake_up_interruptible(&self->port.open_wait); 557 wake_up_interruptible(&port->open_wait);
556 } 558 }
557 559
558 self->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 560 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
559 spin_unlock_irqrestore(&self->port.lock, flags); 561 spin_unlock_irqrestore(&port->lock, flags);
560 wake_up_interruptible(&self->port.close_wait); 562 wake_up_interruptible(&port->close_wait);
561 tty_port_tty_set(&self->port, NULL); 563 tty_port_tty_set(port, NULL);
562} 564}
563 565
564/* 566/*
@@ -991,6 +993,7 @@ static void ircomm_tty_shutdown(struct ircomm_tty_cb *self)
991static void ircomm_tty_hangup(struct tty_struct *tty) 993static void ircomm_tty_hangup(struct tty_struct *tty)
992{ 994{
993 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data; 995 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
996 struct tty_port *port = &self->port;
994 unsigned long flags; 997 unsigned long flags;
995 998
996 IRDA_DEBUG(0, "%s()\n", __func__ ); 999 IRDA_DEBUG(0, "%s()\n", __func__ );
@@ -1001,17 +1004,17 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
1001 /* ircomm_tty_flush_buffer(tty); */ 1004 /* ircomm_tty_flush_buffer(tty); */
1002 ircomm_tty_shutdown(self); 1005 ircomm_tty_shutdown(self);
1003 1006
1004 spin_lock_irqsave(&self->port.lock, flags); 1007 spin_lock_irqsave(&port->lock, flags);
1005 self->port.flags &= ~ASYNC_NORMAL_ACTIVE; 1008 port->flags &= ~ASYNC_NORMAL_ACTIVE;
1006 if (self->port.tty) { 1009 if (port->tty) {
1007 set_bit(TTY_IO_ERROR, &self->port.tty->flags); 1010 set_bit(TTY_IO_ERROR, &port->tty->flags);
1008 tty_kref_put(self->port.tty); 1011 tty_kref_put(port->tty);
1009 } 1012 }
1010 self->port.tty = NULL; 1013 port->tty = NULL;
1011 self->port.count = 0; 1014 port->count = 0;
1012 spin_unlock_irqrestore(&self->port.lock, flags); 1015 spin_unlock_irqrestore(&port->lock, flags);
1013 1016
1014 wake_up_interruptible(&self->port.open_wait); 1017 wake_up_interruptible(&port->open_wait);
1015} 1018}
1016 1019
1017/* 1020/*