From 0f3dcf3b5d76669123bf99fec812b8b0acd60375 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Wed, 5 May 2021 11:19:04 +0200 Subject: tty: make fp of tty_ldisc_ops::receive_buf{,2} const Char pointer (cp) passed to tty_ldisc_ops::receive_buf{,2} is const. There is no reason for flag pointer (fp) not to be too. So switch it in the definition and all uses. Signed-off-by: Jiri Slaby Cc: William Hubbs Cc: Chris Brannon Cc: Kirk Reiser Cc: Samuel Thibault Cc: Marcel Holtmann Cc: Johan Hedberg Cc: Luiz Augusto von Dentz Cc: Dmitry Torokhov Cc: Arnd Bergmann Cc: "David S. Miller" Cc: Jakub Kicinski Cc: Wolfgang Grandegger Cc: Marc Kleine-Budde Cc: Andreas Koensgen Cc: Paul Mackerras Cc: Liam Girdwood Cc: Mark Brown Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: Peter Ujfalusi Link: https://lore.kernel.org/r/20210505091928.22010-12-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman --- sound/soc/ti/ams-delta.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sound/soc/ti') diff --git a/sound/soc/ti/ams-delta.c b/sound/soc/ti/ams-delta.c index aba0017e870b..55a6736a378e 100644 --- a/sound/soc/ti/ams-delta.c +++ b/sound/soc/ti/ams-delta.c @@ -337,8 +337,8 @@ static int cx81801_hangup(struct tty_struct *tty) } /* Line discipline .receive_buf() */ -static void cx81801_receive(struct tty_struct *tty, - const unsigned char *cp, char *fp, int count) +static void cx81801_receive(struct tty_struct *tty, const unsigned char *cp, + const char *fp, int count) { struct snd_soc_component *component = tty->disc_data; const unsigned char *c; -- cgit v1.2.3 From fbadf70a8053b3dce78a45997ae55651693a2a81 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Wed, 5 May 2021 11:19:07 +0200 Subject: tty: set tty_ldisc_ops::num statically There is no reason to pass the ldisc number to tty_register_ldisc separately. Just set it in the already defined tty_ldisc_ops in all the ldiscs. This simplifies tty_register_ldisc a bit too (no need to set the num member there). Signed-off-by: Jiri Slaby Cc: William Hubbs Cc: Chris Brannon Cc: Kirk Reiser Cc: Samuel Thibault Cc: Marcel Holtmann Cc: Johan Hedberg Cc: Luiz Augusto von Dentz Cc: Dmitry Torokhov Cc: Arnd Bergmann Cc: "David S. Miller" Cc: Jakub Kicinski Cc: Wolfgang Grandegger Cc: Marc Kleine-Budde Cc: Andreas Koensgen Cc: Paul Mackerras Cc: Rodolfo Giometti Cc: Peter Ujfalusi Cc: Liam Girdwood Cc: Mark Brown Cc: Jaroslav Kysela Cc: Takashi Iwai Link: https://lore.kernel.org/r/20210505091928.22010-15-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman --- drivers/accessibility/speakup/spk_ttyio.c | 3 ++- drivers/bluetooth/hci_ldisc.c | 3 ++- drivers/input/serio/serport.c | 3 ++- drivers/misc/ti-st/st_core.c | 3 ++- drivers/net/caif/caif_serial.c | 3 ++- drivers/net/can/slcan.c | 3 ++- drivers/net/hamradio/6pack.c | 4 +++- drivers/net/hamradio/mkiss.c | 3 ++- drivers/net/ppp/ppp_async.c | 3 ++- drivers/net/ppp/ppp_synctty.c | 3 ++- drivers/net/slip/slip.c | 3 ++- drivers/pps/clients/pps-ldisc.c | 3 ++- drivers/tty/n_gsm.c | 3 ++- drivers/tty/n_hdlc.c | 3 ++- drivers/tty/n_null.c | 3 ++- drivers/tty/n_tty.c | 3 ++- drivers/tty/tty_ldisc.c | 7 +++---- include/linux/tty.h | 2 +- net/nfc/nci/uart.c | 3 ++- sound/soc/ti/ams-delta.c | 3 ++- 20 files changed, 41 insertions(+), 23 deletions(-) (limited to 'sound/soc/ti') diff --git a/drivers/accessibility/speakup/spk_ttyio.c b/drivers/accessibility/speakup/spk_ttyio.c index b7fd094700d9..8faa27bae6bf 100644 --- a/drivers/accessibility/speakup/spk_ttyio.c +++ b/drivers/accessibility/speakup/spk_ttyio.c @@ -105,6 +105,7 @@ static int spk_ttyio_receive_buf2(struct tty_struct *tty, static struct tty_ldisc_ops spk_ttyio_ldisc_ops = { .owner = THIS_MODULE, + .num = N_SPEAKUP, .name = "speakup_ldisc", .open = spk_ttyio_ldisc_open, .close = spk_ttyio_ldisc_close, @@ -212,7 +213,7 @@ static int spk_ttyio_initialise_ldisc(struct spk_synth *synth) void spk_ttyio_register_ldisc(void) { - if (tty_register_ldisc(N_SPEAKUP, &spk_ttyio_ldisc_ops)) + if (tty_register_ldisc(&spk_ttyio_ldisc_ops)) pr_warn("speakup: Error registering line discipline. Most synths won't work.\n"); } diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index e785851a92c1..ee32006e8fc9 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c @@ -821,6 +821,7 @@ static __poll_t hci_uart_tty_poll(struct tty_struct *tty, static struct tty_ldisc_ops hci_uart_ldisc = { .owner = THIS_MODULE, + .num = N_HCI, .name = "n_hci", .open = hci_uart_tty_open, .close = hci_uart_tty_close, @@ -840,7 +841,7 @@ static int __init hci_uart_init(void) BT_INFO("HCI UART driver ver %s", VERSION); /* Register the tty discipline */ - err = tty_register_ldisc(N_HCI, &hci_uart_ldisc); + err = tty_register_ldisc(&hci_uart_ldisc); if (err) { BT_ERR("HCI line discipline registration failed. (%d)", err); return err; diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c index ff3715315592..870b1d2606fc 100644 --- a/drivers/input/serio/serport.c +++ b/drivers/input/serio/serport.c @@ -274,6 +274,7 @@ static void serport_ldisc_write_wakeup(struct tty_struct * tty) static struct tty_ldisc_ops serport_ldisc = { .owner = THIS_MODULE, + .num = N_MOUSE, .name = "input", .open = serport_ldisc_open, .close = serport_ldisc_close, @@ -294,7 +295,7 @@ static struct tty_ldisc_ops serport_ldisc = { static int __init serport_init(void) { int retval; - retval = tty_register_ldisc(N_MOUSE, &serport_ldisc); + retval = tty_register_ldisc(&serport_ldisc); if (retval) printk(KERN_ERR "serport.c: Error registering line discipline.\n"); diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c index 239a75502cd6..a4f5d02940c7 100644 --- a/drivers/misc/ti-st/st_core.c +++ b/drivers/misc/ti-st/st_core.c @@ -845,6 +845,7 @@ static void st_tty_flush_buffer(struct tty_struct *tty) } static struct tty_ldisc_ops st_ldisc_ops = { + .num = N_TI_WL, .name = "n_st", .open = st_tty_open, .close = st_tty_close, @@ -860,7 +861,7 @@ int st_core_init(struct st_data_s **core_data) struct st_data_s *st_gdata; long err; - err = tty_register_ldisc(N_TI_WL, &st_ldisc_ops); + err = tty_register_ldisc(&st_ldisc_ops); if (err) { pr_err("error registering %d line discipline %ld", N_TI_WL, err); diff --git a/drivers/net/caif/caif_serial.c b/drivers/net/caif/caif_serial.c index b0566588ce33..2407a0f6656d 100644 --- a/drivers/net/caif/caif_serial.c +++ b/drivers/net/caif/caif_serial.c @@ -382,6 +382,7 @@ static void ldisc_close(struct tty_struct *tty) /* The line discipline structure. */ static struct tty_ldisc_ops caif_ldisc = { .owner = THIS_MODULE, + .num = N_CAIF, .name = "n_caif", .open = ldisc_open, .close = ldisc_close, @@ -431,7 +432,7 @@ static int __init caif_ser_init(void) { int ret; - ret = tty_register_ldisc(N_CAIF, &caif_ldisc); + ret = tty_register_ldisc(&caif_ldisc); if (ret < 0) pr_err("cannot register CAIF ldisc=%d err=%d\n", N_CAIF, ret); diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index 7dc3e79cb5c4..e3f528c82242 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -698,6 +698,7 @@ static int slcan_ioctl(struct tty_struct *tty, struct file *file, static struct tty_ldisc_ops slc_ldisc = { .owner = THIS_MODULE, + .num = N_SLCAN, .name = "slcan", .open = slcan_open, .close = slcan_close, @@ -722,7 +723,7 @@ static int __init slcan_init(void) return -ENOMEM; /* Fill in our line protocol discipline, and register it */ - status = tty_register_ldisc(N_SLCAN, &slc_ldisc); + status = tty_register_ldisc(&slc_ldisc); if (status) { printk(KERN_ERR "slcan: can't register line discipline\n"); kfree(slcan_devs); diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c index c0a80f04dd8e..4db1d3c4d771 100644 --- a/drivers/net/hamradio/6pack.c +++ b/drivers/net/hamradio/6pack.c @@ -744,6 +744,7 @@ static int sixpack_ioctl(struct tty_struct *tty, struct file *file, static struct tty_ldisc_ops sp_ldisc = { .owner = THIS_MODULE, + .num = N_6PACK, .name = "6pack", .open = sixpack_open, .close = sixpack_close, @@ -766,7 +767,8 @@ static int __init sixpack_init_driver(void) printk(msg_banner); /* Register the provided line protocol discipline */ - if ((status = tty_register_ldisc(N_6PACK, &sp_ldisc)) != 0) + status = tty_register_ldisc(&sp_ldisc); + if (status) printk(msg_regfail, status); return status; diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c index fc05ded48178..1eb87a5a9394 100644 --- a/drivers/net/hamradio/mkiss.c +++ b/drivers/net/hamradio/mkiss.c @@ -933,6 +933,7 @@ out: static struct tty_ldisc_ops ax_ldisc = { .owner = THIS_MODULE, + .num = N_AX25, .name = "mkiss", .open = mkiss_open, .close = mkiss_close, @@ -952,7 +953,7 @@ static int __init mkiss_init_driver(void) printk(banner); - status = tty_register_ldisc(N_AX25, &ax_ldisc); + status = tty_register_ldisc(&ax_ldisc); if (status != 0) printk(msg_regfail, status); diff --git a/drivers/net/ppp/ppp_async.c b/drivers/net/ppp/ppp_async.c index 9f08bd19551f..4bfb66c40c86 100644 --- a/drivers/net/ppp/ppp_async.c +++ b/drivers/net/ppp/ppp_async.c @@ -372,6 +372,7 @@ ppp_asynctty_wakeup(struct tty_struct *tty) static struct tty_ldisc_ops ppp_ldisc = { .owner = THIS_MODULE, + .num = N_PPP, .name = "ppp", .open = ppp_asynctty_open, .close = ppp_asynctty_close, @@ -389,7 +390,7 @@ ppp_async_init(void) { int err; - err = tty_register_ldisc(N_PPP, &ppp_ldisc); + err = tty_register_ldisc(&ppp_ldisc); if (err != 0) printk(KERN_ERR "PPP_async: error %d registering line disc.\n", err); diff --git a/drivers/net/ppp/ppp_synctty.c b/drivers/net/ppp/ppp_synctty.c index c82c4e6df4cb..0942d3ee48e0 100644 --- a/drivers/net/ppp/ppp_synctty.c +++ b/drivers/net/ppp/ppp_synctty.c @@ -365,6 +365,7 @@ ppp_sync_wakeup(struct tty_struct *tty) static struct tty_ldisc_ops ppp_sync_ldisc = { .owner = THIS_MODULE, + .num = N_SYNC_PPP, .name = "pppsync", .open = ppp_sync_open, .close = ppp_sync_close, @@ -382,7 +383,7 @@ ppp_sync_init(void) { int err; - err = tty_register_ldisc(N_SYNC_PPP, &ppp_sync_ldisc); + err = tty_register_ldisc(&ppp_sync_ldisc); if (err != 0) printk(KERN_ERR "PPP_sync: error %d registering line disc.\n", err); diff --git a/drivers/net/slip/slip.c b/drivers/net/slip/slip.c index 4dda49e61745..938ac0ec0305 100644 --- a/drivers/net/slip/slip.c +++ b/drivers/net/slip/slip.c @@ -1263,6 +1263,7 @@ static int sl_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) static struct tty_ldisc_ops sl_ldisc = { .owner = THIS_MODULE, + .num = N_SLIP, .name = "slip", .open = slip_open, .close = slip_close, @@ -1298,7 +1299,7 @@ static int __init slip_init(void) return -ENOMEM; /* Fill in our line protocol discipline, and register it */ - status = tty_register_ldisc(N_SLIP, &sl_ldisc); + status = tty_register_ldisc(&sl_ldisc); if (status != 0) { printk(KERN_ERR "SLIP: can't register line discipline (err = %d)\n", status); kfree(slip_devs); diff --git a/drivers/pps/clients/pps-ldisc.c b/drivers/pps/clients/pps-ldisc.c index bf26cc56b863..2a88e678d0b8 100644 --- a/drivers/pps/clients/pps-ldisc.c +++ b/drivers/pps/clients/pps-ldisc.c @@ -112,12 +112,13 @@ static int __init pps_tty_init(void) /* Init PPS_TTY data */ pps_ldisc_ops.owner = THIS_MODULE; + pps_ldisc_ops.num = N_PPS; pps_ldisc_ops.name = "pps_tty"; pps_ldisc_ops.dcd_change = pps_tty_dcd_change; pps_ldisc_ops.open = pps_tty_open; pps_ldisc_ops.close = pps_tty_close; - err = tty_register_ldisc(N_PPS, &pps_ldisc_ops); + err = tty_register_ldisc(&pps_ldisc_ops); if (err) pr_err("can't register PPS line discipline\n"); else diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 477403ecc445..654e439ff6c8 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -2857,6 +2857,7 @@ static int gsm_create_network(struct gsm_dlci *dlci, struct gsm_netconfig *nc) /* Line discipline for real tty */ static struct tty_ldisc_ops tty_ldisc_packet = { .owner = THIS_MODULE, + .num = N_GSM0710, .name = "n_gsm", .open = gsmld_open, .close = gsmld_close, @@ -3242,7 +3243,7 @@ static const struct tty_operations gsmtty_ops = { static int __init gsm_init(void) { /* Fill in our line protocol discipline, and register it */ - int status = tty_register_ldisc(N_GSM0710, &tty_ldisc_packet); + int status = tty_register_ldisc(&tty_ldisc_packet); if (status != 0) { pr_err("n_gsm: can't register line discipline (err = %d)\n", status); diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index 62b1d1a6e0f1..2256039911f5 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -788,6 +788,7 @@ static struct n_hdlc_buf *n_hdlc_buf_get(struct n_hdlc_buf_list *buf_list) static struct tty_ldisc_ops n_hdlc_ldisc = { .owner = THIS_MODULE, + .num = N_HDLC, .name = "hdlc", .open = n_hdlc_tty_open, .close = n_hdlc_tty_close, @@ -807,7 +808,7 @@ static int __init n_hdlc_init(void) /* range check maxframe arg */ maxframe = clamp(maxframe, 4096, MAX_HDLC_FRAME_SIZE); - status = tty_register_ldisc(N_HDLC, &n_hdlc_ldisc); + status = tty_register_ldisc(&n_hdlc_ldisc); if (!status) pr_info("N_HDLC line discipline registered with maxframe=%d\n", maxframe); diff --git a/drivers/tty/n_null.c b/drivers/tty/n_null.c index 2ff373d2f98d..ee229c812dce 100644 --- a/drivers/tty/n_null.c +++ b/drivers/tty/n_null.c @@ -40,6 +40,7 @@ static void n_null_receivebuf(struct tty_struct *tty, static struct tty_ldisc_ops null_ldisc = { .owner = THIS_MODULE, + .num = N_NULL, .name = "n_null", .open = n_null_open, .close = n_null_close, @@ -50,7 +51,7 @@ static struct tty_ldisc_ops null_ldisc = { static int __init n_null_init(void) { - BUG_ON(tty_register_ldisc(N_NULL, &null_ldisc)); + BUG_ON(tty_register_ldisc(&null_ldisc)); return 0; } diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 8ce712eec026..2fe27905c398 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -2424,6 +2424,7 @@ static int n_tty_ioctl(struct tty_struct *tty, struct file *file, static struct tty_ldisc_ops n_tty_ops = { .owner = THIS_MODULE, + .num = N_TTY, .name = "n_tty", .open = n_tty_open, .close = n_tty_close, @@ -2455,5 +2456,5 @@ EXPORT_SYMBOL_GPL(n_tty_inherit_ops); void __init n_tty_init(void) { - tty_register_ldisc(N_TTY, &n_tty_ops); + tty_register_ldisc(&n_tty_ops); } diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c index 03f414172f34..9aff04bee4cd 100644 --- a/drivers/tty/tty_ldisc.c +++ b/drivers/tty/tty_ldisc.c @@ -59,17 +59,16 @@ static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS]; * takes tty_ldiscs_lock to guard against ldisc races */ -int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc) +int tty_register_ldisc(struct tty_ldisc_ops *new_ldisc) { unsigned long flags; int ret = 0; - if (disc < N_TTY || disc >= NR_LDISCS) + if (new_ldisc->num < N_TTY || new_ldisc->num >= NR_LDISCS) return -EINVAL; raw_spin_lock_irqsave(&tty_ldiscs_lock, flags); - tty_ldiscs[disc] = new_ldisc; - new_ldisc->num = disc; + tty_ldiscs[new_ldisc->num] = new_ldisc; new_ldisc->refcount = 0; raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags); diff --git a/include/linux/tty.h b/include/linux/tty.h index 283ac5f29052..95c632299fb4 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -636,7 +636,7 @@ static inline int tty_port_users(struct tty_port *port) return port->count + port->blocked_open; } -extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc); +extern int tty_register_ldisc(struct tty_ldisc_ops *new_ldisc); extern int tty_unregister_ldisc(int disc); extern int tty_set_ldisc(struct tty_struct *tty, int disc); extern int tty_ldisc_receive_buf(struct tty_ldisc *ld, const unsigned char *p, diff --git a/net/nfc/nci/uart.c b/net/nfc/nci/uart.c index 98102ef64004..648c26b4bad8 100644 --- a/net/nfc/nci/uart.c +++ b/net/nfc/nci/uart.c @@ -442,6 +442,7 @@ EXPORT_SYMBOL_GPL(nci_uart_set_config); static struct tty_ldisc_ops nci_uart_ldisc = { .owner = THIS_MODULE, + .num = N_NCI, .name = "n_nci", .open = nci_uart_tty_open, .close = nci_uart_tty_close, @@ -456,7 +457,7 @@ static struct tty_ldisc_ops nci_uart_ldisc = { static int __init nci_uart_init(void) { - return tty_register_ldisc(N_NCI, &nci_uart_ldisc); + return tty_register_ldisc(&nci_uart_ldisc); } static void __exit nci_uart_exit(void) diff --git a/sound/soc/ti/ams-delta.c b/sound/soc/ti/ams-delta.c index 55a6736a378e..fcbb791bf27a 100644 --- a/sound/soc/ti/ams-delta.c +++ b/sound/soc/ti/ams-delta.c @@ -396,6 +396,7 @@ static void cx81801_wakeup(struct tty_struct *tty) static struct tty_ldisc_ops cx81801_ops = { .name = "cx81801", + .num = N_V253, .owner = THIS_MODULE, .open = cx81801_open, .close = cx81801_close, @@ -503,7 +504,7 @@ static int ams_delta_cx20442_init(struct snd_soc_pcm_runtime *rtd) } /* Register optional line discipline for over the modem control */ - ret = tty_register_ldisc(N_V253, &cx81801_ops); + ret = tty_register_ldisc(&cx81801_ops); if (ret) { dev_warn(card->dev, "Failed to register line discipline, " -- cgit v1.2.3 From f81ee8b8b8421dc06d13f197bb53191559cc51da Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Wed, 5 May 2021 11:19:09 +0200 Subject: tty: make tty_ldisc_ops a param in tty_unregister_ldisc Make tty_unregister_ldisc symmetric to tty_register_ldisc by accepting struct tty_ldisc_ops as a parameter instead of ldisc number. This avoids checking of the ldisc number bounds in tty_unregister_ldisc. Signed-off-by: Jiri Slaby Cc: William Hubbs Cc: Chris Brannon Cc: Kirk Reiser Cc: Samuel Thibault Cc: Marcel Holtmann Cc: Johan Hedberg Cc: Luiz Augusto von Dentz Cc: Dmitry Torokhov Cc: Arnd Bergmann Cc: "David S. Miller" Cc: Jakub Kicinski Cc: Wolfgang Grandegger Cc: Marc Kleine-Budde Cc: Andreas Koensgen Cc: Paul Mackerras Cc: Rodolfo Giometti Cc: Peter Ujfalusi Cc: Liam Girdwood Cc: Mark Brown Cc: Jaroslav Kysela Cc: Takashi Iwai Link: https://lore.kernel.org/r/20210505091928.22010-17-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman --- drivers/accessibility/speakup/spk_ttyio.c | 2 +- drivers/bluetooth/hci_ldisc.c | 2 +- drivers/input/serio/serport.c | 2 +- drivers/misc/ti-st/st_core.c | 6 +++--- drivers/net/caif/caif_serial.c | 2 +- drivers/net/can/slcan.c | 2 +- drivers/net/hamradio/6pack.c | 2 +- drivers/net/hamradio/mkiss.c | 2 +- drivers/net/ppp/ppp_async.c | 2 +- drivers/net/ppp/ppp_synctty.c | 2 +- drivers/net/slip/slip.c | 2 +- drivers/pps/clients/pps-ldisc.c | 2 +- drivers/tty/n_gsm.c | 4 ++-- drivers/tty/n_hdlc.c | 3 +-- drivers/tty/n_null.c | 2 +- drivers/tty/tty_ldisc.c | 9 +++------ include/linux/tty.h | 2 +- net/nfc/nci/uart.c | 2 +- sound/soc/ti/ams-delta.c | 2 +- 19 files changed, 24 insertions(+), 28 deletions(-) (limited to 'sound/soc/ti') diff --git a/drivers/accessibility/speakup/spk_ttyio.c b/drivers/accessibility/speakup/spk_ttyio.c index 8faa27bae6bf..0b7f1a87eaeb 100644 --- a/drivers/accessibility/speakup/spk_ttyio.c +++ b/drivers/accessibility/speakup/spk_ttyio.c @@ -219,7 +219,7 @@ void spk_ttyio_register_ldisc(void) void spk_ttyio_unregister_ldisc(void) { - if (tty_unregister_ldisc(N_SPEAKUP)) + if (tty_unregister_ldisc(&spk_ttyio_ldisc_ops)) pr_warn("speakup: Couldn't unregister ldisc\n"); } diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index ee32006e8fc9..31e0c804363c 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c @@ -917,7 +917,7 @@ static void __exit hci_uart_exit(void) #endif /* Release tty registration of line discipline */ - err = tty_unregister_ldisc(N_HCI); + err = tty_unregister_ldisc(&hci_uart_ldisc); if (err) BT_ERR("Can't unregister HCI line discipline (%d)", err); } diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c index 870b1d2606fc..7fbbe00e3553 100644 --- a/drivers/input/serio/serport.c +++ b/drivers/input/serio/serport.c @@ -304,7 +304,7 @@ static int __init serport_init(void) static void __exit serport_exit(void) { - tty_unregister_ldisc(N_MOUSE); + tty_unregister_ldisc(&serport_ldisc); } module_init(serport_init); diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c index a4f5d02940c7..174ae8e52805 100644 --- a/drivers/misc/ti-st/st_core.c +++ b/drivers/misc/ti-st/st_core.c @@ -872,7 +872,7 @@ int st_core_init(struct st_data_s **core_data) st_gdata = kzalloc(sizeof(struct st_data_s), GFP_KERNEL); if (!st_gdata) { pr_err("memory allocation failed"); - err = tty_unregister_ldisc(N_TI_WL); + err = tty_unregister_ldisc(&st_ldisc_ops); if (err) pr_err("unable to un-register ldisc %ld", err); err = -ENOMEM; @@ -892,7 +892,7 @@ int st_core_init(struct st_data_s **core_data) if (err) { pr_err("error during st_ll initialization(%ld)", err); kfree(st_gdata); - err = tty_unregister_ldisc(N_TI_WL); + err = tty_unregister_ldisc(&st_ldisc_ops); if (err) pr_err("unable to un-register ldisc"); return err; @@ -919,7 +919,7 @@ void st_core_exit(struct st_data_s *st_gdata) kfree_skb(st_gdata->rx_skb); kfree_skb(st_gdata->tx_skb); /* TTY ldisc cleanup */ - err = tty_unregister_ldisc(N_TI_WL); + err = tty_unregister_ldisc(&st_ldisc_ops); if (err) pr_err("unable to un-register ldisc %ld", err); /* free the global data pointer */ diff --git a/drivers/net/caif/caif_serial.c b/drivers/net/caif/caif_serial.c index 2407a0f6656d..d0c24dba4a86 100644 --- a/drivers/net/caif/caif_serial.c +++ b/drivers/net/caif/caif_serial.c @@ -447,7 +447,7 @@ static void __exit caif_ser_exit(void) spin_unlock(&ser_lock); ser_release(NULL); cancel_work_sync(&ser_release_work); - tty_unregister_ldisc(N_CAIF); + tty_unregister_ldisc(&caif_ldisc); debugfs_remove_recursive(debugfsdir); } diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index e3f528c82242..03a2dbd3c367 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -784,7 +784,7 @@ static void __exit slcan_exit(void) kfree(slcan_devs); slcan_devs = NULL; - i = tty_unregister_ldisc(N_SLCAN); + i = tty_unregister_ldisc(&slc_ldisc); if (i) printk(KERN_ERR "slcan: can't unregister ldisc (err %d)\n", i); } diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c index 4db1d3c4d771..aac24f9caceb 100644 --- a/drivers/net/hamradio/6pack.c +++ b/drivers/net/hamradio/6pack.c @@ -781,7 +781,7 @@ static void __exit sixpack_exit_driver(void) { int ret; - if ((ret = tty_unregister_ldisc(N_6PACK))) + if ((ret = tty_unregister_ldisc(&sp_ldisc))) printk(msg_unregfail, ret); } diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c index 1eb87a5a9394..750c6afc9302 100644 --- a/drivers/net/hamradio/mkiss.c +++ b/drivers/net/hamradio/mkiss.c @@ -967,7 +967,7 @@ static void __exit mkiss_exit_driver(void) { int ret; - if ((ret = tty_unregister_ldisc(N_AX25))) + if ((ret = tty_unregister_ldisc(&ax_ldisc))) printk(msg_unregfail, ret); } diff --git a/drivers/net/ppp/ppp_async.c b/drivers/net/ppp/ppp_async.c index 4bfb66c40c86..b2d454d01eba 100644 --- a/drivers/net/ppp/ppp_async.c +++ b/drivers/net/ppp/ppp_async.c @@ -1016,7 +1016,7 @@ static void async_lcp_peek(struct asyncppp *ap, unsigned char *data, static void __exit ppp_async_cleanup(void) { - if (tty_unregister_ldisc(N_PPP) != 0) + if (tty_unregister_ldisc(&ppp_ldisc) != 0) printk(KERN_ERR "failed to unregister PPP line discipline\n"); } diff --git a/drivers/net/ppp/ppp_synctty.c b/drivers/net/ppp/ppp_synctty.c index 0942d3ee48e0..ca403bde56fb 100644 --- a/drivers/net/ppp/ppp_synctty.c +++ b/drivers/net/ppp/ppp_synctty.c @@ -727,7 +727,7 @@ err: static void __exit ppp_sync_cleanup(void) { - if (tty_unregister_ldisc(N_SYNC_PPP) != 0) + if (tty_unregister_ldisc(&ppp_sync_ldisc) != 0) printk(KERN_ERR "failed to unregister Sync PPP line discipline\n"); } diff --git a/drivers/net/slip/slip.c b/drivers/net/slip/slip.c index 938ac0ec0305..867efff40a0e 100644 --- a/drivers/net/slip/slip.c +++ b/drivers/net/slip/slip.c @@ -1360,7 +1360,7 @@ static void __exit slip_exit(void) kfree(slip_devs); slip_devs = NULL; - i = tty_unregister_ldisc(N_SLIP); + i = tty_unregister_ldisc(&sl_ldisc); if (i != 0) printk(KERN_ERR "SLIP: can't unregister line discipline (err = %d)\n", i); } diff --git a/drivers/pps/clients/pps-ldisc.c b/drivers/pps/clients/pps-ldisc.c index 2a88e678d0b8..91b947f37774 100644 --- a/drivers/pps/clients/pps-ldisc.c +++ b/drivers/pps/clients/pps-ldisc.c @@ -131,7 +131,7 @@ static void __exit pps_tty_cleanup(void) { int err; - err = tty_unregister_ldisc(N_PPS); + err = tty_unregister_ldisc(&pps_ldisc_ops); if (err) pr_err("can't unregister PPS line discipline\n"); else diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index cce2ef04caeb..db7d4a30af91 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -3280,13 +3280,13 @@ static int __init gsm_init(void) err_put_driver: put_tty_driver(gsm_tty_driver); err_unreg_ldisc: - tty_unregister_ldisc(N_GSM0710); + tty_unregister_ldisc(&tty_ldisc_packet); return status; } static void __exit gsm_exit(void) { - int status = tty_unregister_ldisc(N_GSM0710); + int status = tty_unregister_ldisc(&tty_ldisc_packet); if (status != 0) pr_err("n_gsm: can't unregister line discipline (err = %d)\n", status); diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index 2256039911f5..c2afbfe0a1d5 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -822,8 +822,7 @@ static int __init n_hdlc_init(void) static void __exit n_hdlc_exit(void) { - /* Release tty registration of line discipline */ - int status = tty_unregister_ldisc(N_HDLC); + int status = tty_unregister_ldisc(&n_hdlc_ldisc); if (status) pr_err("N_HDLC: can't unregister line discipline (err = %d)\n", diff --git a/drivers/tty/n_null.c b/drivers/tty/n_null.c index ee229c812dce..f913b665af72 100644 --- a/drivers/tty/n_null.c +++ b/drivers/tty/n_null.c @@ -57,7 +57,7 @@ static int __init n_null_init(void) static void __exit n_null_exit(void) { - tty_unregister_ldisc(N_NULL); + tty_unregister_ldisc(&null_ldisc); } module_init(n_null_init); diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c index 9aff04bee4cd..d02deeb5e584 100644 --- a/drivers/tty/tty_ldisc.c +++ b/drivers/tty/tty_ldisc.c @@ -87,19 +87,16 @@ EXPORT_SYMBOL(tty_register_ldisc); * takes tty_ldiscs_lock to guard against ldisc races */ -int tty_unregister_ldisc(int disc) +int tty_unregister_ldisc(struct tty_ldisc_ops *ldisc) { unsigned long flags; int ret = 0; - if (disc < N_TTY || disc >= NR_LDISCS) - return -EINVAL; - raw_spin_lock_irqsave(&tty_ldiscs_lock, flags); - if (tty_ldiscs[disc]->refcount) + if (tty_ldiscs[ldisc->num]->refcount) ret = -EBUSY; else - tty_ldiscs[disc] = NULL; + tty_ldiscs[ldisc->num] = NULL; raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags); return ret; diff --git a/include/linux/tty.h b/include/linux/tty.h index 95c632299fb4..6a72d0ff6391 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -637,7 +637,7 @@ static inline int tty_port_users(struct tty_port *port) } extern int tty_register_ldisc(struct tty_ldisc_ops *new_ldisc); -extern int tty_unregister_ldisc(int disc); +extern int tty_unregister_ldisc(struct tty_ldisc_ops *ldisc); extern int tty_set_ldisc(struct tty_struct *tty, int disc); extern int tty_ldisc_receive_buf(struct tty_ldisc *ld, const unsigned char *p, const char *f, int count); diff --git a/net/nfc/nci/uart.c b/net/nfc/nci/uart.c index 648c26b4bad8..502e7a3f8948 100644 --- a/net/nfc/nci/uart.c +++ b/net/nfc/nci/uart.c @@ -462,7 +462,7 @@ static int __init nci_uart_init(void) static void __exit nci_uart_exit(void) { - tty_unregister_ldisc(N_NCI); + tty_unregister_ldisc(&nci_uart_ldisc); } module_init(nci_uart_init); diff --git a/sound/soc/ti/ams-delta.c b/sound/soc/ti/ams-delta.c index fcbb791bf27a..e89548e48364 100644 --- a/sound/soc/ti/ams-delta.c +++ b/sound/soc/ti/ams-delta.c @@ -583,7 +583,7 @@ static int ams_delta_remove(struct platform_device *pdev) { struct snd_soc_card *card = platform_get_drvdata(pdev); - if (tty_unregister_ldisc(N_V253) != 0) + if (tty_unregister_ldisc(&cx81801_ops) != 0) dev_warn(&pdev->dev, "failed to unregister V253 line discipline\n"); -- cgit v1.2.3 From 357a6a875f1c4772f2102639bf19619780889f31 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Wed, 5 May 2021 11:19:11 +0200 Subject: tty: no checking of tty_unregister_ldisc tty_unregister_ldisc now returns 0 = success. No need to check the return value. In fact, the users only warned if an error occured and didn't do anything useful anyway -- the ldisc module was unloaded in any case. Signed-off-by: Jiri Slaby Cc: William Hubbs Cc: Chris Brannon Cc: Kirk Reiser Cc: Samuel Thibault Cc: Marcel Holtmann Cc: Johan Hedberg Cc: Luiz Augusto von Dentz Cc: Arnd Bergmann Cc: Wolfgang Grandegger Cc: Marc Kleine-Budde Cc: "David S. Miller" Cc: Jakub Kicinski Cc: Andreas Koensgen Cc: Paul Mackerras Cc: Rodolfo Giometti Cc: Peter Ujfalusi Cc: Liam Girdwood Cc: Mark Brown Cc: Jaroslav Kysela Cc: Takashi Iwai Link: https://lore.kernel.org/r/20210505091928.22010-19-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman --- drivers/accessibility/speakup/spk_ttyio.c | 3 +-- drivers/bluetooth/hci_ldisc.c | 7 +------ drivers/misc/ti-st/st_core.c | 12 +++--------- drivers/net/can/slcan.c | 4 +--- drivers/net/hamradio/6pack.c | 8 +------- drivers/net/hamradio/mkiss.c | 8 +------- drivers/net/ppp/ppp_async.c | 3 +-- drivers/net/ppp/ppp_synctty.c | 3 +-- drivers/net/slip/slip.c | 4 +--- drivers/pps/clients/pps-ldisc.c | 8 +------- drivers/tty/n_gsm.c | 5 +---- drivers/tty/n_hdlc.c | 8 +------- sound/soc/ti/ams-delta.c | 4 +--- 13 files changed, 15 insertions(+), 62 deletions(-) (limited to 'sound/soc/ti') diff --git a/drivers/accessibility/speakup/spk_ttyio.c b/drivers/accessibility/speakup/spk_ttyio.c index 0b7f1a87eaeb..0d1f397cd896 100644 --- a/drivers/accessibility/speakup/spk_ttyio.c +++ b/drivers/accessibility/speakup/spk_ttyio.c @@ -219,8 +219,7 @@ void spk_ttyio_register_ldisc(void) void spk_ttyio_unregister_ldisc(void) { - if (tty_unregister_ldisc(&spk_ttyio_ldisc_ops)) - pr_warn("speakup: Couldn't unregister ldisc\n"); + tty_unregister_ldisc(&spk_ttyio_ldisc_ops); } static int spk_ttyio_out(struct spk_synth *in_synth, const char ch) diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index 31e0c804363c..5ed2cfa7da1d 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c @@ -883,8 +883,6 @@ static int __init hci_uart_init(void) static void __exit hci_uart_exit(void) { - int err; - #ifdef CONFIG_BT_HCIUART_H4 h4_deinit(); #endif @@ -916,10 +914,7 @@ static void __exit hci_uart_exit(void) mrvl_deinit(); #endif - /* Release tty registration of line discipline */ - err = tty_unregister_ldisc(&hci_uart_ldisc); - if (err) - BT_ERR("Can't unregister HCI line discipline (%d)", err); + tty_unregister_ldisc(&hci_uart_ldisc); } module_init(hci_uart_init); diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c index 174ae8e52805..85315e726644 100644 --- a/drivers/misc/ti-st/st_core.c +++ b/drivers/misc/ti-st/st_core.c @@ -872,9 +872,7 @@ int st_core_init(struct st_data_s **core_data) st_gdata = kzalloc(sizeof(struct st_data_s), GFP_KERNEL); if (!st_gdata) { pr_err("memory allocation failed"); - err = tty_unregister_ldisc(&st_ldisc_ops); - if (err) - pr_err("unable to un-register ldisc %ld", err); + tty_unregister_ldisc(&st_ldisc_ops); err = -ENOMEM; return err; } @@ -892,9 +890,7 @@ int st_core_init(struct st_data_s **core_data) if (err) { pr_err("error during st_ll initialization(%ld)", err); kfree(st_gdata); - err = tty_unregister_ldisc(&st_ldisc_ops); - if (err) - pr_err("unable to un-register ldisc"); + tty_unregister_ldisc(&st_ldisc_ops); return err; } @@ -919,9 +915,7 @@ void st_core_exit(struct st_data_s *st_gdata) kfree_skb(st_gdata->rx_skb); kfree_skb(st_gdata->tx_skb); /* TTY ldisc cleanup */ - err = tty_unregister_ldisc(&st_ldisc_ops); - if (err) - pr_err("unable to un-register ldisc %ld", err); + tty_unregister_ldisc(&st_ldisc_ops); /* free the global data pointer */ kfree(st_gdata); } diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index 03a2dbd3c367..d42ec7d1bc14 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -784,9 +784,7 @@ static void __exit slcan_exit(void) kfree(slcan_devs); slcan_devs = NULL; - i = tty_unregister_ldisc(&slc_ldisc); - if (i) - printk(KERN_ERR "slcan: can't unregister ldisc (err %d)\n", i); + tty_unregister_ldisc(&slc_ldisc); } module_init(slcan_init); diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c index aac24f9caceb..686c38c46113 100644 --- a/drivers/net/hamradio/6pack.c +++ b/drivers/net/hamradio/6pack.c @@ -774,15 +774,9 @@ static int __init sixpack_init_driver(void) return status; } -static const char msg_unregfail[] = KERN_ERR \ - "6pack: can't unregister line discipline (err = %d)\n"; - static void __exit sixpack_exit_driver(void) { - int ret; - - if ((ret = tty_unregister_ldisc(&sp_ldisc))) - printk(msg_unregfail, ret); + tty_unregister_ldisc(&sp_ldisc); } /* encode an AX.25 packet into 6pack */ diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c index 750c6afc9302..e3294a0a9800 100644 --- a/drivers/net/hamradio/mkiss.c +++ b/drivers/net/hamradio/mkiss.c @@ -960,15 +960,9 @@ static int __init mkiss_init_driver(void) return status; } -static const char msg_unregfail[] = KERN_ERR \ - "mkiss: can't unregister line discipline (err = %d)\n"; - static void __exit mkiss_exit_driver(void) { - int ret; - - if ((ret = tty_unregister_ldisc(&ax_ldisc))) - printk(msg_unregfail, ret); + tty_unregister_ldisc(&ax_ldisc); } MODULE_AUTHOR("Ralf Baechle DL5RB "); diff --git a/drivers/net/ppp/ppp_async.c b/drivers/net/ppp/ppp_async.c index b2d454d01eba..29a93d6bfe37 100644 --- a/drivers/net/ppp/ppp_async.c +++ b/drivers/net/ppp/ppp_async.c @@ -1016,8 +1016,7 @@ static void async_lcp_peek(struct asyncppp *ap, unsigned char *data, static void __exit ppp_async_cleanup(void) { - if (tty_unregister_ldisc(&ppp_ldisc) != 0) - printk(KERN_ERR "failed to unregister PPP line discipline\n"); + tty_unregister_ldisc(&ppp_ldisc); } module_init(ppp_async_init); diff --git a/drivers/net/ppp/ppp_synctty.c b/drivers/net/ppp/ppp_synctty.c index ca403bde56fb..af3e048695b6 100644 --- a/drivers/net/ppp/ppp_synctty.c +++ b/drivers/net/ppp/ppp_synctty.c @@ -727,8 +727,7 @@ err: static void __exit ppp_sync_cleanup(void) { - if (tty_unregister_ldisc(&ppp_sync_ldisc) != 0) - printk(KERN_ERR "failed to unregister Sync PPP line discipline\n"); + tty_unregister_ldisc(&ppp_sync_ldisc); } module_init(ppp_sync_init); diff --git a/drivers/net/slip/slip.c b/drivers/net/slip/slip.c index 867efff40a0e..dc84cb844319 100644 --- a/drivers/net/slip/slip.c +++ b/drivers/net/slip/slip.c @@ -1360,9 +1360,7 @@ static void __exit slip_exit(void) kfree(slip_devs); slip_devs = NULL; - i = tty_unregister_ldisc(&sl_ldisc); - if (i != 0) - printk(KERN_ERR "SLIP: can't unregister line discipline (err = %d)\n", i); + tty_unregister_ldisc(&sl_ldisc); } module_init(slip_init); diff --git a/drivers/pps/clients/pps-ldisc.c b/drivers/pps/clients/pps-ldisc.c index 91b947f37774..d73c4c2ed4e1 100644 --- a/drivers/pps/clients/pps-ldisc.c +++ b/drivers/pps/clients/pps-ldisc.c @@ -129,13 +129,7 @@ static int __init pps_tty_init(void) static void __exit pps_tty_cleanup(void) { - int err; - - err = tty_unregister_ldisc(&pps_ldisc_ops); - if (err) - pr_err("can't unregister PPS line discipline\n"); - else - pr_info("PPS line discipline removed\n"); + tty_unregister_ldisc(&pps_ldisc_ops); } module_init(pps_tty_init); diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index db7d4a30af91..157b26ef6259 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -3286,10 +3286,7 @@ err_unreg_ldisc: static void __exit gsm_exit(void) { - int status = tty_unregister_ldisc(&tty_ldisc_packet); - if (status != 0) - pr_err("n_gsm: can't unregister line discipline (err = %d)\n", - status); + tty_unregister_ldisc(&tty_ldisc_packet); tty_unregister_driver(gsm_tty_driver); put_tty_driver(gsm_tty_driver); } diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index c2afbfe0a1d5..d899ee4e0116 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -822,13 +822,7 @@ static int __init n_hdlc_init(void) static void __exit n_hdlc_exit(void) { - int status = tty_unregister_ldisc(&n_hdlc_ldisc); - - if (status) - pr_err("N_HDLC: can't unregister line discipline (err = %d)\n", - status); - else - pr_info("N_HDLC: line discipline unregistered\n"); + tty_unregister_ldisc(&n_hdlc_ldisc); } module_init(n_hdlc_init); diff --git a/sound/soc/ti/ams-delta.c b/sound/soc/ti/ams-delta.c index e89548e48364..ecd24d412a9b 100644 --- a/sound/soc/ti/ams-delta.c +++ b/sound/soc/ti/ams-delta.c @@ -583,9 +583,7 @@ static int ams_delta_remove(struct platform_device *pdev) { struct snd_soc_card *card = platform_get_drvdata(pdev); - if (tty_unregister_ldisc(&cx81801_ops) != 0) - dev_warn(&pdev->dev, - "failed to unregister V253 line discipline\n"); + tty_unregister_ldisc(&cx81801_ops); snd_soc_unregister_card(card); card->dev = NULL; -- cgit v1.2.3