Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1053550ybj; Fri, 20 Sep 2019 04:27:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+hvSsqkXRXzIZw0ntY/jUCABulGiKmd056G/Il1h+6EoK7+nXrAkH48V74eyDFNNb3Pqd X-Received: by 2002:a17:906:4bc7:: with SMTP id x7mr18691032ejv.16.1568978822693; Fri, 20 Sep 2019 04:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568978822; cv=none; d=google.com; s=arc-20160816; b=v1OGwfaYpjuC5dbBgSMp1402hQGp5JhZUl85P2X3pAdqRRqv8217XlyQ60Xldu3Euz HK0gETHqOYZrj3ap+HQWpZyIFkzzOfsMxc10g8uH0ngZt71rIsQG2Wfwngh/hk3Kw8DV W742es+9ANMWKpFCbPjYtelkIXdPxi4ms+suJztLVsGUQM1FEhKEWROs63dR1WcWW0D5 igPvb5XbGiyUzbg732kA4kc5ZZKsbRDdXNz0BCJclLzQlCUbopFq/MWFBo9NG3RnBzVf TH10zQ+b6Rdb9Ld5l1PITlju/n8DaVpFznyHmKcotjWN+qk/u+n1cigfjYM24vsTjIIl /Eiw== 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=mcvINUm4UtjOj4i6tXJTL3ETc92O0W1vBF2m5PXvh8k=; b=fPtfj6j66+CrXvGGXegIGMQ2aZwIIh8/xqZARmdWsmzau6XF+LvWYMmLW9Xc5ss+ab GrsaIMtKQnywZ6SMhU4gUWjoG1YD7ywWV+q5dPCAHZzi4MZJ1OmO9ttYPfdo+9lgaO4B 7L+hBezVIX2mfCYgIIgmDn+KbnZlJdQysaiAFpKXNPN4nWUsrkXdYmup4FyMjIZIZqiG 5mk6xg34ytbr2sl05GoquaQ2vE/0RLPOLoZ/XDXH5ooTcjK/1Acv4an1g4vCnPhtxIdQ CHCMSy+vUy9m+8kUZIE0y1PSGCMnXSj09+LagFpSQs4VfWlKtPR59Mv60IJdIz0V+TFQ PTJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MjYovGCo; 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 m12si1107337edc.50.2019.09.20.04.26.38; Fri, 20 Sep 2019 04:27:02 -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=MjYovGCo; 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 S2392279AbfISWOZ (ORCPT + 99 others); Thu, 19 Sep 2019 18:14:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:53908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392247AbfISWOY (ORCPT ); Thu, 19 Sep 2019 18:14:24 -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 7F2CF21927; Thu, 19 Sep 2019 22:14:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568931263; bh=mxeu4uLj13ZdTwyKcHula4thozA5vnCkalosJXisIRE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MjYovGCoG8I5KTuC6nWnvEZ35l2YmFTy81kQTEDMcFWukWKO6VOSjemJ0JkqDfmWX Ve/Js3jq8v3kHNnrYhWR5dLPQAp4IiZQMHjpfN7DuOrLgukXwYLVxwCM02pXnxomK9 i2gfrCk3fGhtmciOT+rIj37jnNW4VdfakL6cX6o8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ben Hutchings , Len Brown , Sasha Levin Subject: [PATCH 4.19 62/79] tools/power x86_energy_perf_policy: Fix "uninitialized variable" warnings at -O2 Date: Fri, 20 Sep 2019 00:03:47 +0200 Message-Id: <20190919214813.091419115@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190919214807.612593061@linuxfoundation.org> References: <20190919214807.612593061@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: Ben Hutchings [ Upstream commit adb8049097a9ec4acd09fbd3aa8636199a78df8a ] x86_energy_perf_policy first uses __get_cpuid() to check the maximum CPUID level and exits if it is too low. It then assumes that later calls will succeed (which I think is architecturally guaranteed). It also assumes that CPUID works at all (which is not guaranteed on x86_32). If optimisations are enabled, gcc warns about potentially uninitialized variables. Fix this by adding an exit-on-error after every call to __get_cpuid() instead of just checking the maximum level. Signed-off-by: Ben Hutchings Signed-off-by: Len Brown Signed-off-by: Sasha Levin --- .../x86_energy_perf_policy.c | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c index 65bbe627a425f..bbef8bcf44d6d 100644 --- a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c +++ b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c @@ -1260,6 +1260,15 @@ void probe_dev_msr(void) if (system("/sbin/modprobe msr > /dev/null 2>&1")) err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" "); } + +static void get_cpuid_or_exit(unsigned int leaf, + unsigned int *eax, unsigned int *ebx, + unsigned int *ecx, unsigned int *edx) +{ + if (!__get_cpuid(leaf, eax, ebx, ecx, edx)) + errx(1, "Processor not supported\n"); +} + /* * early_cpuid() * initialize turbo_is_enabled, has_hwp, has_epb @@ -1267,15 +1276,10 @@ void probe_dev_msr(void) */ void early_cpuid(void) { - unsigned int eax, ebx, ecx, edx, max_level; + unsigned int eax, ebx, ecx, edx; unsigned int fms, family, model; - __get_cpuid(0, &max_level, &ebx, &ecx, &edx); - - if (max_level < 6) - errx(1, "Processor not supported\n"); - - __get_cpuid(1, &fms, &ebx, &ecx, &edx); + get_cpuid_or_exit(1, &fms, &ebx, &ecx, &edx); family = (fms >> 8) & 0xf; model = (fms >> 4) & 0xf; if (family == 6 || family == 0xf) @@ -1289,7 +1293,7 @@ void early_cpuid(void) bdx_highest_ratio = msr & 0xFF; } - __get_cpuid(0x6, &eax, &ebx, &ecx, &edx); + get_cpuid_or_exit(0x6, &eax, &ebx, &ecx, &edx); turbo_is_enabled = (eax >> 1) & 1; has_hwp = (eax >> 7) & 1; has_epb = (ecx >> 3) & 1; @@ -1307,7 +1311,7 @@ void parse_cpuid(void) eax = ebx = ecx = edx = 0; - __get_cpuid(0, &max_level, &ebx, &ecx, &edx); + get_cpuid_or_exit(0, &max_level, &ebx, &ecx, &edx); if (ebx == 0x756e6547 && edx == 0x49656e69 && ecx == 0x6c65746e) genuine_intel = 1; @@ -1316,7 +1320,7 @@ void parse_cpuid(void) fprintf(stderr, "CPUID(0): %.4s%.4s%.4s ", (char *)&ebx, (char *)&edx, (char *)&ecx); - __get_cpuid(1, &fms, &ebx, &ecx, &edx); + get_cpuid_or_exit(1, &fms, &ebx, &ecx, &edx); family = (fms >> 8) & 0xf; model = (fms >> 4) & 0xf; stepping = fms & 0xf; @@ -1341,7 +1345,7 @@ void parse_cpuid(void) errx(1, "CPUID: no MSR"); - __get_cpuid(0x6, &eax, &ebx, &ecx, &edx); + get_cpuid_or_exit(0x6, &eax, &ebx, &ecx, &edx); /* turbo_is_enabled already set */ /* has_hwp already set */ has_hwp_notify = eax & (1 << 8); -- 2.20.1