tty: n_gsm: replace use of gsm_read_ea() with gsm_read_ea_val()

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.

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@intel.com>
Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
Link: https://lore.kernel.org/r/20220831073800.7459-3-daniel.starke@siemens.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Daniel Starke 2022-08-31 09:37:57 +02:00 committed by Greg Kroah-Hartman
parent 796492de01
commit 669609cea1
1 changed files with 47 additions and 48 deletions

View File

@ -1415,18 +1415,12 @@ static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen)
unsigned int modem = 0; unsigned int modem = 0;
struct gsm_dlci *dlci; struct gsm_dlci *dlci;
int len = clen; int len = clen;
int slen; int cl = clen;
const u8 *dp = data; const u8 *dp = data;
struct tty_struct *tty; struct tty_struct *tty;
while (gsm_read_ea(&addr, *dp++) == 0) { len = gsm_read_ea_val(&addr, data, cl);
len--; if (len < 1)
if (len == 0)
return;
}
/* Must be at least one byte following the EA */
len--;
if (len <= 0)
return; return;
addr >>= 1; addr >>= 1;
@ -1435,15 +1429,20 @@ static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen)
return; return;
dlci = gsm->dlci[addr]; dlci = gsm->dlci[addr];
slen = len; /* Must be at least one byte following the EA */
while (gsm_read_ea(&modem, *dp++) == 0) { if ((cl - len) < 1)
len--; return;
if (len == 0)
return; dp += len;
} cl -= len;
len--;
/* get the modem status */
len = gsm_read_ea_val(&modem, dp, cl);
if (len < 1)
return;
tty = tty_port_tty_get(&dlci->port); tty = tty_port_tty_get(&dlci->port);
gsm_process_modem(tty, dlci, modem, slen - len); gsm_process_modem(tty, dlci, modem, cl);
if (tty) { if (tty) {
tty_wakeup(tty); tty_wakeup(tty);
tty_kref_put(tty); tty_kref_put(tty);
@ -1918,11 +1917,10 @@ static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen)
struct tty_port *port = &dlci->port; struct tty_port *port = &dlci->port;
struct tty_struct *tty; struct tty_struct *tty;
unsigned int modem = 0; unsigned int modem = 0;
int len = clen; int len;
int slen = 0;
if (debug & 16) if (debug & 16)
pr_debug("%d bytes for tty\n", len); pr_debug("%d bytes for tty\n", clen);
switch (dlci->adaption) { switch (dlci->adaption) {
/* Unsupported types */ /* Unsupported types */
case 4: /* Packetised interruptible data */ case 4: /* Packetised interruptible data */
@ -1930,24 +1928,22 @@ static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen)
case 3: /* Packetised uininterruptible voice/data */ case 3: /* Packetised uininterruptible voice/data */
break; break;
case 2: /* Asynchronous serial with line state in each frame */ case 2: /* Asynchronous serial with line state in each frame */
while (gsm_read_ea(&modem, *data++) == 0) { len = gsm_read_ea_val(&modem, data, clen);
len--; if (len < 1)
slen++; return;
if (len == 0)
return;
}
len--;
slen++;
tty = tty_port_tty_get(port); tty = tty_port_tty_get(port);
if (tty) { if (tty) {
gsm_process_modem(tty, dlci, modem, slen); gsm_process_modem(tty, dlci, modem, len);
tty_wakeup(tty); tty_wakeup(tty);
tty_kref_put(tty); tty_kref_put(tty);
} }
/* Skip processed modem data */
data += len;
clen -= len;
fallthrough; fallthrough;
case 1: /* Line state will go via DLCI 0 controls only */ case 1: /* Line state will go via DLCI 0 controls only */
default: default:
tty_insert_flip_string(port, data, len); tty_insert_flip_string(port, data, clen);
tty_flip_buffer_push(port); tty_flip_buffer_push(port);
} }
} }
@ -1968,24 +1964,27 @@ static void gsm_dlci_command(struct gsm_dlci *dlci, const u8 *data, int len)
{ {
/* See what command is involved */ /* See what command is involved */
unsigned int command = 0; unsigned int command = 0;
while (len-- > 0) { unsigned int clen = 0;
if (gsm_read_ea(&command, *data++) == 1) { unsigned int dlen;
int clen = *data++;
len--; /* read the command */
/* FIXME: this is properly an EA */ dlen = gsm_read_ea_val(&command, data, len);
clen >>= 1; len -= dlen;
/* Malformed command ? */ data += dlen;
if (clen > len)
return; /* read any control data */
if (command & 1) dlen = gsm_read_ea_val(&clen, data, len);
gsm_control_message(dlci->gsm, command, len -= dlen;
data, clen); data += dlen;
else
gsm_control_response(dlci->gsm, command, /* Malformed command? */
data, clen); if (clen > len)
return; return;
}
} if (command & 1)
gsm_control_message(dlci->gsm, command, data, clen);
else
gsm_control_response(dlci->gsm, command, data, clen);
} }
/** /**