[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <df8b824a-5479-0593-4f87-7ac8317584fa@kernel.org>
Date: Thu, 13 Oct 2022 08:21:37 +0200
From: Jiri Slaby <jirislaby@...nel.org>
To: Sasha Levin <sashal@...nel.org>, linux-kernel@...r.kernel.org,
stable@...r.kernel.org
Cc: Daniel Starke <daniel.starke@...mens.com>,
kernel test robot <lkp@...el.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: Re: [PATCH AUTOSEL 5.15 34/47] tty: n_gsm: replace use of
gsm_read_ea() with gsm_read_ea_val()
On 13. 10. 22, 2:21, Sasha Levin wrote:
> From: Daniel Starke <daniel.starke@...mens.com>
>
> [ Upstream commit 669609cea1d294f43efdd8d57ab65927df90e6df ]
>
> Replace the use of gsm_read_ea() with gsm_read_ea_val() where applicable to
> improve code readability and avoid errors like in the past. See first link
> below for reference.
I don't think this warrants for stable. It's only a cleanup, not a fix.
And it's quite intrusive.
> Link: https://lore.kernel.org/all/20220504081733.3494-1-daniel.starke@siemens.com/
> Link: https://lore.kernel.org/all/202208222147.WfFRmf1r-lkp@intel.com/
> Reported-by: kernel test robot <lkp@...el.com>
> Signed-off-by: Daniel Starke <daniel.starke@...mens.com>
> Link: https://lore.kernel.org/r/20220831073800.7459-3-daniel.starke@siemens.com
> Signed-off-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
> Signed-off-by: Sasha Levin <sashal@...nel.org>
> ---
> drivers/tty/n_gsm.c | 95 ++++++++++++++++++++++-----------------------
> 1 file changed, 47 insertions(+), 48 deletions(-)
>
> diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
> index 154697be11b0..d27247a84aab 100644
> --- a/drivers/tty/n_gsm.c
> +++ b/drivers/tty/n_gsm.c
> @@ -1297,18 +1297,12 @@ static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen)
> unsigned int modem = 0;
> struct gsm_dlci *dlci;
> int len = clen;
> - int slen;
> + int cl = clen;
> const u8 *dp = data;
> struct tty_struct *tty;
>
> - while (gsm_read_ea(&addr, *dp++) == 0) {
> - len--;
> - if (len == 0)
> - return;
> - }
> - /* Must be at least one byte following the EA */
> - len--;
> - if (len <= 0)
> + len = gsm_read_ea_val(&addr, data, cl);
> + if (len < 1)
> return;
>
> addr >>= 1;
> @@ -1317,15 +1311,20 @@ static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen)
> return;
> dlci = gsm->dlci[addr];
>
> - slen = len;
> - while (gsm_read_ea(&modem, *dp++) == 0) {
> - len--;
> - if (len == 0)
> - return;
> - }
> - len--;
> + /* Must be at least one byte following the EA */
> + if ((cl - len) < 1)
> + return;
> +
> + dp += len;
> + cl -= len;
> +
> + /* get the modem status */
> + len = gsm_read_ea_val(&modem, dp, cl);
> + if (len < 1)
> + return;
> +
> tty = tty_port_tty_get(&dlci->port);
> - gsm_process_modem(tty, dlci, modem, slen - len);
> + gsm_process_modem(tty, dlci, modem, cl);
> if (tty) {
> tty_wakeup(tty);
> tty_kref_put(tty);
> @@ -1819,11 +1818,10 @@ static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen)
> struct tty_port *port = &dlci->port;
> struct tty_struct *tty;
> unsigned int modem = 0;
> - int len = clen;
> - int slen = 0;
> + int len;
>
> if (debug & 16)
> - pr_debug("%d bytes for tty\n", len);
> + pr_debug("%d bytes for tty\n", clen);
> switch (dlci->adaption) {
> /* Unsupported types */
> case 4: /* Packetised interruptible data */
> @@ -1831,24 +1829,22 @@ static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen)
> case 3: /* Packetised uininterruptible voice/data */
> break;
> case 2: /* Asynchronous serial with line state in each frame */
> - while (gsm_read_ea(&modem, *data++) == 0) {
> - len--;
> - slen++;
> - if (len == 0)
> - return;
> - }
> - len--;
> - slen++;
> + len = gsm_read_ea_val(&modem, data, clen);
> + if (len < 1)
> + return;
> tty = tty_port_tty_get(port);
> if (tty) {
> - gsm_process_modem(tty, dlci, modem, slen);
> + gsm_process_modem(tty, dlci, modem, len);
> tty_wakeup(tty);
> tty_kref_put(tty);
> }
> + /* Skip processed modem data */
> + data += len;
> + clen -= len;
> fallthrough;
> case 1: /* Line state will go via DLCI 0 controls only */
> default:
> - tty_insert_flip_string(port, data, len);
> + tty_insert_flip_string(port, data, clen);
> tty_flip_buffer_push(port);
> }
> }
> @@ -1869,24 +1865,27 @@ static void gsm_dlci_command(struct gsm_dlci *dlci, const u8 *data, int len)
> {
> /* See what command is involved */
> unsigned int command = 0;
> - while (len-- > 0) {
> - if (gsm_read_ea(&command, *data++) == 1) {
> - int clen = *data++;
> - len--;
> - /* FIXME: this is properly an EA */
> - clen >>= 1;
> - /* Malformed command ? */
> - if (clen > len)
> - return;
> - if (command & 1)
> - gsm_control_message(dlci->gsm, command,
> - data, clen);
> - else
> - gsm_control_response(dlci->gsm, command,
> - data, clen);
> - return;
> - }
> - }
> + unsigned int clen = 0;
> + unsigned int dlen;
> +
> + /* read the command */
> + dlen = gsm_read_ea_val(&command, data, len);
> + len -= dlen;
> + data += dlen;
> +
> + /* read any control data */
> + dlen = gsm_read_ea_val(&clen, data, len);
> + len -= dlen;
> + data += dlen;
> +
> + /* Malformed command? */
> + if (clen > len)
> + return;
> +
> + if (command & 1)
> + gsm_control_message(dlci->gsm, command, data, clen);
> + else
> + gsm_control_response(dlci->gsm, command, data, clen);
> }
>
> /**
--
js
suse labs
Powered by blists - more mailing lists