Received: by 2002:a05:6a10:5594:0:0:0:0 with SMTP id ee20csp517106pxb; Mon, 25 Apr 2022 15:22:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhlYCeJAcPr9DNwwCyPn+7aTizy9gc8gPpWtdGvyheD1N5FwnUHJhD25B6mDznD5IkB0a1 X-Received: by 2002:a63:7d4a:0:b0:398:dad:6963 with SMTP id m10-20020a637d4a000000b003980dad6963mr16772226pgn.329.1650925343276; Mon, 25 Apr 2022 15:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650925343; cv=none; d=google.com; s=arc-20160816; b=BTi6lg7e7vueNZ80Z+4GxmGM7GuShZSEU5HtYaONoCc9xPXlbVKTucd2+mVsb5NBKz L/tNXIT0UGmX6OWmnee/XLohgzRcM09whzjNoAzsCm2NYae07jw202/DCPIFMfhEii2U NldfOcKkdY3tjDhm6Pcxmroy+Z8wsKQxd32wJafaoQhLYhzgg/HpO0Jm5pRz+YrGFVTR iqdOKyeknNUWg+0o/2rbg8R5aYyFrifiLuOmBiANCcBWHa2sD3aHeRBViTSlJpuR8VJ8 TlB8FkLvUhEoA/lf5OqC46upOHfIYaL1lW8uutKWsmeSWJCCZGdxt0lzxqB4E0UOSWoe T60Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=ibveypy2TT2i4YuSJ92muBFUBKsW8Al9oyDzThK4kpU=; b=mDr6CE3s3FX7WqGfs3XnJ5nz6fY6lHGSzAAftgy7lWth0ygPEcoCmJpo8ExAzxaQTR RthnddSthBxEwSMkt0/069JoGQd2ZSB8Zszw8Z1sRag5vYc0JJ0slMRVgmonEGu5Xdxc ZUGg4lWxiCuQdsyEp1ynDjkyiub1vmQ66ScFm7/gFGZCSrh63WkvNmXyyAqXMy4gvq2m UhvyOVUSinc3ydaPaU6BDSF9egbjfR3RxQlIf54G+i9JgeKSE9yyujRuJqGwY/7apAQ0 YMFg1IyVmBmQp/8tg6DBuB9Y4YfmfHD7nz/DXaFNIPgFEENrIamV49yoJfCBTh+0SamG nqGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=GGDFW8jU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oo10-20020a17090b1c8a00b001cd6a811925si576327pjb.48.2022.04.25.15.21.20; Mon, 25 Apr 2022 15:22:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=GGDFW8jU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239977AbiDYKvw (ORCPT + 99 others); Mon, 25 Apr 2022 06:51:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233781AbiDYKvt (ORCPT ); Mon, 25 Apr 2022 06:51:49 -0400 X-Greylist: delayed 63 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 25 Apr 2022 03:48:43 PDT Received: from mta-65-226.siemens.flowmailer.net (mta-65-226.siemens.flowmailer.net [185.136.65.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DE3063CC for ; Mon, 25 Apr 2022 03:48:40 -0700 (PDT) Received: by mta-65-226.siemens.flowmailer.net with ESMTPSA id 20220425104733c4677b3423d2a9cbb7 for ; Mon, 25 Apr 2022 12:47:33 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=daniel.starke@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc; bh=ibveypy2TT2i4YuSJ92muBFUBKsW8Al9oyDzThK4kpU=; b=GGDFW8jUESh9CAa2Qw8xzLTbXEizho7aK/UrtUKNjeFNF7EAUDMsWThmC5UvVBz5wrD287 hg0Hxt4dF6mTBffFhnoZc1NFP/bUDtzKYNMciuhn7pRHLcJ/ymWDWckgUmdHOp8n9CJV1GMl dWoqMP0OFeJrZByN2WdphYPd6CnoI=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: linux-kernel@vger.kernel.org, Daniel Starke , kernel test robot Subject: [PATCH 1/1] tty: n_gsm: fix sometimes uninitialized warning in gsm_dlci_modem_output() Date: Mon, 25 Apr 2022 03:47:26 -0700 Message-Id: <20220425104726.7986-1-daniel.starke@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Starke '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: c19ffe00fed6 ("tty: n_gsm: fix invalid use of MSC in advanced option") Cc: stable@vger.kernel.org Reported-by: kernel test robot Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 8652308c187f..a38b922bcbc1 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -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); -- 2.25.1