Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp756820lqo; Fri, 10 May 2024 14:05:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWv/9MphBs6y4E0Zo0HIhR4K5d0cbYmHAhq1ZOtWG6Bl2sowMuX4A995dZKqQTYDIhE6+PKY0VLWvF0M540V0BcWI315Vrth3HcSOJw3Q== X-Google-Smtp-Source: AGHT+IGoMY+3Grs/q5zbow7ODAfY26aG2iF1NpkS24bMuxR5EVkprwLfGe7rpwGAAXUzZJmrlXrJ X-Received: by 2002:a17:902:7893:b0:1e2:9ddc:f72d with SMTP id d9443c01a7336-1ef43d2af36mr37853315ad.26.1715375153516; Fri, 10 May 2024 14:05:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715375153; cv=pass; d=google.com; s=arc-20160816; b=L720tfHsfrugJeJrzf8AnWV26FyXA0ylJHKVjjJADwpLiUWPtoNUkN4X/amBD0eX6S 6aCqHWo0FPYHu6pPR1ZMEXDIREFXcg/0vE0UhReapBLPB4cUbJSv0fX/4rvufajF1fS3 mOAo7faYfWmhOF0c/vKj2noDF4cSV10adH48SynIw+dJztjF6CaK8Ekm37oKD7qoSAK+ YjjXy/+JsDEbIQVx3LuiY1QpWP4SwY2g8Y0Nrd+2gguept8P0rQYJ+lcpf2XFZ5t8kpW qPR2Pk+v7p2zsC6aaZth5VpS62aXxQnKr1vh/BAt/K1nw+ijc2w4dhGLWDk7YRFTCvzd XVaQ== 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:dkim-signature; bh=tPCdic2XWGsNsoIWJrutf8EOhxmYCvAkYdzhgxZf/ck=; fh=fHhbvXgCev/wpffLVpfaAi8pPyv7hrTyhVPgsZ7HNrs=; b=AkAM/wpMw87iHnT7yZrG0RiRQJccEVhjaR3AtzXQKNfUTCBAR7lst9neNRHlKKlnUU 4jOVxVvNuLDYpOffMR6RWpQOxsO2LkSA6cOXgwNnhHJSvgNHV/TKFOwU+3R7FkbPJTkc 15xdl2IyVuAQByaPFl+gU550Kxr1NJgwJtO1ywM1pGoG7zE+HA+iCPOkZh2wj86ZvmW0 2xVcf1iPInbF7w++FUvT4kV4y/ymvUgCpWFFyNb3NG0HAzJFDq2bqEtQzhyPSCx4jPwf jqrPMpcyZ52k9vGKC9nhtIY7oPf5WlLZRRSYYNY23A/vLO6AICMrl1Zjs2SpKfzHx6ju 7HBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dm1LHtwI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-176191-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176191-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0c138749si45682735ad.444.2024.05.10.14.05.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 14:05:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176191-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dm1LHtwI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-176191-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176191-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 712132881D2 for ; Fri, 10 May 2024 21:05:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A0AF413BADC; Fri, 10 May 2024 21:04:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dm1LHtwI" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9F1C13B5A8; Fri, 10 May 2024 21:04:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715375094; cv=none; b=L2d7HWduJogMrx7r0gFr+IeMD7r8qLbw/HuewHlo3c2g8yxQlfjNLPbJZNBlzsdSoGVu1rF7xk8g9irmOQeKyU04hnwzUpb1xioXb2S+Szswjsypu9SV5IB5PZUHwWwbUbzfB0KC3gZDpyWasXHJetF7Px98iLNkNTO9HfIdfyQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715375094; c=relaxed/simple; bh=HBZIj1WAuQM5nC/b9RWGi6gCG6UEdmsr7b+HnD3F+1E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TDbhYzQdAYGZ6AK7h79LnhKqwXXJXSkelkSnU4A5CqMrJS1wQJdqMFnuNVdXY3JunrTQ1RVvd41rvrKdMo6K+mGUTwewkIuxI8fZhxFId3HTx7maqyUXRT7kCovkPXVVYhsO/jbvtBEoJwE3hMvSvrPWyeLuWeg4LxiPcT7SHlY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dm1LHtwI; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0086CC32781; Fri, 10 May 2024 21:04:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715375094; bh=HBZIj1WAuQM5nC/b9RWGi6gCG6UEdmsr7b+HnD3F+1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dm1LHtwIJqJWUYZU/FM4z2YDihwqpiFG3uY4Z+EMVdi+48iNByqfb1A25NdIXLlyE NSpSw8JH9nca5my7b9OymwjfQn6bmNzplbyRRtbQurXFL/7N1xI9nOdM40sVjJG0nK OAhk3kGLOf/hh3liILX3YNNFq6LZ3qBa9vzzfYkGzJEuJvHyHN72VpHeDYnbSn1y5W 958QUcpjnYwo1897xdtxMU3zh8ij8bcPKHRkeLzgHeMisHM+oFgEUafjw3L4pahj5l WzEfaueLku+xbqNATXeK7+EMsOv6KH38p7ci7vV9fohVNcH7rICGVXWrdhTwtEfjP8 fbAfkpTynnj5Q== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 2/2] perf annotate-data: Ensure the number of type histograms Date: Fri, 10 May 2024 14:04:52 -0700 Message-ID: <20240510210452.2449944-2-namhyung@kernel.org> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog In-Reply-To: <20240510210452.2449944-1-namhyung@kernel.org> References: <20240510210452.2449944-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Arnaldo reported that there is a case where nr_histograms and histograms don't agree each other. It ended up in a segfault trying to access NULL histograms array. Let's make sure to update the nr_histograms when the histograms array is changed. Reported-by: Arnaldo Carvalho de Melo Signed-off-by: Namhyung Kim --- tools/perf/util/annotate-data.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c index 57e7d4b3550b..965da6c0b542 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -1800,7 +1800,6 @@ static int alloc_data_type_histograms(struct annotated_data_type *adt, int nr_en sz += sizeof(struct type_hist_entry) * adt->self.size; /* Allocate a table of pointers for each event */ - adt->nr_histograms = nr_entries; adt->histograms = calloc(nr_entries, sizeof(*adt->histograms)); if (adt->histograms == NULL) return -ENOMEM; @@ -1814,6 +1813,8 @@ static int alloc_data_type_histograms(struct annotated_data_type *adt, int nr_en if (adt->histograms[i] == NULL) goto err; } + + adt->nr_histograms = nr_entries; return 0; err: @@ -1827,7 +1828,9 @@ static void delete_data_type_histograms(struct annotated_data_type *adt) { for (int i = 0; i < adt->nr_histograms; i++) zfree(&(adt->histograms[i])); + zfree(&adt->histograms); + adt->nr_histograms = 0; } void annotated_data_type__tree_delete(struct rb_root *root) -- 2.45.0.118.g7fe29c98d7-goog