Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3390504ybp; Sun, 6 Oct 2019 10:53:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQ2uaLyYvUHOXxLY62RyEAkQUZz54UVy3pjStaOcsJzwnbrMSyw7xY4vHPu6Hdc2A7ifvf X-Received: by 2002:aa7:cf11:: with SMTP id a17mr25465295edy.153.1570384410687; Sun, 06 Oct 2019 10:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570384410; cv=none; d=google.com; s=arc-20160816; b=nVYryzg0kYHy0CiG5oqmBPg3E+ZiHqDr/hN376s9TW7wN3qv9/2owHTtThgjkUzSXr VVDn1Wx5HgNdZNpeWU/4Duxv5FCEzN7uj62faWnCzV5e4GhPbA+Hq5abK/vf6DJmjUYn NKwkHxN4/vD7QWq5+GgMOFqhYat7yaUjpjvkh/s/l6TwxT9r6pI91s+Edxum/G+RSpMU w4WSzt2mXocpyzNcpr8Imngt6twLYfBBw2V5jTWzal0kx3Kex1g6Zo/ZAUlbHQzqttT2 0B+PPMGUWyfaAQFrN1/FJMXL+gtD3Q4fpPYZhqb4F0A/h4i8N1mLShadiLa3b0TYAMMD bgYA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BvswBD7BVsFjMzenp0178eZ21x/JT60JtfypQc2JI14=; b=dgW/adxI/mdeaPA2sQIAVOt0obkz20Kug6zR8nV2t3GdJekD+bplONVPrzyckQ9zCZ iFSTQuve2b8pe4LKGGexWdyRZ4wSEai12+nyRLBCMto9QLQzeknB9qHl4J0QFKrxv751 9AEYt6bbljploo9ygilVQCfFFa8odJpzL53Pa6dYAmAHCTRffGbIDyDWLwBfhVOzJJLG mffOa5h9xOHoz/NDL/7UxAcAvQFi4dCjtKMytaU7R7xMAhGobNmoCu4kLwJFSjUFPVho v5vKZM5gtVFe/lIvRliLk2wL8/UNPNW0PVqG18iDk9CbdHDNKV3/cZxKux4oWTsA3c7/ /O0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="sUJ/YH9d"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oe23si5887780ejb.199.2019.10.06.10.53.07; Sun, 06 Oct 2019 10:53:30 -0700 (PDT) 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=@kernel.org header.s=default header.b="sUJ/YH9d"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727500AbfJFRw4 (ORCPT + 99 others); Sun, 6 Oct 2019 13:52:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:37972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730650AbfJFRik (ORCPT ); Sun, 6 Oct 2019 13:38:40 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3A8692080F; Sun, 6 Oct 2019 17:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383518; bh=f+mN/3SNEj0pxynAHt+FW+QiIG9PflCFqhGEbsaoz64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sUJ/YH9dtlJ9o/ym5Xiz0ziqE2afL7+xHA1OV775Us3lEgVolXaOGe+KZb9ljtu5Z B4Nq3PDaSV9X8zgmjihXluLU7N95wX8K8mmjg1TWMmw0FvA/lM9/8FZxsk1IvQuszP jQCWAAfIDcQXF3TrGu41Tkz5iEj0kG1oNnvXz9QM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nathan Chancellor , Paul Burton , Ralf Baechle , James Hogan , Nick Desaulniers , linux-mips@vger.kernel.org, clang-built-linux@googlegroups.com, Sasha Levin Subject: [PATCH 5.2 091/137] MIPS: Dont use bc_false uninitialized in __mm_isBranchInstr Date: Sun, 6 Oct 2019 19:21:15 +0200 Message-Id: <20191006171216.429826413@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171209.403038733@linuxfoundation.org> References: <20191006171209.403038733@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Nathan Chancellor [ Upstream commit c2869aafe7191d366d74c55cb8a93c6d0baba317 ] clang warns: arch/mips/kernel/branch.c:148:8: error: variable 'bc_false' is used uninitialized whenever switch case is taken [-Werror,-Wsometimes-uninitialized] case mm_bc2t_op: ^~~~~~~~~~ arch/mips/kernel/branch.c:157:8: note: uninitialized use occurs here if (bc_false) ^~~~~~~~ arch/mips/kernel/branch.c:149:8: error: variable 'bc_false' is used uninitialized whenever switch case is taken [-Werror,-Wsometimes-uninitialized] case mm_bc1t_op: ^~~~~~~~~~ arch/mips/kernel/branch.c:157:8: note: uninitialized use occurs here if (bc_false) ^~~~~~~~ arch/mips/kernel/branch.c:142:4: note: variable 'bc_false' is declared here int bc_false = 0; ^ 2 errors generated. When mm_bc1t_op and mm_bc2t_op are taken, the bc_false initialization does not happen, which leads to a garbage value upon use, as illustrated below with a small sample program. $ mipsel-linux-gnu-gcc --version | head -n1 mipsel-linux-gnu-gcc (Debian 8.3.0-2) 8.3.0 $ clang --version | head -n1 ClangBuiltLinux clang version 9.0.0 (git://github.com/llvm/llvm-project 544315b4197034a3be8acd12cba56a75fb1f08dc) (based on LLVM 9.0.0svn) $ cat test.c #include static void switch_scoped(int opcode) { switch (opcode) { case 1: case 2: { int bc_false = 0; bc_false = 4; case 3: case 4: printf("\t* switch scoped bc_false = %d\n", bc_false); } } } static void function_scoped(int opcode) { int bc_false = 0; switch (opcode) { case 1: case 2: { bc_false = 4; case 3: case 4: printf("\t* function scoped bc_false = %d\n", bc_false); } } } int main(void) { int opcode; for (opcode = 1; opcode < 5; opcode++) { printf("opcode = %d:\n", opcode); switch_scoped(opcode); function_scoped(opcode); printf("\n"); } return 0; } $ mipsel-linux-gnu-gcc -std=gnu89 -static test.c && \ qemu-mipsel a.out opcode = 1: * switch scoped bc_false = 4 * function scoped bc_false = 4 opcode = 2: * switch scoped bc_false = 4 * function scoped bc_false = 4 opcode = 3: * switch scoped bc_false = 2147483004 * function scoped bc_false = 0 opcode = 4: * switch scoped bc_false = 2147483004 * function scoped bc_false = 0 $ clang -std=gnu89 --target=mipsel-linux-gnu -m32 -static test.c && \ qemu-mipsel a.out opcode = 1: * switch scoped bc_false = 4 * function scoped bc_false = 4 opcode = 2: * switch scoped bc_false = 4 * function scoped bc_false = 4 opcode = 3: * switch scoped bc_false = 2147483004 * function scoped bc_false = 0 opcode = 4: * switch scoped bc_false = 2147483004 * function scoped bc_false = 0 Move the definition up so that we get the right behavior and mark it __maybe_unused as it will not be used when CONFIG_MIPS_FP_SUPPORT isn't enabled. Fixes: 6a1cc218b9cc ("MIPS: branch: Remove FP branch handling when CONFIG_MIPS_FP_SUPPORT=n") Link: https://github.com/ClangBuiltLinux/linux/issues/603 Signed-off-by: Nathan Chancellor Signed-off-by: Paul Burton Cc: Ralf Baechle Cc: James Hogan Cc: Nick Desaulniers Cc: linux-mips@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: clang-built-linux@googlegroups.com Signed-off-by: Sasha Levin --- arch/mips/kernel/branch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/mips/kernel/branch.c b/arch/mips/kernel/branch.c index 180ad081afcf9..c2d88c1dcc0f8 100644 --- a/arch/mips/kernel/branch.c +++ b/arch/mips/kernel/branch.c @@ -58,6 +58,7 @@ int __mm_isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn, unsigned long *contpc) { union mips_instruction insn = (union mips_instruction)dec_insn.insn; + int __maybe_unused bc_false = 0; if (!cpu_has_mmips) return 0; @@ -139,7 +140,6 @@ int __mm_isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn, #ifdef CONFIG_MIPS_FP_SUPPORT case mm_bc2f_op: case mm_bc1f_op: { - int bc_false = 0; unsigned int fcr31; unsigned int bit; -- 2.20.1