@@ -790,7 +790,6 @@ static int uart_get_info(struct tty_port *port, struct serial_struct *retinfo)
790790{
791791 struct uart_state * state = container_of (port , struct uart_state , port );
792792 struct uart_port * uport ;
793- int ret = - ENODEV ;
794793
795794 /* Initialize structure in case we error out later to prevent any stack info leakage. */
796795 * retinfo = (struct serial_struct ){};
@@ -799,10 +798,10 @@ static int uart_get_info(struct tty_port *port, struct serial_struct *retinfo)
799798 * Ensure the state we copy is consistent and no hardware changes
800799 * occur as we go
801800 */
802- mutex_lock (& port -> mutex );
801+ guard ( mutex ) (& port -> mutex );
803802 uport = uart_port_check (state );
804803 if (!uport )
805- goto out ;
804+ return - ENODEV ;
806805
807806 retinfo -> type = uport -> type ;
808807 retinfo -> line = uport -> line ;
@@ -823,10 +822,7 @@ static int uart_get_info(struct tty_port *port, struct serial_struct *retinfo)
823822 retinfo -> iomem_reg_shift = uport -> regshift ;
824823 retinfo -> iomem_base = (void * )(unsigned long )uport -> mapbase ;
825824
826- ret = 0 ;
827- out :
828- mutex_unlock (& port -> mutex );
829- return ret ;
825+ return 0 ;
830826}
831827
832828static int uart_get_info_user (struct tty_struct * tty ,
@@ -3061,26 +3057,25 @@ static ssize_t console_store(struct device *dev,
30613057 if (ret )
30623058 return ret ;
30633059
3064- mutex_lock (& port -> mutex );
3060+ guard ( mutex ) (& port -> mutex );
30653061 uport = uart_port_check (state );
3066- if (uport ) {
3067- oldconsole = uart_console_registered ( uport ) ;
3068- if ( oldconsole && ! newconsole ) {
3069- ret = unregister_console (uport -> cons );
3070- } else if (! oldconsole && newconsole ) {
3071- if ( uart_console ( uport )) {
3072- uport -> console_reinit = 1 ;
3073- register_console ( uport -> cons ) ;
3074- } else {
3075- ret = - ENOENT ;
3076- }
3077- }
3078- } else {
3079- ret = - ENXIO ;
3062+ if (! uport )
3063+ return - ENXIO ;
3064+
3065+ oldconsole = uart_console_registered (uport );
3066+ if (oldconsole && ! newconsole ) {
3067+ ret = unregister_console ( uport -> cons );
3068+ if ( ret < 0 )
3069+ return ret ;
3070+ } else if (! oldconsole && newconsole ) {
3071+ if (! uart_console ( uport ))
3072+ return - ENOENT ;
3073+
3074+ uport -> console_reinit = 1 ;
3075+ register_console ( uport -> cons ) ;
30803076 }
3081- mutex_unlock (& port -> mutex );
30823077
3083- return ret < 0 ? ret : count ;
3078+ return count ;
30843079}
30853080
30863081static DEVICE_ATTR_RO (uartclk );
@@ -3136,7 +3131,6 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
31363131{
31373132 struct uart_state * state ;
31383133 struct tty_port * port ;
3139- int ret = 0 ;
31403134 struct device * tty_dev ;
31413135 int num_groups ;
31423136
@@ -3146,11 +3140,9 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
31463140 state = drv -> state + uport -> line ;
31473141 port = & state -> port ;
31483142
3149- mutex_lock (& port -> mutex );
3150- if (state -> uart_port ) {
3151- ret = - EINVAL ;
3152- goto out ;
3153- }
3143+ guard (mutex )(& port -> mutex );
3144+ if (state -> uart_port )
3145+ return - EINVAL ;
31543146
31553147 /* Link the port to the driver state table and vice versa */
31563148 atomic_set (& state -> refcount , 1 );
@@ -3170,10 +3162,8 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
31703162 uport -> minor = drv -> tty_driver -> minor_start + uport -> line ;
31713163 uport -> name = kasprintf (GFP_KERNEL , "%s%d" , drv -> dev_name ,
31723164 drv -> tty_driver -> name_base + uport -> line );
3173- if (!uport -> name ) {
3174- ret = - ENOMEM ;
3175- goto out ;
3176- }
3165+ if (!uport -> name )
3166+ return - ENOMEM ;
31773167
31783168 if (uport -> cons && uport -> dev )
31793169 of_console_check (uport -> dev -> of_node , uport -> cons -> name , uport -> line );
@@ -3189,10 +3179,9 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
31893179
31903180 uport -> tty_groups = kcalloc (num_groups , sizeof (* uport -> tty_groups ),
31913181 GFP_KERNEL );
3192- if (!uport -> tty_groups ) {
3193- ret = - ENOMEM ;
3194- goto out ;
3195- }
3182+ if (!uport -> tty_groups )
3183+ return - ENOMEM ;
3184+
31963185 uport -> tty_groups [0 ] = & tty_dev_attr_group ;
31973186 if (uport -> attr_group )
31983187 uport -> tty_groups [1 ] = uport -> attr_group ;
@@ -3215,10 +3204,7 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
32153204 uport -> line );
32163205 }
32173206
3218- out :
3219- mutex_unlock (& port -> mutex );
3220-
3221- return ret ;
3207+ return 0 ;
32223208}
32233209
32243210/**
@@ -3384,7 +3370,7 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
33843370 struct serial_ctrl_device * ctrl_dev , * new_ctrl_dev = NULL ;
33853371 int ret ;
33863372
3387- mutex_lock (& port_mutex );
3373+ guard ( mutex ) (& port_mutex );
33883374
33893375 /*
33903376 * Prevent serial_port_runtime_resume() from trying to use the port
@@ -3396,10 +3382,8 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
33963382 ctrl_dev = serial_core_ctrl_find (drv , port -> dev , port -> ctrl_id );
33973383 if (!ctrl_dev ) {
33983384 new_ctrl_dev = serial_core_ctrl_device_add (port );
3399- if (IS_ERR (new_ctrl_dev )) {
3400- ret = PTR_ERR (new_ctrl_dev );
3401- goto err_unlock ;
3402- }
3385+ if (IS_ERR (new_ctrl_dev ))
3386+ return PTR_ERR (new_ctrl_dev );
34033387 ctrl_dev = new_ctrl_dev ;
34043388 }
34053389
@@ -3420,8 +3404,6 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
34203404 if (ret )
34213405 goto err_unregister_port_dev ;
34223406
3423- mutex_unlock (& port_mutex );
3424-
34253407 return 0 ;
34263408
34273409err_unregister_port_dev :
@@ -3430,9 +3412,6 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
34303412err_unregister_ctrl_dev :
34313413 serial_base_ctrl_device_remove (new_ctrl_dev );
34323414
3433- err_unlock :
3434- mutex_unlock (& port_mutex );
3435-
34363415 return ret ;
34373416}
34383417
0 commit comments