Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp552614lqh; Tue, 7 May 2024 07:17:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWrIxBjLx5SOfLg153sTgLdoYoreMI5w1nEnHqOYsyv3qzwnQFOFx6v5izQv7YFX6yoq7NmwVm2Kz+6pTZcKj5f4abK0gw+dgX5f3+cZA== X-Google-Smtp-Source: AGHT+IGL79ScSkFKsfeb1CuPUNYwcLI4zokCUKAs+S3sLWiD5GKeodEaln3GXarRZRfzzTIDWcmt X-Received: by 2002:a05:6808:1395:b0:3c9:6c32:b1ec with SMTP id c21-20020a056808139500b003c96c32b1ecmr7035264oiw.56.1715091444865; Tue, 07 May 2024 07:17:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715091444; cv=pass; d=google.com; s=arc-20160816; b=m5Z3OGMhHPXcw1iA8ik15+9ay5xgth47AWEy5E6QmsoWoFRwy1eBDkIiu4B1W/LplS Xkee3K5XLWUfBLwoBh8NRb2HOoCymk2VaWrqFvUDvXjLxaMMygAajcdV8m7B3tlvuGbV ZNUBc972fZv41h5c4ASj4rvoCEzQWBE+2XwN2GkD4ElZffsksL5+JizaT7fVL2A6G+8s wrJblg2rBUYyeCVYPiAWgCHSp7fPwWkyWEmbm2GMhP02HTNU1hwNI53Ea6C9Lt2ETuo8 yxXqGoEU+1foqQp37YcF+yBXCvdNMjwNw0PZWRIpIKGOowggVicJrOivbAjb0XeItYjU pW6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=94EkyeyW2jVaOydQ3Cktfpcow5c3gtuRLO1vyX9AjEo=; fh=z3/YlGhmWVGbDDVRrPyvN7QnpotMsOuIPt85/Od1vi8=; b=o4IRd2JF8mlcBFtybl1JE46e7dcU82fKBYhZctDUc89Q5vF6kJ1X6wGAl77hxIzbqx qsyaK/ChbaS7+4914oyGBnRPwzqSdsr+1QUdSaQEM8N0LwDBQR7FX1bJBm9SbeY4P0jX SbZ31VR62zLFhE5Jm+UVprkvwAfIhSqF6bmJPrUDFFFH8YY0W7RZQNlZDociKS1CfbxV 9JXLhCwDVHphYuK1lkXfahWcV9P2w3gQ6RE548Hv6vPVYqeuDFasW0I7/2YebombF9WU iL/xE53yYgia6CFiNuUDbLgFlyui0rP/BbWeyfpdF3B5n2a9lLzVHL/MlOyTBUY+ZO95 tSzg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-171536-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171536-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e15-20020a67fb4f000000b0047bc5754c1csi1963088vsr.10.2024.05.07.07.17.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 07:17:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171536-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-171536-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171536-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 217CE1C23F1E for ; Tue, 7 May 2024 14:17:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A58A916D9C9; Tue, 7 May 2024 14:13:26 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4CC8516C849; Tue, 7 May 2024 14:13:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715091204; cv=none; b=X9lldrCbSHcXsybgzwVxKUyKFABF/zu9jP/yCM/xUaMIdbGsFR+ya/I1qK9leckXl1vGFlltO3y70wRMHzEF3DOqrJgVeTVA621zppTFmk0AjAQ+6YPikZ+zmCFO3Gu3a9TpMTZdQSnE/i9sfB3xTn/l6c39yrRIGGxCt5zYDwI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715091204; c=relaxed/simple; bh=sE3X07S6/95vfe+bBwB2Qtkb4OMn+hxVPTR3EAq1XMs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rF4M9F3yC2QuKs1kXB6DZHFsjUDxYv9b0jrieqi7KgIZMix1Qf/AFcsGhsACNw1M6g2OMWiun20qY6F2P5znXNumHAMmRIuxfClLL0VhwBEm43VbmRhCncfhncPaiFoR2AyA/oO+0vOguEqQxxS0Rd98LZD7ziaT2CFkIqQSLiY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 595341515; Tue, 7 May 2024 07:13:29 -0700 (PDT) Received: from e127643.broadband (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 78FCB3F6A8; Tue, 7 May 2024 07:13:01 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, atrajeev@linux.vnet.ibm.com, irogers@google.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org Subject: [PATCH 2/4] perf maps: Re-use __maps__free_maps_by_name() Date: Tue, 7 May 2024 15:12:06 +0100 Message-Id: <20240507141210.195939-3-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507141210.195939-1-james.clark@arm.com> References: <20240507141210.195939-1-james.clark@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit maps__merge_in() hard codes the steps to free the maps_by_name list. It seems to not map__put() each element before freeing, and it sets maps_by_name_sorted to true after freeing, which may be harmless but is inconsistent with maps__init() and other functions. maps__maps_by_name_addr() is also quite hard to read because we already have maps__maps_by_name() and maps__maps_by_address(), but the function is only used in that place so delete it. Signed-off-by: James Clark --- tools/perf/util/maps.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index 61eb742d91e3..16b39db594f4 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -124,11 +124,6 @@ static void maps__set_maps_by_address(struct maps *maps, struct map **new) } -static struct map ***maps__maps_by_name_addr(struct maps *maps) -{ - return &RC_CHK_ACCESS(maps)->maps_by_name; -} - static void maps__set_nr_maps_allocated(struct maps *maps, unsigned int nr_maps_allocated) { RC_CHK_ACCESS(maps)->nr_maps_allocated = nr_maps_allocated; @@ -284,6 +279,9 @@ void maps__put(struct maps *maps) static void __maps__free_maps_by_name(struct maps *maps) { + if (!maps__maps_by_name(maps)) + return; + /* * Free everything to try to do it from the rbtree in the next search */ @@ -291,6 +289,9 @@ static void __maps__free_maps_by_name(struct maps *maps) map__put(maps__maps_by_name(maps)[i]); zfree(&RC_CHK_ACCESS(maps)->maps_by_name); + + /* Consistent with maps__init(). When maps_by_name == NULL, maps_by_name_sorted == false */ + maps__set_maps_by_name_sorted(maps, false); } static int map__start_cmp(const void *a, const void *b) @@ -1167,8 +1168,7 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map) } maps__set_maps_by_address(kmaps, merged_maps_by_address); maps__set_maps_by_address_sorted(kmaps, true); - zfree(maps__maps_by_name_addr(kmaps)); - maps__set_maps_by_name_sorted(kmaps, true); + __maps__free_maps_by_name(kmaps); maps__set_nr_maps_allocated(kmaps, merged_nr_maps_allocated); /* Copy entries before the new_map that can't overlap. */ -- 2.34.1