Skip to content

Commit 2b5eac0

Browse files
Jiri Slaby (SUSE)gregkh
authored andcommitted
tty: introduce and use tty_port_tty_vhangup() helper
This code (tty_get -> vhangup -> tty_put) is repeated on few places. Introduce a helper similar to tty_port_tty_hangup() (asynchronous) to handle even vhangup (synchronous). And use it on those places. In fact, reuse the tty_port_tty_hangup()'s code and call tty_vhangup() depending on a new bool parameter. Signed-off-by: "Jiri Slaby (SUSE)" <[email protected]> Cc: Karsten Keil <[email protected]> Cc: David Lin <[email protected]> Cc: Johan Hovold <[email protected]> Cc: Alex Elder <[email protected]> Cc: Oliver Neukum <[email protected]> Cc: Marcel Holtmann <[email protected]> Cc: Johan Hedberg <[email protected]> Cc: Luiz Augusto von Dentz <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e04c78d commit 2b5eac0

File tree

8 files changed

+25
-42
lines changed

8 files changed

+25
-42
lines changed

drivers/isdn/capi/capi.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,9 @@ static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np)
306306
static void capincci_free_minor(struct capincci *np)
307307
{
308308
struct capiminor *mp = np->minorp;
309-
struct tty_struct *tty;
310309

311310
if (mp) {
312-
tty = tty_port_tty_get(&mp->port);
313-
if (tty) {
314-
tty_vhangup(tty);
315-
tty_kref_put(tty);
316-
}
317-
311+
tty_port_tty_vhangup(&mp->port);
318312
capiminor_free(mp);
319313
}
320314
}

drivers/staging/greybus/uart.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,6 @@ static void gb_uart_remove(struct gbphy_device *gbphy_dev)
916916
{
917917
struct gb_tty *gb_tty = gb_gbphy_get_data(gbphy_dev);
918918
struct gb_connection *connection = gb_tty->connection;
919-
struct tty_struct *tty;
920919
int ret;
921920

922921
ret = gbphy_runtime_get_sync(gbphy_dev);
@@ -929,11 +928,7 @@ static void gb_uart_remove(struct gbphy_device *gbphy_dev)
929928
wake_up_all(&gb_tty->wioctl);
930929
mutex_unlock(&gb_tty->mutex);
931930

932-
tty = tty_port_tty_get(&gb_tty->port);
933-
if (tty) {
934-
tty_vhangup(tty);
935-
tty_kref_put(tty);
936-
}
931+
tty_port_tty_vhangup(&gb_tty->port);
937932

938933
gb_connection_disable_rx(connection);
939934
tty_unregister_device(gb_tty_driver, gb_tty->minor);

drivers/tty/serial/serial_core.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,7 +3209,6 @@ static void serial_core_remove_one_port(struct uart_driver *drv,
32093209
struct uart_state *state = drv->state + uport->line;
32103210
struct tty_port *port = &state->port;
32113211
struct uart_port *uart_port;
3212-
struct tty_struct *tty;
32133212

32143213
mutex_lock(&port->mutex);
32153214
uart_port = uart_port_check(state);
@@ -3228,11 +3227,7 @@ static void serial_core_remove_one_port(struct uart_driver *drv,
32283227
*/
32293228
tty_port_unregister_device(port, drv->tty_driver, uport->line);
32303229

3231-
tty = tty_port_tty_get(port);
3232-
if (tty) {
3233-
tty_vhangup(port->tty);
3234-
tty_kref_put(tty);
3235-
}
3230+
tty_port_tty_vhangup(port);
32363231

32373232
/*
32383233
* If the port is used as a console, unregister it

drivers/tty/tty_port.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,19 @@ EXPORT_SYMBOL(tty_port_hangup);
396396
* @port: tty port
397397
* @check_clocal: hang only ttys with %CLOCAL unset?
398398
*/
399-
void tty_port_tty_hangup(struct tty_port *port, bool check_clocal)
399+
void __tty_port_tty_hangup(struct tty_port *port, bool check_clocal, bool async)
400400
{
401401
struct tty_struct *tty = tty_port_tty_get(port);
402402

403-
if (tty && (!check_clocal || !C_CLOCAL(tty)))
404-
tty_hangup(tty);
403+
if (tty && (!check_clocal || !C_CLOCAL(tty))) {
404+
if (async)
405+
tty_hangup(tty);
406+
else
407+
tty_vhangup(tty);
408+
}
405409
tty_kref_put(tty);
406410
}
407-
EXPORT_SYMBOL_GPL(tty_port_tty_hangup);
411+
EXPORT_SYMBOL_GPL(__tty_port_tty_hangup);
408412

409413
/**
410414
* tty_port_tty_wakeup - helper to wake up a tty

drivers/usb/class/cdc-acm.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,6 @@ static int acm_probe(struct usb_interface *intf,
15711571
static void acm_disconnect(struct usb_interface *intf)
15721572
{
15731573
struct acm *acm = usb_get_intfdata(intf);
1574-
struct tty_struct *tty;
15751574
int i;
15761575

15771576
/* sibling interface is already cleaning up */
@@ -1598,11 +1597,7 @@ static void acm_disconnect(struct usb_interface *intf)
15981597
usb_set_intfdata(acm->data, NULL);
15991598
mutex_unlock(&acm->mutex);
16001599

1601-
tty = tty_port_tty_get(&acm->port);
1602-
if (tty) {
1603-
tty_vhangup(tty);
1604-
tty_kref_put(tty);
1605-
}
1600+
tty_port_tty_vhangup(&acm->port);
16061601

16071602
cancel_delayed_work_sync(&acm->dwork);
16081603

drivers/usb/serial/usb-serial.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,6 @@ static void usb_serial_disconnect(struct usb_interface *interface)
11761176
struct usb_serial *serial = usb_get_intfdata(interface);
11771177
struct device *dev = &interface->dev;
11781178
struct usb_serial_port *port;
1179-
struct tty_struct *tty;
11801179

11811180
/* sibling interface is cleaning up */
11821181
if (!serial)
@@ -1191,11 +1190,7 @@ static void usb_serial_disconnect(struct usb_interface *interface)
11911190

11921191
for (i = 0; i < serial->num_ports; ++i) {
11931192
port = serial->port[i];
1194-
tty = tty_port_tty_get(&port->port);
1195-
if (tty) {
1196-
tty_vhangup(tty);
1197-
tty_kref_put(tty);
1198-
}
1193+
tty_port_tty_vhangup(&port->port);
11991194
usb_serial_port_poison_urbs(port);
12001195
wake_up_interruptible(&port->port.delta_msr_wait);
12011196
cancel_work_sync(&port->work);

include/linux/tty_port.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ bool tty_port_carrier_raised(struct tty_port *port);
232232
void tty_port_raise_dtr_rts(struct tty_port *port);
233233
void tty_port_lower_dtr_rts(struct tty_port *port);
234234
void tty_port_hangup(struct tty_port *port);
235-
void tty_port_tty_hangup(struct tty_port *port, bool check_clocal);
235+
void __tty_port_tty_hangup(struct tty_port *port, bool check_clocal, bool async);
236236
void tty_port_tty_wakeup(struct tty_port *port);
237237
int tty_port_block_til_ready(struct tty_port *port, struct tty_struct *tty,
238238
struct file *filp);
@@ -251,4 +251,14 @@ static inline int tty_port_users(struct tty_port *port)
251251
return port->count + port->blocked_open;
252252
}
253253

254+
static inline void tty_port_tty_hangup(struct tty_port *port, bool check_clocal)
255+
{
256+
__tty_port_tty_hangup(port, check_clocal, true);
257+
}
258+
259+
static inline void tty_port_tty_vhangup(struct tty_port *port)
260+
{
261+
__tty_port_tty_hangup(port, false, false);
262+
}
263+
254264
#endif

net/bluetooth/rfcomm/tty.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@ static int __rfcomm_release_dev(void __user *arg)
438438
{
439439
struct rfcomm_dev_req req;
440440
struct rfcomm_dev *dev;
441-
struct tty_struct *tty;
442441

443442
if (copy_from_user(&req, arg, sizeof(req)))
444443
return -EFAULT;
@@ -464,11 +463,7 @@ static int __rfcomm_release_dev(void __user *arg)
464463
rfcomm_dlc_close(dev->dlc, 0);
465464

466465
/* Shut down TTY synchronously before freeing rfcomm_dev */
467-
tty = tty_port_tty_get(&dev->port);
468-
if (tty) {
469-
tty_vhangup(tty);
470-
tty_kref_put(tty);
471-
}
466+
tty_port_tty_vhangup(&dev->port);
472467

473468
if (!test_bit(RFCOMM_TTY_OWNED, &dev->status))
474469
tty_port_put(&dev->port);

0 commit comments

Comments
 (0)