tty: n_gsm: fix missing receive state reset after mode switch
authorDaniel Starke <daniel.starke@siemens.com>
Wed, 24 Apr 2024 05:48:42 +0000 (07:48 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 4 May 2024 16:13:26 +0000 (18:13 +0200)
commit70d7f1427afcf7fa2d21cb5a04c6f3555d5b9357
treed8ceec549bdb1e9c2d99b08270d7fd2fafe8c32d
parent47388e807f85948eefc403a8a5fdc5b406a65d5a
tty: n_gsm: fix missing receive state reset after mode switch

The current implementation uses either gsm0_receive() or gsm1_receive()
depending on whether the user configured the mux in basic or advanced
option mode. Both functions share some state values over the same logical
elements of the frame. However, both frame types differ in their nature.
gsm0_receive() uses non-transparency framing, whereas gsm1_receive() uses
transparency mechanism. Switching between both modes leaves the receive
function in an undefined state when done during frame reception.

Fix this by splitting both states. Add gsm0_receive_state_check_and_fix()
and gsm1_receive_state_check_and_fix() to ensure that gsm->state is reset
after a change of gsm->receive.

Note that gsm->state is only accessed in:
- gsm0_receive()
- gsm1_receive()
- gsm_error()

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/20240424054842.7741-2-daniel.starke@siemens.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/n_gsm.c