Skip to content

Commit 9361ebf

Browse files
dstarke-siemensgregkh
authored andcommitted
tty: n_gsm: fix invalid gsmtty_write_room() result
gsmtty_write() does not prevent the user to use the full fifo size of 4096 bytes as allocated in gsm_dlci_alloc(). However, gsmtty_write_room() tries to limit the return value by 'TX_SIZE' and returns a negative value if the fifo has more than 'TX_SIZE' bytes stored. This is obviously wrong as 'TX_SIZE' is defined as 512. Define 'TX_SIZE' to the fifo size and use it accordingly for allocation to keep the current behavior. Return the correct remaining size of the fifo in gsmtty_write_room() via kfifo_avail(). Fixes: e1eaea4 ("tty: n_gsm line discipline") Cc: [email protected] Signed-off-by: Daniel Starke <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent edd5f60 commit 9361ebf

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

drivers/tty/n_gsm.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ struct gsm_dlci {
137137
int retries;
138138
/* Uplink tty if active */
139139
struct tty_port port; /* The tty bound to this DLCI if there is one */
140+
#define TX_SIZE 4096 /* Must be power of 2. */
140141
struct kfifo fifo; /* Queue fifo for the DLCI */
141142
int adaption; /* Adaption layer in use */
142143
int prev_adaption;
@@ -1731,7 +1732,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
17311732
return NULL;
17321733
spin_lock_init(&dlci->lock);
17331734
mutex_init(&dlci->mutex);
1734-
if (kfifo_alloc(&dlci->fifo, 4096, GFP_KERNEL) < 0) {
1735+
if (kfifo_alloc(&dlci->fifo, TX_SIZE, GFP_KERNEL) < 0) {
17351736
kfree(dlci);
17361737
return NULL;
17371738
}
@@ -2976,8 +2977,6 @@ static struct tty_ldisc_ops tty_ldisc_packet = {
29762977
* Virtual tty side
29772978
*/
29782979

2979-
#define TX_SIZE 512
2980-
29812980
/**
29822981
* gsm_modem_upd_via_data - send modem bits via convergence layer
29832982
* @dlci: channel
@@ -3217,7 +3216,7 @@ static unsigned int gsmtty_write_room(struct tty_struct *tty)
32173216
struct gsm_dlci *dlci = tty->driver_data;
32183217
if (dlci->state == DLCI_CLOSED)
32193218
return 0;
3220-
return TX_SIZE - kfifo_len(&dlci->fifo);
3219+
return kfifo_avail(&dlci->fifo);
32213220
}
32223221

32233222
static unsigned int gsmtty_chars_in_buffer(struct tty_struct *tty)

0 commit comments

Comments
 (0)