From patchwork Fri Jan 24 09:31:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 11350095 X-Patchwork-Delegate: paulburton@kernel.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F1739139A for ; Fri, 24 Jan 2020 11:37:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C6896206F0 for ; Fri, 24 Jan 2020 11:37:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865870; bh=IMvMgTvmXA/X0cRlwO7yY8WTvXjfr41rRPJBUM6+wz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=iRAQuwQxyyc/4lX47BvSO0jidYK8obA2sGLqqTKdRwHSVIl44Muw4tBj4WeWg6Zba qYXfWXJCcDJ/wpAKn5QILtOEKa2pca1DosfgrXvF8F4LkIKoxkYtH9yJcpj9/sijke nxxqSasQIuXwMdodlRntzNUXuiDfci4GNNeOfuPU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404008AbgAXLag (ORCPT ); Fri, 24 Jan 2020 06:30:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:48346 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391679AbgAXLag (ORCPT ); Fri, 24 Jan 2020 06:30:36 -0500 Received: from localhost (ip-213-127-102-57.ip.prioritytelecom.net [213.127.102.57]) (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 2577C24658; Fri, 24 Jan 2020 11:30:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865434; bh=IMvMgTvmXA/X0cRlwO7yY8WTvXjfr41rRPJBUM6+wz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u3Q/+hsIzvWbyFP4yFTW6dATfNgOKQvIoGxXca5TdOle40LvJSH5S1MnPWSGcCsqS aJuf1xWG8Rl4yafRRJ/PSV2DDdfmQMP2yhBQsiw0dCt71cDuuFrd2TsZr2KXd1JVn3 0ySjcSBOw+oVVbuqzzRPxfVqDdQkMxGhpVjpg/sw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nathan Chancellor , Eli Friedman , Nick Desaulniers , Paul Burton , ralf@linux-mips.org, jhogan@kernel.org, "Maciej W. Rozycki" , Hassan Naveed , Stephen Kitt , Serge Semin , Mike Rapoport , Andrew Morton , Michal Hocko , linux-mips@vger.kernel.org, clang-built-linux@googlegroups.com, Sasha Levin Subject: [PATCH 4.19 522/639] mips: avoid explicit UB in assignment of mips_io_port_base Date: Fri, 24 Jan 2020 10:31:32 +0100 Message-Id: <20200124093154.161499157@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124093047.008739095@linuxfoundation.org> References: <20200124093047.008739095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Nick Desaulniers [ Upstream commit 12051b318bc3ce5b42d6d786191008284b067d83 ] The code in question is modifying a variable declared const through pointer manipulation. Such code is explicitly undefined behavior, and is the lone issue preventing malta_defconfig from booting when built with Clang: If an attempt is made to modify an object defined with a const-qualified type through use of an lvalue with non-const-qualified type, the behavior is undefined. LLVM is removing such assignments. A simple fix is to not declare variables const that you plan on modifying. Limiting the scope would be a better method of preventing unwanted writes to such a variable. Further, the code in question mentions "compiler bugs" without any links to bug reports, so it is difficult to know if the issue is resolved in GCC. The patch was authored in 2006, which would have been GCC 4.0.3 or 4.1.1. The minimal supported version of GCC in the Linux kernel is currently 4.6. For what its worth, there was UB before the commit in question, it just added a barrier and got lucky IRT codegen. I don't think there's any actual compiler bugs related, just runtime bugs due to UB. Link: https://github.com/ClangBuiltLinux/linux/issues/610 Fixes: 966f4406d903 ("[MIPS] Work around bad code generation for .") Reported-by: Nathan Chancellor Debugged-by: Nathan Chancellor Suggested-by: Eli Friedman Signed-off-by: Nick Desaulniers Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor Signed-off-by: Paul Burton Cc: ralf@linux-mips.org Cc: jhogan@kernel.org Cc: Maciej W. Rozycki Cc: Hassan Naveed Cc: Stephen Kitt Cc: Serge Semin Cc: Mike Rapoport Cc: Andrew Morton Cc: Michal Hocko 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/include/asm/io.h | 14 ++------------ arch/mips/kernel/setup.c | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/arch/mips/include/asm/io.h b/arch/mips/include/asm/io.h index 54c730aed3271..df1eaa3652794 100644 --- a/arch/mips/include/asm/io.h +++ b/arch/mips/include/asm/io.h @@ -62,21 +62,11 @@ * instruction, so the lower 16 bits must be zero. Should be true on * on any sane architecture; generic code does not use this assumption. */ -extern const unsigned long mips_io_port_base; +extern unsigned long mips_io_port_base; -/* - * Gcc will generate code to load the value of mips_io_port_base after each - * function call which may be fairly wasteful in some cases. So we don't - * play quite by the book. We tell gcc mips_io_port_base is a long variable - * which solves the code generation issue. Now we need to violate the - * aliasing rules a little to make initialization possible and finally we - * will need the barrier() to fight side effects of the aliasing chat. - * This trickery will eventually collapse under gcc's optimizer. Oh well. - */ static inline void set_io_port_base(unsigned long base) { - * (unsigned long *) &mips_io_port_base = base; - barrier(); + mips_io_port_base = base; } /* diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 8aaaa42f91ed6..e87c98b8a72c0 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -76,7 +76,7 @@ static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE; * mips_io_port_base is the begin of the address space to which x86 style * I/O ports are mapped. */ -const unsigned long mips_io_port_base = -1; +unsigned long mips_io_port_base = -1; EXPORT_SYMBOL(mips_io_port_base); static struct resource code_resource = { .name = "Kernel code", }; From patchwork Fri Jan 24 09:33:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 11350093 X-Patchwork-Delegate: paulburton@kernel.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B14BE109A for ; Fri, 24 Jan 2020 11:35:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 850BD214DB for ; Fri, 24 Jan 2020 11:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865733; bh=pd/qIKtPgckZAMIldyVkQ5zIky2l2yZfKCFKZb3UNHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=G6k4S9+qFLGYTcFXkScfP0oSCQDl4UKCiPRUpVoYJbUO4bDXldNziAyLnleW6XLGC dPwl6cUjqeSKOqMnePQBTRqQKeYupgDcfRGqrznQBYuXtkM9Gmle/mfT6EE6593ujM mbtk3GsPTLGVsFq9/8SOiBdBvkDI9FY7cuhXLAFc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404580AbgAXLfc (ORCPT ); Fri, 24 Jan 2020 06:35:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:55532 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388424AbgAXLfb (ORCPT ); Fri, 24 Jan 2020 06:35:31 -0500 Received: from localhost (ip-213-127-102-57.ip.prioritytelecom.net [213.127.102.57]) (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 004CA206D4; Fri, 24 Jan 2020 11:35:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865730; bh=pd/qIKtPgckZAMIldyVkQ5zIky2l2yZfKCFKZb3UNHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bTSweiKJ2WayI4TWXujJ8IQrsW5reN9PdiJhcZ46DHSgjsxTwZQXkucrN0SlKfzyI g0rvjre04HH2Hhx1tyZWVL7omF14YI3YWkpyOKdJ3kLeB0P3ObSBPrKGt6CNuQXI2R OsMbsEnEzN5nI/4HGAim5Um5m+iQH6A9YU9idpfQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tiezhu Yang , Paul Burton , Ralf Baechle , James Hogan , Huacai Chen , Jiaxun Yang , linux-mips@vger.kernel.org, Sasha Levin Subject: [PATCH 4.19 622/639] MIPS: Loongson: Fix return value of loongson_hwmon_init Date: Fri, 24 Jan 2020 10:33:12 +0100 Message-Id: <20200124093207.538374289@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124093047.008739095@linuxfoundation.org> References: <20200124093047.008739095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Tiezhu Yang [ Upstream commit dece3c2a320b0a6d891da6ff774ab763969b6860 ] When call function hwmon_device_register failed, use the actual return value instead of always -ENOMEM. Fixes: 64f09aa967e1 ("MIPS: Loongson-3: Add CPU Hwmon platform driver") Signed-off-by: Tiezhu Yang Signed-off-by: Paul Burton Cc: Ralf Baechle Cc: James Hogan Cc: Huacai Chen Cc: Jiaxun Yang Cc: linux-mips@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Sasha Levin --- drivers/platform/mips/cpu_hwmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/platform/mips/cpu_hwmon.c b/drivers/platform/mips/cpu_hwmon.c index f66521c7f8462..98128374d710a 100644 --- a/drivers/platform/mips/cpu_hwmon.c +++ b/drivers/platform/mips/cpu_hwmon.c @@ -159,7 +159,7 @@ static int __init loongson_hwmon_init(void) cpu_hwmon_dev = hwmon_device_register(NULL); if (IS_ERR(cpu_hwmon_dev)) { - ret = -ENOMEM; + ret = PTR_ERR(cpu_hwmon_dev); pr_err("hwmon_device_register fail!\n"); goto fail_hwmon_device_register; }