Commit 19317433 authored by Daniel Starke's avatar Daniel Starke Committed by Greg Kroah-Hartman

tty: n_gsm: fix sometimes uninitialized warning in gsm_dlci_modem_output()

'size' may be used uninitialized in gsm_dlci_modem_output() if called with
an adaption that is neither 1 nor 2. The function is currently only called
by gsm_modem_upd_via_data() and only for adaption 2.
Properly handle every invalid case by returning -EINVAL to silence the
compiler warning and avoid future regressions.

Fixes: c19ffe00 ("tty: n_gsm: fix invalid use of MSC in advanced option")
Cc: stable@vger.kernel.org
Reported-by: default avatarkernel test robot <lkp@intel.com>
Signed-off-by: default avatarDaniel Starke <daniel.starke@siemens.com>
Link: https://lore.kernel.org/r/20220425104726.7986-1-daniel.starke@siemens.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 637674fa
......@@ -932,18 +932,21 @@ static int gsm_dlci_modem_output(struct gsm_mux *gsm, struct gsm_dlci *dlci,
{
u8 *dp = NULL;
struct gsm_msg *msg;
int size;
int size = 0;
/* for modem bits without break data */
if (dlci->adaption == 1) {
size = 0;
} else if (dlci->adaption == 2) {
size = 1;
switch (dlci->adaption) {
case 1: /* Unstructured */
break;
case 2: /* Unstructured with modem bits. */
size++;
if (brk > 0)
size++;
} else {
break;
default:
pr_err("%s: unsupported adaption %d\n", __func__,
dlci->adaption);
return -EINVAL;
}
msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment