From patchwork Tue Aug 27 16:44:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13779811 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 470F6C54731 for ; Tue, 27 Aug 2024 16:47:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=V0lXp0W0bnOhYd8/oaVtWkLXyFmgqh7I7qKWvQpmAlc=; b=OwQ+5aZN+Sa4eTdBhtZAznXwXH faq6xzNeX4Mwi2K/R7LLd3+G79ytnyz5a3rBJ+cOXtvCMYe91pL1GO9+jyTTUzh+jMqdDX9BNAYUg ND2JZFWkHPGulvA9h2NvQNeR3jENQw7PIJocsKq6n5HSi1+6PjxIKFZWS3LSrvcLx0ch7Y5C73Lv8 zJ+FZSRNUpyd2ipF94PMGhz8X/1u/VBAjpHk8PTR0XAXtaXdcP+3y6B1k3rfkKttbVwJlaPRCna8J 5tsEEYu+UzeFjIcr9TXJkGWeXnwWCaAhJJ5DhMT1wyEubuxwoIftGBOR2wW8UzinIosbNuhBvCrGl jRh2cYSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizLZ-0000000C8Hu-1Ga1; Tue, 27 Aug 2024 16:47:09 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizJ8-0000000C7WQ-2aJv for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 16:44:39 +0000 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 3A45F13D5; Tue, 27 Aug 2024 09:45:04 -0700 (PDT) Received: from e132581.cambridge.arm.com (e132581.arm.com [10.2.76.71]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E08393F762; Tue, 27 Aug 2024 09:44:35 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Will Deacon , Mark Rutland , Suzuki K Poulose , Mike Leach , James Clark , John Garry , Namhyung Kim , Ian Rogers , Adrian Hunter , "Liang, Kan" , Jonathan Cameron , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 2/9] perf auxtrace arm: Refactor error handling Date: Tue, 27 Aug 2024 17:44:10 +0100 Message-Id: <20240827164417.3309560-3-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827164417.3309560-1-leo.yan@arm.com> References: <20240827164417.3309560-1-leo.yan@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_094438_724497_128EF6DA X-CRM114-Status: GOOD ( 14.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Refactor the auxtrace_record__init() function to use a central place to release resources and return value. This unifies the exit flow, and allows the PMU arrays can be used throughout the function. No functional changes; this is a preparation for sequential changes. Signed-off-by: Leo Yan --- tools/perf/arch/arm/util/auxtrace.c | 35 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/tools/perf/arch/arm/util/auxtrace.c b/tools/perf/arch/arm/util/auxtrace.c index 3b8eca0ffb17..74630d2d81dc 100644 --- a/tools/perf/arch/arm/util/auxtrace.c +++ b/tools/perf/arch/arm/util/auxtrace.c @@ -125,6 +125,7 @@ struct auxtrace_record struct perf_pmu *found_etm = NULL; struct perf_pmu *found_spe = NULL; struct perf_pmu *found_ptt = NULL; + struct auxtrace_record *itr = NULL; int auxtrace_event_cnt = 0; int nr_spes = 0; int nr_ptts = 0; @@ -147,9 +148,6 @@ struct auxtrace_record found_ptt = find_pmu_for_event(hisi_ptt_pmus, nr_ptts, evsel); } - free(arm_spe_pmus); - free(hisi_ptt_pmus); - if (found_etm) auxtrace_event_cnt++; @@ -159,31 +157,36 @@ struct auxtrace_record if (found_ptt) auxtrace_event_cnt++; - if (auxtrace_event_cnt > 1) { + if (!auxtrace_event_cnt) { + /* + * Clear 'err' even if we haven't found an event - that way perf + * record can still be used even if tracers aren't present. + * The NULL return value will take care of telling the + * infrastructure HW tracing isn't available. + */ + *err = 0; + goto out; + } else if (auxtrace_event_cnt > 1) { pr_err("Concurrent AUX trace operation not currently supported\n"); *err = -EOPNOTSUPP; - return NULL; + goto out; } if (found_etm) - return cs_etm_record_init(err); + itr = cs_etm_record_init(err); #if defined(__aarch64__) if (found_spe) - return arm_spe_recording_init(err, found_spe); + itr = arm_spe_recording_init(err, found_spe); if (found_ptt) - return hisi_ptt_recording_init(err, found_ptt); + itr = hisi_ptt_recording_init(err, found_ptt); #endif - /* - * Clear 'err' even if we haven't found an event - that way perf - * record can still be used even if tracers aren't present. The NULL - * return value will take care of telling the infrastructure HW tracing - * isn't available. - */ - *err = 0; - return NULL; +out: + free(arm_spe_pmus); + free(hisi_ptt_pmus); + return itr; } #if defined(__arm__)