Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759468AbcJQWTs (ORCPT ); Mon, 17 Oct 2016 18:19:48 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:61552 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757573AbcJQWTU (ORCPT ); Mon, 17 Oct 2016 18:19:20 -0400 From: Arnd Bergmann To: Jiri Kosina Cc: Linus Torvalds , linux-kernel@vger.kernel.org, Arnd Bergmann , x86@kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "Luis R. Rodriguez" Subject: [PATCH 22/28] x86: apm: avoid uninitialized data Date: Tue, 18 Oct 2016 00:16:10 +0200 Message-Id: <20161017221650.1902729-3-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20161017220342.1627073-1-arnd@arndb.de> References: <20161017220342.1627073-1-arnd@arndb.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:r+7J5YGUsRdUhvrx7OGtOFRNOLrZYKr3Vo35KVOAB698/cr+iqr 7c7dN30GM7wFKxaLMiQ9tqQsgfcSs/wRyrAyUzM862P+N4EUtyntxxWstudZWDFQONlfPap MDJy34x2uboczcbKEBFR6nOen9WfS8IQ2hHMn91H8L9N2CWjxbZaHUG0Ahs1UGuy1a4Wou7 vzXGAO8BdvZhQnEWaWZgg== X-UI-Out-Filterresults: notjunk:1;V01:K0:vOc0iNaaG8U=:2zN7H/kR9EtM2iUws9LCPP 7c8vIvLgiBLcPjlTpCYrNVOZwCQkXIZu7GEWNGWbSlbGEXQV4wg4kmUw3EeJQ+x7aY/Jmf1Tb QI4Nf2Oa3inWH+yO/EkpIvJDv+gFMQnvsE1gh/OpUvCnjze9VOKTz/ZbOcHI004e5sr263MZy SF4RWzfOhmwwTXM92A3WvAHYTqoQ+WpPubub0tOXLCubPgQcsnNBrj/+vgUnct6W5KSK79ea2 AAfjl/lQt9Mmwp73oZOJQsU1dxgqKUE1tnpYAImtjS2X1g6xchBVTVDQQh7CEzoj/QNZN/A8n PP6huOCKE2jv8F0vEj7fdvQhOrbei4EviKYTekzOSxE0qKRDAC2DBqsYwSZatfaBRFz7B+MtR XKktJqxDqKkpPT8DHr8ZYV5wIaKcpgr2N6VLthEYiTTA1327+y4TcDdi0r/3EHLANCNrJl05Y DLlhJDRQsNnjTctVqFd1DUB2lBd2g+pGHcVuQ7ryw6zqWKnV81Y5fRcFRP0ckkANpj2c4MDCy ABqYmImo383ATcnR4IceDlqLT4kEmws5ukl5CQKMXat54WMeSM45vtYj0KQ9kGrdo2o16YskY MYeWuPh2rqEvRgNBFFuM1psppp/uCTfAMbn6+SD9vNuAKoav1XwRfhwZ25jlyc/bBBHATL7DL uWLjepzNoYfl8dsPYTbXdK7JuUf9waFURtJ/CRRH8jRFBBgla6u1pfVL1znCchqNv2u+owp2h thxdks280gh1ro3Z Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1643 Lines: 41 apm_bios_call() can fail, and return a status in its argument structure. If that status however is zero during a call from apm_get_power_status(), we end up using data that may have never been set, as reported by "gcc -Wmaybe-uninitialized": arch/x86/kernel/apm_32.c: In function ‘apm’: arch/x86/kernel/apm_32.c:1729:17: error: ‘bx’ may be used uninitialized in this function [-Werror=maybe-uninitialized] arch/x86/kernel/apm_32.c:1835:5: error: ‘cx’ may be used uninitialized in this function [-Werror=maybe-uninitialized] arch/x86/kernel/apm_32.c:1730:17: note: ‘cx’ was declared here arch/x86/kernel/apm_32.c:1842:27: error: ‘dx’ may be used uninitialized in this function [-Werror=maybe-uninitialized] arch/x86/kernel/apm_32.c:1731:17: note: ‘dx’ was declared here This changes the function to return "APM_NO_ERROR" here, which makes the code more robust to broken BIOS versions, and avoids the warning. Cc: x86@kernel.org Signed-off-by: Arnd Bergmann --- arch/x86/kernel/apm_32.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c index c7364bd..51287cd 100644 --- a/arch/x86/kernel/apm_32.c +++ b/arch/x86/kernel/apm_32.c @@ -1042,8 +1042,11 @@ static int apm_get_power_status(u_short *status, u_short *bat, u_short *life) if (apm_info.get_power_status_broken) return APM_32_UNSUPPORTED; - if (apm_bios_call(&call)) + if (apm_bios_call(&call)) { + if (!call.err) + return APM_NO_ERROR; return call.err; + } *status = call.ebx; *bat = call.ecx; if (apm_info.get_power_status_swabinminutes) { -- 2.9.0