Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tty: n_tty: clean up process_output_block()

* Use guard(mutex), which results in:
- the function can return directly when "space == 0".
- "i" can now be "unsigned" as it is no longer abused to hold a retval
from tty->ops->write(). Note the compared-to "nr" is already
"unsigned".
* The end label is now dubbed "do_write" as that is what happens there.
Unlike the uncertain "break_out" name.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20250317070046.24386-8-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
e287d646 fdfa49a8

+11 -16
+11 -16
drivers/tty/n_tty.c
··· 519 519 const u8 *buf, unsigned int nr) 520 520 { 521 521 struct n_tty_data *ldata = tty->disc_data; 522 - unsigned int space; 523 - int i; 522 + unsigned int space, i; 524 523 const u8 *cp; 525 524 526 - mutex_lock(&ldata->output_lock); 525 + guard(mutex)(&ldata->output_lock); 527 526 528 527 space = tty_write_room(tty); 529 - if (space == 0) { 530 - mutex_unlock(&ldata->output_lock); 528 + if (space == 0) 531 529 return 0; 532 - } 530 + 533 531 if (nr > space) 534 532 nr = space; 535 533 ··· 539 541 if (O_ONLRET(tty)) 540 542 ldata->column = 0; 541 543 if (O_ONLCR(tty)) 542 - goto break_out; 544 + goto do_write; 543 545 ldata->canon_column = ldata->column; 544 546 break; 545 547 case '\r': 546 548 if (O_ONOCR(tty) && ldata->column == 0) 547 - goto break_out; 549 + goto do_write; 548 550 if (O_OCRNL(tty)) 549 - goto break_out; 551 + goto do_write; 550 552 ldata->canon_column = ldata->column = 0; 551 553 break; 552 554 case '\t': 553 - goto break_out; 555 + goto do_write; 554 556 case '\b': 555 557 if (ldata->column > 0) 556 558 ldata->column--; ··· 558 560 default: 559 561 if (!iscntrl(c)) { 560 562 if (O_OLCUC(tty)) 561 - goto break_out; 563 + goto do_write; 562 564 if (!is_continuation(c, tty)) 563 565 ldata->column++; 564 566 } 565 567 break; 566 568 } 567 569 } 568 - break_out: 569 - i = tty->ops->write(tty, buf, i); 570 - 571 - mutex_unlock(&ldata->output_lock); 572 - return i; 570 + do_write: 571 + return tty->ops->write(tty, buf, i); 573 572 } 574 573 575 574 static int n_tty_process_echo_ops(struct tty_struct *tty, size_t *tail,