From patchwork Mon Dec 12 15:55:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 32431 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2327129wrr; Mon, 12 Dec 2022 08:08:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf5/lIUOqrCVVS4MBTvRwjiTlFOVC38YD1dCarbnXg4yRh636AiZegQ1olZY//tG4OMuhoiM X-Received: by 2002:a05:6402:1ccc:b0:461:8be6:1ac4 with SMTP id ds12-20020a0564021ccc00b004618be61ac4mr15560188edb.20.1670861320192; Mon, 12 Dec 2022 08:08:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670861320; cv=none; d=google.com; s=arc-20160816; b=H4AYU8zkyQflncYx2TRdDo2aO+mUvNeh2IIHuEPZCgwCoWyAXwOvOqd+NwoIN/7oIn jVF6B4x/aCpjhRMJ5Ny2WDlMmjHJi8SYy4WBfdO9GnZkDxMtR7vGO042PFpEr9BQI4EQ HTUOsltzsmt2++9jX8jz6MI5EDhorBvxs3RPok/rf3cGHQnWEbcvZz2NIH8YedBjqJAK mlCxCQLZOB6Kg95+07sVtoU5KrH6x2AqFAMgCwO48Ws3Mbv5yWv1X2cU0+wJH/YXHeBT R4Y1CGDwAIWiIzEKAWNlLwJoXAL6IBCF6R4Y9vFFr6qzdCCjjTbLZtbWuvaEukrJwKpf vk+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=oBdGslY/MXeWJolkGr+JMvEApF++GsEr9E3pzoC6JdY=; b=mSmZtjFeypTRKEpoAliMcoZoTQ8ucJESB7gD08kmOrdC6bjdGps5Da16nfdPbmuV/K OxpBqnhri62LDVe4Nww0SMmu+WWAvGluXxXLEytYZeIwtYRWSd7lN4ZZpYqvIw1xLKeP bxKTFmRozj43crlRqz93m0+08ju8r/c0A/ut1Q1SS1q6drfMjxCaPUvouRn2lgdPHW/F JNRzrNoIjYu4x2gra387aLyKzMM5UTwF5s9A8Ht3NF7Xzppqn+z+IqFHLKBEXG2cNXk3 B4vMeP9yyVZaeY7ZbXmWA0NuZZ0icZ4/DqRRNbUjswhXrNSYisnth60/nWHmSXI5v5Va P7ag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i28-20020a0564020f1c00b0046b1abd7884si7331243eda.108.2022.12.12.08.08.11; Mon, 12 Dec 2022 08:08:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232537AbiLLP4D (ORCPT + 99 others); Mon, 12 Dec 2022 10:56:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232636AbiLLPz5 (ORCPT ); Mon, 12 Dec 2022 10:55:57 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 52ED812AE6; Mon, 12 Dec 2022 07:55:53 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 963411FB; Mon, 12 Dec 2022 07:56:33 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 949133F71E; Mon, 12 Dec 2022 07:55:50 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org Cc: Al.Grant@arm.com, James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Will Deacon , Mike Leach , Leo Yan , Mathieu Poirier , Suzuki K Poulose , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH 4/5] perf: cs-etm: Cleanup cs_etm__process_auxtrace_info() Date: Mon, 12 Dec 2022 15:55:12 +0000 Message-Id: <20221212155513.2259623-5-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221212155513.2259623-1-james.clark@arm.com> References: <20221212155513.2259623-1-james.clark@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752025079246987897?= X-GMAIL-MSGID: =?utf-8?q?1752025079246987897?= hdr is a copy of 3 values of ptr and doesn't need to be long lived. So just use ptr instead which means the malloc and the extra error path can be removed to simplify things. Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index bf8fbcec2d69..ab30591a6c6a 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2888,7 +2888,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, int num_cpu, trcidr_idx; int err = 0; int i, j; - u64 *ptr, *hdr = NULL; + u64 *ptr = NULL; u64 **metadata = NULL; u64 hdr_version; @@ -2914,15 +2914,8 @@ int cs_etm__process_auxtrace_info(union perf_event *event, return -EINVAL; } - hdr = zalloc(sizeof(*hdr) * CS_HEADER_VERSION_MAX); - if (!hdr) - return -ENOMEM; - - /* Extract header information - see cs-etm.h for format */ - for (i = 0; i < CS_HEADER_VERSION_MAX; i++) - hdr[i] = ptr[i]; - num_cpu = hdr[CS_PMU_TYPE_CPUS] & 0xffffffff; - pmu_type = (unsigned int) ((hdr[CS_PMU_TYPE_CPUS] >> 32) & + num_cpu = ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; + pmu_type = (unsigned int) ((ptr[CS_PMU_TYPE_CPUS] >> 32) & 0xffffffff); if (dump_trace) @@ -2934,10 +2927,8 @@ int cs_etm__process_auxtrace_info(union perf_event *event, * in anything other than a sequential array is worth doing. */ traceid_list = intlist__new(NULL); - if (!traceid_list) { - err = -ENOMEM; - goto err_free_hdr; - } + if (!traceid_list) + return -ENOMEM; metadata = zalloc(sizeof(*metadata) * num_cpu); if (!metadata) { @@ -2945,6 +2936,9 @@ int cs_etm__process_auxtrace_info(union perf_event *event, goto err_free_traceid_list; } + /* Start parsing after the common part of the header */ + i = CS_HEADER_VERSION_MAX; + /* * The metadata is stored in the auxtrace_info section and encodes * the configuration of the ARM embedded trace macrocell which is @@ -3043,7 +3037,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, etm->num_cpu = num_cpu; etm->pmu_type = pmu_type; - etm->snapshot_mode = (hdr[CS_ETM_SNAPSHOT] != 0); + etm->snapshot_mode = (ptr[CS_ETM_SNAPSHOT] != 0); etm->metadata = metadata; etm->auxtrace_type = auxtrace_info->type; etm->timeless_decoding = cs_etm__is_timeless_decoding(etm); @@ -3110,7 +3104,5 @@ int cs_etm__process_auxtrace_info(union perf_event *event, zfree(&metadata); err_free_traceid_list: intlist__delete(traceid_list); -err_free_hdr: - zfree(&hdr); return err; }