Skip to content

Commit e287d64

Browse files
Jiri Slaby (SUSE)gregkh
authored andcommitted
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) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fdfa49a commit e287d64

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

drivers/tty/n_tty.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,15 @@ static ssize_t process_output_block(struct tty_struct *tty,
519519
const u8 *buf, unsigned int nr)
520520
{
521521
struct n_tty_data *ldata = tty->disc_data;
522-
unsigned int space;
523-
int i;
522+
unsigned int space, i;
524523
const u8 *cp;
525524

526-
mutex_lock(&ldata->output_lock);
525+
guard(mutex)(&ldata->output_lock);
527526

528527
space = tty_write_room(tty);
529-
if (space == 0) {
530-
mutex_unlock(&ldata->output_lock);
528+
if (space == 0)
531529
return 0;
532-
}
530+
533531
if (nr > space)
534532
nr = space;
535533

@@ -541,37 +539,34 @@ static ssize_t process_output_block(struct tty_struct *tty,
541539
if (O_ONLRET(tty))
542540
ldata->column = 0;
543541
if (O_ONLCR(tty))
544-
goto break_out;
542+
goto do_write;
545543
ldata->canon_column = ldata->column;
546544
break;
547545
case '\r':
548546
if (O_ONOCR(tty) && ldata->column == 0)
549-
goto break_out;
547+
goto do_write;
550548
if (O_OCRNL(tty))
551-
goto break_out;
549+
goto do_write;
552550
ldata->canon_column = ldata->column = 0;
553551
break;
554552
case '\t':
555-
goto break_out;
553+
goto do_write;
556554
case '\b':
557555
if (ldata->column > 0)
558556
ldata->column--;
559557
break;
560558
default:
561559
if (!iscntrl(c)) {
562560
if (O_OLCUC(tty))
563-
goto break_out;
561+
goto do_write;
564562
if (!is_continuation(c, tty))
565563
ldata->column++;
566564
}
567565
break;
568566
}
569567
}
570-
break_out:
571-
i = tty->ops->write(tty, buf, i);
572-
573-
mutex_unlock(&ldata->output_lock);
574-
return i;
568+
do_write:
569+
return tty->ops->write(tty, buf, i);
575570
}
576571

577572
static int n_tty_process_echo_ops(struct tty_struct *tty, size_t *tail,

0 commit comments

Comments
 (0)