Skip to content

Commit 4d0e56d

Browse files
Jiri Slaby (SUSE)gregkh
authored andcommitted
tty: serial: get rid of exit label from uart_set_info()
The label is unneeded since 7ba2e76 (tty: Split the serial_core helpers for setserial into two). Until then, there was a lock held in uart_set_info(). Now it is not, so we can remove the label. This involves reordering the code, so that it is clear what values are returned, where and why. Until now, it was really hard to follow. The "change_port" part of the function is extracted into a separate function in the next patch. This patch makes the transition there easier too. 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 e52ed2d commit 4d0e56d

File tree

1 file changed

+51
-65
lines changed

1 file changed

+51
-65
lines changed

drivers/tty/serial/serial_core.c

Lines changed: 51 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
843843
unsigned int change_irq, change_port, closing_wait;
844844
unsigned int old_custom_divisor, close_delay;
845845
upf_t old_flags, new_flags;
846-
int retval = 0;
846+
int retval;
847847

848848
if (!uport)
849849
return -EIO;
@@ -882,21 +882,18 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
882882
if (!(uport->flags & UPF_FIXED_PORT)) {
883883
unsigned int uartclk = new_info->baud_base * 16;
884884
/* check needs to be done here before other settings made */
885-
if (uartclk == 0) {
886-
retval = -EINVAL;
887-
goto exit;
888-
}
885+
if (uartclk == 0)
886+
return -EINVAL;
889887
}
890888
if (!capable(CAP_SYS_ADMIN)) {
891-
retval = -EPERM;
892889
if (change_irq || change_port ||
893890
(new_info->baud_base != uport->uartclk / 16) ||
894891
(close_delay != port->close_delay) ||
895892
(closing_wait != port->closing_wait) ||
896893
(new_info->xmit_fifo_size &&
897894
new_info->xmit_fifo_size != uport->fifosize) ||
898895
(((new_flags ^ old_flags) & ~UPF_USR_MASK) != 0))
899-
goto exit;
896+
return -EPERM;
900897
uport->flags = ((uport->flags & ~UPF_USR_MASK) |
901898
(new_flags & UPF_USR_MASK));
902899
uport->custom_divisor = new_info->custom_divisor;
@@ -906,30 +903,24 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
906903
if (change_irq || change_port) {
907904
retval = security_locked_down(LOCKDOWN_TIOCSSERIAL);
908905
if (retval)
909-
goto exit;
906+
return retval;
910907
}
911908

912-
/*
913-
* Ask the low level driver to verify the settings.
914-
*/
915-
if (uport->ops->verify_port)
909+
/* Ask the low level driver to verify the settings. */
910+
if (uport->ops->verify_port) {
916911
retval = uport->ops->verify_port(uport, new_info);
912+
if (retval)
913+
return retval;
914+
}
917915

918916
if ((new_info->irq >= irq_get_nr_irqs()) || (new_info->irq < 0) ||
919917
(new_info->baud_base < 9600))
920-
retval = -EINVAL;
921-
922-
if (retval)
923-
goto exit;
918+
return -EINVAL;
924919

925920
if (change_port || change_irq) {
926-
retval = -EBUSY;
927-
928-
/*
929-
* Make sure that we are the sole user of this port.
930-
*/
921+
/* Make sure that we are the sole user of this port. */
931922
if (tty_port_users(port) > 1)
932-
goto exit;
923+
return -EBUSY;
933924

934925
/*
935926
* We need to shutdown the serial port at the old
@@ -967,40 +958,33 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
967958
*/
968959
if (uport->type != PORT_UNKNOWN && uport->ops->request_port) {
969960
retval = uport->ops->request_port(uport);
970-
} else {
971-
/* Always success - Jean II */
972-
retval = 0;
973-
}
974-
975-
/*
976-
* If we fail to request resources for the
977-
* new port, try to restore the old settings.
978-
*/
979-
if (retval) {
980-
uport->iobase = old_iobase;
981-
uport->type = old_type;
982-
uport->hub6 = old_hub6;
983-
uport->iotype = old_iotype;
984-
uport->regshift = old_shift;
985-
uport->mapbase = old_mapbase;
986-
987-
if (old_type != PORT_UNKNOWN) {
988-
retval = uport->ops->request_port(uport);
989-
/*
990-
* If we failed to restore the old settings,
991-
* we fail like this.
992-
*/
993-
if (retval)
994-
uport->type = PORT_UNKNOWN;
995-
996-
/*
997-
* We failed anyway.
998-
*/
999-
retval = -EBUSY;
961+
/*
962+
* If we fail to request resources for the
963+
* new port, try to restore the old settings.
964+
*/
965+
if (retval) {
966+
uport->iobase = old_iobase;
967+
uport->type = old_type;
968+
uport->hub6 = old_hub6;
969+
uport->iotype = old_iotype;
970+
uport->regshift = old_shift;
971+
uport->mapbase = old_mapbase;
972+
973+
if (old_type != PORT_UNKNOWN) {
974+
retval = uport->ops->request_port(uport);
975+
/*
976+
* If we failed to restore the old
977+
* settings, we fail like this.
978+
*/
979+
if (retval)
980+
uport->type = PORT_UNKNOWN;
981+
982+
/* We failed anyway. */
983+
return -EBUSY;
984+
}
985+
986+
return retval;
1000987
}
1001-
1002-
/* Added to return the correct error -Ram Gupta */
1003-
goto exit;
1004988
}
1005989
}
1006990

@@ -1017,9 +1001,9 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
10171001
uport->fifosize = new_info->xmit_fifo_size;
10181002

10191003
check_and_exit:
1020-
retval = 0;
10211004
if (uport->type == PORT_UNKNOWN)
1022-
goto exit;
1005+
return 0;
1006+
10231007
if (tty_port_initialized(port)) {
10241008
if (((old_flags ^ uport->flags) & UPF_SPD_MASK) ||
10251009
old_custom_divisor != uport->custom_divisor) {
@@ -1035,15 +1019,17 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
10351019
}
10361020
uart_change_line_settings(tty, state, NULL);
10371021
}
1038-
} else {
1039-
retval = uart_startup(tty, state, true);
1040-
if (retval == 0)
1041-
tty_port_set_initialized(port, true);
1042-
if (retval > 0)
1043-
retval = 0;
1022+
1023+
return 0;
10441024
}
1045-
exit:
1046-
return retval;
1025+
1026+
retval = uart_startup(tty, state, true);
1027+
if (retval < 0)
1028+
return retval;
1029+
if (retval == 0)
1030+
tty_port_set_initialized(port, true);
1031+
1032+
return 0;
10471033
}
10481034

10491035
static int uart_set_info_user(struct tty_struct *tty, struct serial_struct *ss)

0 commit comments

Comments
 (0)