Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp320153ybv; Wed, 19 Feb 2020 22:23:35 -0800 (PST) X-Google-Smtp-Source: APXvYqxz9BFyDypbhFLKNQIX3zJrr8Ej/UMyG7oRKDzwZzapTxh5pWEZfKt8rN5K52N+E/LUVXI8 X-Received: by 2002:a9d:6a2:: with SMTP id 31mr21960190otx.313.1582179815112; Wed, 19 Feb 2020 22:23:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582179815; cv=none; d=google.com; s=arc-20160816; b=ob0AivdmlHkOLmE0UgknZXFP2sM+wGr0OmEfgBYpAKOUizPCQpbQnNr7/9RtUQlPeq pwxXnqlAH+WowIuRtlQe/6GnLp175m3dw2Dro7u1fGCo7PEL5rs4uo+KXJcO+no54PFb pKDt23nFHBhO1XclltlulvUuV4wjs2Ns8eyFri5fGwgHpj/nJKDMh6woHo941793ZKkX R7EvN9BGwbde7ERlDEsjBe7lO12777EN0gTAXmWDH5vMXnYJQZbIZOyHR44ehhE31c7I JS88rKk5bLTXU9Jrq9mBgdyk3YiG/NR8teCxzuwLUAQVE8hs24oZeF4v5FJ+aHV/oY9Z CN4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=xQ2hH1WuA3WIBV0TGGs6V9kr1LqyBnjsbugRrEFt9Ew=; b=alPI2vZQ4RbcfjAx2+AyvZP/LmwhHkhutjdx1dWJUle5yI0RlUJ6QSsnWdOxEUuC+m lcN7+HQmOksBLZ+gVP6qIOzHMpLS6smUB5512Ritz52mHRX91mg0VCnR2ExNmOs62HyU AzkeTQY+pWNYLqcB/p737EDrRlG3DpFrc2BRU6JQoXFyks/+YcxTElB3yF/0F+7UKnpp ihq+12CuBeBKjsZ07NXnbRQGWc57htuYwPBESP8c1xNq68dVBQ89HeVB03VoH6op2eO0 7tqNGz1y+IoyrRVbdppcNkkUpYIe632E+Yx85xqczh2ImXdh3faq1tcf3aYsL38dYU1s saIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="mqTSY/qA"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s128si9985491oig.204.2020.02.19.22.23.22; Wed, 19 Feb 2020 22:23:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="mqTSY/qA"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726927AbgBTGXH (ORCPT + 99 others); Thu, 20 Feb 2020 01:23:07 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:34860 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725988AbgBTGXG (ORCPT ); Thu, 20 Feb 2020 01:23:06 -0500 Received: by mail-pf1-f194.google.com with SMTP id i19so1397832pfa.2 for ; Wed, 19 Feb 2020 22:23:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xQ2hH1WuA3WIBV0TGGs6V9kr1LqyBnjsbugRrEFt9Ew=; b=mqTSY/qAB/RCNO8ZmyzzeSV454kKhoI4MrnzIubx8FG9Hs1YDY8qgkYCOOZ03fnOpj M9d3mq2QPbxb8DI9+NencQP10TelM1jX3r75i6nEudJJNC0pyPwTl5Zo70spE5jj6nwC RYRBy2U0gZtVNXuoqBFMSLZN6PyqSMEXMIPUo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xQ2hH1WuA3WIBV0TGGs6V9kr1LqyBnjsbugRrEFt9Ew=; b=qeyE22qWiL2v3NI5+UynFp/Bs9fUkLQkINqsLz/t6iKyG9rU2OwWRR6jCXckAyQC16 FlYaOo2zUFJw//U5RIYkIxKCt2BBvZQ3qJtkRzRNT22mb8ExFiXaIr31LocKTnDXaI8v Rf13FP6dqZhFPzEmgDATPE+WMROTZliwxl54b6j8q6/aTxUOCUL0HAmrMZuZKYIQJ6uF Z6TvocyQCfGqvw40iqyiKpHyyHWzbNuy7OKEZz6ii/RuLnl046K2Ck0WkkfxNRNwKaQi gb9rcB2pR+Nx8ftus2kKGUjEup31KlmOunJ6et6FbjPJ5gUKUgNvZk43tx/2UmFMVNLP SCRA== X-Gm-Message-State: APjAAAUCs88dccjvvz3wfE3nRvzJ3NyRHfROms9p4kQBbGdUWrOFqqrW /iKdLUjpWCeUzCfd5PlBht9zVg== X-Received: by 2002:a63:9251:: with SMTP id s17mr31193888pgn.127.1582179786195; Wed, 19 Feb 2020 22:23:06 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u126sm1728668pfu.182.2020.02.19.22.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 22:23:05 -0800 (PST) From: Kees Cook To: Jeff Kirsher Cc: Alexander Potapenko , Kees Cook , intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH] e1000: Distribute switch variables for initialization Date: Wed, 19 Feb 2020 22:23:02 -0800 Message-Id: <20200220062302.68898-1-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Variables declared in a switch statement before any case statements cannot be automatically initialized with compiler instrumentation (as they are not part of any execution flow). With GCC's proposed automatic stack variable initialization feature, this triggers a warning (and they don't get initialized). Clang's automatic stack variable initialization (via CONFIG_INIT_STACK_ALL=y) doesn't throw a warning, but it also doesn't initialize such variables[1]. Note that these warnings (or silent skipping) happen before the dead-store elimination optimization phase, so even when the automatic initializations are later elided in favor of direct initializations, the warnings remain. To avoid these problems, move such variables into the "case" where they're used or lift them up into the main function body. drivers/net/ethernet/intel/e1000/e1000_main.c: In function ‘e1000_xmit_frame’: drivers/net/ethernet/intel/e1000/e1000_main.c:3143:18: warning: statement will never be executed [-Wswitch-unreachable] 3143 | unsigned int pull_size; | ^~~~~~~~~ [1] https://bugs.llvm.org/show_bug.cgi?id=44916 Signed-off-by: Kees Cook --- drivers/net/ethernet/intel/e1000/e1000_main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c index 2bced34c19ba..a540d0206129 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_main.c +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c @@ -3140,8 +3140,9 @@ static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); if (skb->data_len && hdr_len == len) { switch (hw->mac_type) { + case e1000_82544: { unsigned int pull_size; - case e1000_82544: + /* Make sure we have room to chop off 4 bytes, * and that the end alignment will work out to * this hardware's requirements @@ -3162,6 +3163,7 @@ static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, } len = skb_headlen(skb); break; + } default: /* do nothing */ break;