tty: n_gsm: fix invalid gsmtty_write_room() result
authorDaniel Starke <daniel.starke@siemens.com>
Wed, 4 May 2022 08:17:33 +0000 (10:17 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 12 Jul 2022 14:35:06 +0000 (16:35 +0200)
commit00fa5cbbb6a7a7035e7694a1b516904a3f51c2d4
treefc66313723859b46f3de97ec11a3294ce8e68af0
parent156f2c2378e1cd6760c0486f3e883afe8675d5e2
tty: n_gsm: fix invalid gsmtty_write_room() result

[ Upstream commit 9361ebfbb79fd1bc8594a487c01ad52cdaa391ea ]

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: e1eaea46bb40 ("tty: n_gsm line discipline")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
Link: https://lore.kernel.org/r/20220504081733.3494-3-daniel.starke@siemens.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/tty/n_gsm.c