From patchwork Wed Mar 8 22:59:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 66510 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp638442wrd; Wed, 8 Mar 2023 15:33:03 -0800 (PST) X-Google-Smtp-Source: AK7set/SXtTtRz/wDzwO44im9WkGcMFzJNvydD/685qBDliMaMQ1XbvrMYy25tiKXZjXFIE9tOwg X-Received: by 2002:a05:6a20:548a:b0:cb:e735:65a5 with SMTP id i10-20020a056a20548a00b000cbe73565a5mr25463810pzk.40.1678318383350; Wed, 08 Mar 2023 15:33:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678318383; cv=none; d=google.com; s=arc-20160816; b=eCDaHnZrGzh30UBwlTfQUOkOrQ9lvSjOTRVPF6ER8aJeN+vN14N5YXjb4zCB88Hiv1 uiHIqzUr6yYMbpSWIHj1yrfk7osvnuUAQ4sZCnRPeVMBSIBL/Yp2WN6IkVPXHtLSZ9WX VRh6NBPQYzdVPznCIqvNqIrYvqmCD7otIv50xNc8N1H5UbuMPr6AAnNsI3jtNCKZcHPL Ba3ZZj0gnaZ6WSFePWPgOG53UDX3r8ROAnu+Pzl837blUxvTqqKnOkf4bPt/ULokm7ow 27MWvC1KllbfmG3h8ZP6ees1h1qmAG9Tf8nTWQFSOL2ozu3I0siHlPZIdiRv3vVAzDsm XGvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=dcvWMdLTJ1iuXhAaTLlBF3OqMzr4/MuwhIZh3sQrcPM=; b=j/gQdJyyFgocp3PulfggEnWP/YdOy9qHJPeRcdoTl/zz5gRXiaZ/mfLPbRNhlrIQ3m XTxO0QtJOkgbwT6Nep6qwwbz10NCLKpkK/Ltk2fsu3zkw+BCVYqvKn5DDHY5hV+eustg kCnb0XdyBq3E9YmS+8DgCajM8onY/synm+emHSPd87CnM8VFR70UBJU+S2uIqXvvEeVT +hFis/RGGbBz4LSRSAgcGUs1ltLFJ1KJRwWteOs3AVyti/QtTEz3P1wd6Cq9ShNeTHi5 KVq8zKDHWDhw3SnCCDEysJQlXfBZ+P9aFUbjxeaNNIrK9fdncnw+OVzYFH+D2Call1is JyIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PZRWXsWy; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y127-20020a633285000000b004fb7d5d316esi15546651pgy.404.2023.03.08.15.32.50; Wed, 08 Mar 2023 15:33:03 -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; dkim=pass header.i=@google.com header.s=20210112 header.b=PZRWXsWy; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229940AbjCHXAy (ORCPT + 99 others); Wed, 8 Mar 2023 18:00:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230058AbjCHXA2 (ORCPT ); Wed, 8 Mar 2023 18:00:28 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B36E6D330D for ; Wed, 8 Mar 2023 15:00:14 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id o3-20020a257303000000b00a131264017aso206423ybc.20 for ; Wed, 08 Mar 2023 15:00:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678316414; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dcvWMdLTJ1iuXhAaTLlBF3OqMzr4/MuwhIZh3sQrcPM=; b=PZRWXsWyADHy4mHeUXfY7eIe/xrWmdkDJrMwb2jSMuPSbFIhhmJzZ1o0/wjrUqNstt cqtNrNIfM5xuzRRHpDGe9KgHWeCS1PN7gzn2xt4jLpq06QR2klOwgxB7GtHWAUsCwqPI eoEqtmRdgmFINGPcsI+w4704lHFMvDkZYFWvALIWLS+RVWM7dHzTFEMpNTjSkjgpeNqI 6HjGyK4aGU+gEF6gYHMayjhtdhdJHW44d2PA0zp2OGqdyXV/QRp78bXUC15kbkUb70n9 vwfjR2VH6Y+by5dQIfLTsh1tb49rv8CQbdFX3gw+M1+dzhmJhSI1wpR7BCmJsH/QHzdq HUjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678316414; h=cc: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=dcvWMdLTJ1iuXhAaTLlBF3OqMzr4/MuwhIZh3sQrcPM=; b=3NJNedIRAWfzrrgnEFcRUuAzN2hCmV6mz5RTb+UjZDTGEgTI5Ybaa3+dpyzK6jr3+V aOE4UsEuxCFAKlKkJyA+l1kY1jYWpE9g6WNIV40j8f5T3iO/4qcacSu23kxf4Xb3OSFn ZWwRuNPQiiQRmYdzdT+wBuA+D2mwvfmb+8FRXXlG2tcii4a7sJlyS4JdfjKBPhEF+pcE qKoCpMzxhYYmDEt9R2s+APmrapxjNMRPymjkRtIARhdeEnWjZF6rMdeNG/I4xSBxJS7r jzTdos8mYCunP8UStpMQuR2J4Hc30O7Jw8Kfl4tVCSlqEQxE6o22Yap5d03mk3Kke7n6 trKQ== X-Gm-Message-State: AO0yUKXpwIKidLlWi2+vStmiyKOEyZBF+EMS0ZN91LVOlcA+LaU6VeNC vypZm+GyeKt79n7mz2OgGT08NAoiCfsJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:5292:ba14:c261:246a]) (user=irogers job=sendgmr) by 2002:a5b:b03:0:b0:ad7:b81e:69bd with SMTP id z3-20020a5b0b03000000b00ad7b81e69bdmr9346841ybp.2.1678316413963; Wed, 08 Mar 2023 15:00:13 -0800 (PST) Date: Wed, 8 Mar 2023 14:59:08 -0800 In-Reply-To: <20230308225912.1960990-1-irogers@google.com> Message-Id: <20230308225912.1960990-8-irogers@google.com> Mime-Version: 1.0 References: <20230308225912.1960990-1-irogers@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Subject: [PATCH v4 07/11] perf parse-events: Pass ownership of the group name From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Mark Rutland , Adrian Hunter , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kan Liang , Zhengjun Xing , Ravi Bangoria , "Steinar H. Gunderson" , Kim Phillips , Florian Fischer , James Clark , Suzuki Poulouse , Sean Christopherson , Leo Yan , John Garry , Kajol Jain , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1759844377138654278?= X-GMAIL-MSGID: =?utf-8?q?1759844377138654278?= Pass ownership of the group name rather than copying and freeing the original. This saves a memory allocation and copy. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 3 ++- tools/perf/util/parse-events.y | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 0336ff27c15f..1be454697d57 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1761,6 +1761,7 @@ parse_events__set_leader_for_uncore_aliase(char *name, struct list_head *list, handled: ret = 1; + free(name); out: free(leaders); return ret; @@ -1786,7 +1787,7 @@ void parse_events__set_leader(char *name, struct list_head *list, leader = arch_evlist__leader(list); __perf_evlist__set_leader(list, &leader->core); - leader->group_name = name ? strdup(name) : NULL; + leader->group_name = name; list_move(&leader->core.node, list); } diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index be8c51770051..541b8dde2063 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -202,8 +202,8 @@ PE_NAME '{' events '}' struct list_head *list = $3; inc_group_count(list, _parse_state); + /* Takes ownership of $1. */ parse_events__set_leader($1, list, _parse_state); - free($1); $$ = list; } |