Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2077110rdb; Mon, 9 Oct 2023 11:41:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE2yIPFPxB9792WXP0wXoQ23YK5x7EBHG1dku9+s3CBZ51gw9P0iQDgGd3JYXdMRjRI/Yh3 X-Received: by 2002:a05:6a20:da8b:b0:16c:1340:c621 with SMTP id iy11-20020a056a20da8b00b0016c1340c621mr12695728pzb.31.1696876872746; Mon, 09 Oct 2023 11:41:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696876872; cv=none; d=google.com; s=arc-20160816; b=VBrG5tFNF/AG5Vm66FpwavgsmwDmUcgeDarrNm/ekpJPYZDWdz29w2PebHImB29KhH VncucF62DA6YBo8oOxwExA+GtZaLJkPJEyW73dzpcWuBGRwfH8OR9YvbDm2hRBoCPEkf 17uYB+AiNia8ktCRGQuZL80ZLbpEN+1H8CZnuXTm57Io/apqjvrAMXn97v+dbQiR10ki +81RHiusSupkyYslHvZCnxLU6zcbn/IhQiomexJvNHLKGJYfhBUIhrvKkCU5z9eh+BkB 1SjBO15XVbF+MKawWWFvRyxmgkWq5b95VxOFAL6LC/F3Y3da20IBF6HkEKt0BqzbrXPM RiXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=JGGlE54ge9XxgsvPeqIZ7isbDlHsMUv/MJYLVA09opo=; fh=8uoRd8OfBKdrcgzCS0TCbKG83gg6rx5b6zeE6Tx82zI=; b=wvevB35G2Qh3YAs0XRlK5aNtIqBZerhR930sC+bQIoVrKze0GK7u8Ad6LIwyH4TnIE QWVBry8TT/uD+QpB88Gl2zzuJOcIMj3smh/nISBXowvENI0VW4eQWfoibSSxqJTLqnew T5ATNIWLg5vlhVHwuQwXsWIS1g4HMIcKaV4Xi9wpYEwLdYSb8GYjEeDiNUaCCYoRRG+T BcQuHQWE7i7p/hoFXgVb9yv118CVxK6uKDBrjWB/UyZ4MfKmMUm9GIVigfhRAQa0X4QX HsOPr0zub42uFUMoZgJc4A8rN2g+WlcQf3Qxk9ro5bmzD7V4pAaUhDYuQ/qEc+Sfz+fP E/AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HPZgNN8l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id u187-20020a6279c4000000b0068e3efffe2csi7587098pfc.243.2023.10.09.11.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 11:41:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HPZgNN8l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 4BF14802D468; Mon, 9 Oct 2023 11:41:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378366AbjJISkG (ORCPT + 99 others); Mon, 9 Oct 2023 14:40:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378250AbjJISjw (ORCPT ); Mon, 9 Oct 2023 14:39:52 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00708FF for ; Mon, 9 Oct 2023 11:39:47 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a21c283542so84080847b3.3 for ; Mon, 09 Oct 2023 11:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696876787; x=1697481587; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=JGGlE54ge9XxgsvPeqIZ7isbDlHsMUv/MJYLVA09opo=; b=HPZgNN8loVefaOMfnRHnLVQVv2af1+7RIMbdemt0ihqTnrd+eC09lwm75mFfpYfoK8 VuM7z5hvPEqcV4xKoabEexIrQXkuMOBoXOzdovVPUOYM7Co1+/FnIRdDj13p3os/Rw7s NI8p7mPr7mM5ZF4uZ1mpG8YUhvyXuFinhqEKXJ+MQu3lrzW6kz4bJP3lMkttN6Hqxorz mHe7KnritTalDR6fFTBGMfrTMXulwEzrUJ6mji+Y2of/4EV33s2AeShAbwxSMRJ+d02t dZitQgZz34BI/Fy+TBjVTcAzYr64CsOm6jp1TlVN3L0JNxAf97JGub/g2KK4QBxJEYCZ lAGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696876787; x=1697481587; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JGGlE54ge9XxgsvPeqIZ7isbDlHsMUv/MJYLVA09opo=; b=c7LHh6c68UBcV7NEAQ6dnSg0xlbdU2sE56rJHH+sODekPGfjEUnm6sONX5YtI9flgl kP8SzQVAN4zk7HTYSuUukOE14Gyk33gQ2wReAODCPwDymV9H1G5/MZdKfOBt+a/JDDTV S3KzUfCT14Y5UXRs0lBzDqc5mdm08M15MW5MmCk8ouuz6ESu7cHS057ZUbNCJJA8r0O+ F1/upvSHAcCVz/WjiVrSQSqQ8uNqlZp5Djj9gpE7gjS6XNhW1bu93AT1grxRHi9nG9R+ m3LR8gNlmyOEA3+60Q/0oFqR7w9Rfvq2D4taK4XQSXHxiu8gwLcdravgAX+KEU3fJPLG ZzwQ== X-Gm-Message-State: AOJu0YwvTnfpYyENraTCuZoGUxCLZByTF/NVWcWBdI8C429371HLI+7q 5mTDylk7edg7uOeElFiYG2YF0h28nazi X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:ac4a:9b94:7158:3f4e]) (user=irogers job=sendgmr) by 2002:a25:c243:0:b0:d89:4d2c:d846 with SMTP id s64-20020a25c243000000b00d894d2cd846mr246744ybf.12.1696876787012; Mon, 09 Oct 2023 11:39:47 -0700 (PDT) Date: Mon, 9 Oct 2023 11:39:10 -0700 In-Reply-To: <20231009183920.200859-1-irogers@google.com> Message-Id: <20231009183920.200859-10-irogers@google.com> Mime-Version: 1.0 References: <20231009183920.200859-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Subject: [PATCH v3 08/18] perf mem-events: Avoid uninitialized read From: Ian Rogers To: Nathan Chancellor , Nick Desaulniers , Tom Rix , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Yang Jihong , Huacai Chen , Ming Wang , Kan Liang , Ravi Bangoria , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 09 Oct 2023 11:41:03 -0700 (PDT) pmu should be initialized to NULL before perf_pmus__scan loop. Fix and shrink the scope of pmu at the same time. Issue detected by clang-tidy. Fixes: 5752c20f3787 ("perf mem: Scan all PMUs instead of just core ones") Signed-off-by: Ian Rogers --- tools/perf/util/mem-events.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c index 39ffe8ceb380..954b235e12e5 100644 --- a/tools/perf/util/mem-events.c +++ b/tools/perf/util/mem-events.c @@ -185,7 +185,6 @@ int perf_mem_events__record_args(const char **rec_argv, int *argv_nr, { int i = *argv_nr, k = 0; struct perf_mem_event *e; - struct perf_pmu *pmu; for (int j = 0; j < PERF_MEM_EVENTS__MAX; j++) { e = perf_mem_events__ptr(j); @@ -202,6 +201,8 @@ int perf_mem_events__record_args(const char **rec_argv, int *argv_nr, rec_argv[i++] = "-e"; rec_argv[i++] = perf_mem_events__name(j, NULL); } else { + struct perf_pmu *pmu = NULL; + if (!e->supported) { perf_mem_events__print_unsupport_hybrid(e, j); return -1; -- 2.42.0.609.gbb76f46606-goog