@@ -790,7 +790,6 @@ static int uart_get_info(struct tty_port *port, struct serial_struct *retinfo)
790
790
{
791
791
struct uart_state * state = container_of (port , struct uart_state , port );
792
792
struct uart_port * uport ;
793
- int ret = - ENODEV ;
794
793
795
794
/* Initialize structure in case we error out later to prevent any stack info leakage. */
796
795
* retinfo = (struct serial_struct ){};
@@ -799,10 +798,10 @@ static int uart_get_info(struct tty_port *port, struct serial_struct *retinfo)
799
798
* Ensure the state we copy is consistent and no hardware changes
800
799
* occur as we go
801
800
*/
802
- mutex_lock (& port -> mutex );
801
+ guard ( mutex ) (& port -> mutex );
803
802
uport = uart_port_check (state );
804
803
if (!uport )
805
- goto out ;
804
+ return - ENODEV ;
806
805
807
806
retinfo -> type = uport -> type ;
808
807
retinfo -> line = uport -> line ;
@@ -823,10 +822,7 @@ static int uart_get_info(struct tty_port *port, struct serial_struct *retinfo)
823
822
retinfo -> iomem_reg_shift = uport -> regshift ;
824
823
retinfo -> iomem_base = (void * )(unsigned long )uport -> mapbase ;
825
824
826
- ret = 0 ;
827
- out :
828
- mutex_unlock (& port -> mutex );
829
- return ret ;
825
+ return 0 ;
830
826
}
831
827
832
828
static int uart_get_info_user (struct tty_struct * tty ,
@@ -3061,26 +3057,25 @@ static ssize_t console_store(struct device *dev,
3061
3057
if (ret )
3062
3058
return ret ;
3063
3059
3064
- mutex_lock (& port -> mutex );
3060
+ guard ( mutex ) (& port -> mutex );
3065
3061
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 ) ;
3080
3076
}
3081
- mutex_unlock (& port -> mutex );
3082
3077
3083
- return ret < 0 ? ret : count ;
3078
+ return count ;
3084
3079
}
3085
3080
3086
3081
static DEVICE_ATTR_RO (uartclk );
@@ -3136,7 +3131,6 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
3136
3131
{
3137
3132
struct uart_state * state ;
3138
3133
struct tty_port * port ;
3139
- int ret = 0 ;
3140
3134
struct device * tty_dev ;
3141
3135
int num_groups ;
3142
3136
@@ -3146,11 +3140,9 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
3146
3140
state = drv -> state + uport -> line ;
3147
3141
port = & state -> port ;
3148
3142
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 ;
3154
3146
3155
3147
/* Link the port to the driver state table and vice versa */
3156
3148
atomic_set (& state -> refcount , 1 );
@@ -3170,10 +3162,8 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
3170
3162
uport -> minor = drv -> tty_driver -> minor_start + uport -> line ;
3171
3163
uport -> name = kasprintf (GFP_KERNEL , "%s%d" , drv -> dev_name ,
3172
3164
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 ;
3177
3167
3178
3168
if (uport -> cons && uport -> dev )
3179
3169
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
3189
3179
3190
3180
uport -> tty_groups = kcalloc (num_groups , sizeof (* uport -> tty_groups ),
3191
3181
GFP_KERNEL );
3192
- if (!uport -> tty_groups ) {
3193
- ret = - ENOMEM ;
3194
- goto out ;
3195
- }
3182
+ if (!uport -> tty_groups )
3183
+ return - ENOMEM ;
3184
+
3196
3185
uport -> tty_groups [0 ] = & tty_dev_attr_group ;
3197
3186
if (uport -> attr_group )
3198
3187
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
3215
3204
uport -> line );
3216
3205
}
3217
3206
3218
- out :
3219
- mutex_unlock (& port -> mutex );
3220
-
3221
- return ret ;
3207
+ return 0 ;
3222
3208
}
3223
3209
3224
3210
/**
@@ -3384,7 +3370,7 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
3384
3370
struct serial_ctrl_device * ctrl_dev , * new_ctrl_dev = NULL ;
3385
3371
int ret ;
3386
3372
3387
- mutex_lock (& port_mutex );
3373
+ guard ( mutex ) (& port_mutex );
3388
3374
3389
3375
/*
3390
3376
* 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)
3396
3382
ctrl_dev = serial_core_ctrl_find (drv , port -> dev , port -> ctrl_id );
3397
3383
if (!ctrl_dev ) {
3398
3384
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 );
3403
3387
ctrl_dev = new_ctrl_dev ;
3404
3388
}
3405
3389
@@ -3420,8 +3404,6 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
3420
3404
if (ret )
3421
3405
goto err_unregister_port_dev ;
3422
3406
3423
- mutex_unlock (& port_mutex );
3424
-
3425
3407
return 0 ;
3426
3408
3427
3409
err_unregister_port_dev :
@@ -3430,9 +3412,6 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
3430
3412
err_unregister_ctrl_dev :
3431
3413
serial_base_ctrl_device_remove (new_ctrl_dev );
3432
3414
3433
- err_unlock :
3434
- mutex_unlock (& port_mutex );
3435
-
3436
3415
return ret ;
3437
3416
}
3438
3417
0 commit comments