Skip to content

Commit 1931743

Browse files
dstarke-siemensgregkh
authored andcommitted
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: c19ffe0 ("tty: n_gsm: fix invalid use of MSC in advanced option") Cc: stable@vger.kernel.org Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Daniel Starke <daniel.starke@siemens.com> Link: https://lore.kernel.org/r/20220425104726.7986-1-daniel.starke@siemens.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 637674f commit 1931743

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

drivers/tty/n_gsm.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -932,18 +932,21 @@ static int gsm_dlci_modem_output(struct gsm_mux *gsm, struct gsm_dlci *dlci,
932932
{
933933
u8 *dp = NULL;
934934
struct gsm_msg *msg;
935-
int size;
935+
int size = 0;
936936

937937
/* for modem bits without break data */
938-
if (dlci->adaption == 1) {
939-
size = 0;
940-
} else if (dlci->adaption == 2) {
941-
size = 1;
938+
switch (dlci->adaption) {
939+
case 1: /* Unstructured */
940+
break;
941+
case 2: /* Unstructured with modem bits. */
942+
size++;
942943
if (brk > 0)
943944
size++;
944-
} else {
945+
break;
946+
default:
945947
pr_err("%s: unsupported adaption %d\n", __func__,
946948
dlci->adaption);
949+
return -EINVAL;
947950
}
948951

949952
msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype);

0 commit comments

Comments
 (0)