From nobody Thu Apr 16 03:39:28 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2646346ACF for ; Mon, 2 Mar 2026 23:45:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772495123; cv=none; b=kHymX+LRa/sVluIriVxe6khFa9zl2lNg3aM08R24uD/ZqotJ+MhkJhzb+g2G2UyO8YB8PLqMNZoCAwvk8eloOfxWyL2Q/DxLJ58lAInhbHvpTEnvZ1G/yV4jk8+uTlvoVihtKfJ4wID1FPkTVWTyeI+ePzApXlDcfv8mBdAcMgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772495123; c=relaxed/simple; bh=Ryw42QOZYCD6ImijtfIf1UyVQ5xoh3C3sfE6+2YHB54=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mJMvrMs1ob7cw81PXPoh1YT/9f2bym1qq8IT0YLsejJuMPkASyMSVIqtew4ZU62IkllZt1EXLkNWzrRaS8wbnr/8pX+Ngb+NvlRRzDYiZ9w+ZIxZW+LLiGYqwvoqg2urjp3z4K/IwDLoVDjXS7NrjrTxaUpweprE5poEDl+UN/I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=280KPrP6; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="280KPrP6" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2ba9a744f7dso5570514eec.0 for ; Mon, 02 Mar 2026 15:45:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772495121; x=1773099921; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XApOxNLqALRPqrd9a4JI8RQyzwyIkRhsoF996QzzUnM=; b=280KPrP6ejRpeiFpgpBtUxPUA28o6DT5hi1LtZTjxihTMCYvgvG1lpF8rQ/9ZwY1CU QtBwaie/5a7f3tttT6BrpRN36J3OBKbtA1fW/RHHMx6l1fWetFh2CulPtcNtTFrO0Nss +MMHLCUuXi7cBxmktOZkKjPmdNmYyfP97hkFvGZtyCsSTO+uiOIB4bKlbWUXpxF0BVsV e84OxNJ8bdN+CVNp2xD80FxplvUJBozX1ppNqb+04OkZzJ3EIU6zNQR8MK/nmD8MIdoP FpVYqIvYNF/ywsnRbgxyx/+gIqYIaROg5vq4FJxlLjRbCcYldyvIatggWiq3fcdpc2fn +hwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772495121; x=1773099921; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XApOxNLqALRPqrd9a4JI8RQyzwyIkRhsoF996QzzUnM=; b=u9smvF0+e51kEdtk927dR0DjdMfOBq/qZkzkqCqA/v5FC36/BR1J/WtHMIrEkNOu0b QJVXZTikfR25W7wBbwh2+qx1dJ2NfUtA53TLdHyHH2njRcXh8HijSYHrKLcOptOZmCgT iaw/8bGqCmuCYTQ1vGyDd++of1Dapqn70lvr801+TJ0pm40xj95CUUB1/y61P6yNFYW+ JCYc4wuQa/rWeL+mwsOe5ij8Rlwko9gZqL3DRjaEhZKr0XWJxHBelHMXguUkSTHj522p KuhuEgEKLZdaRoLxdJ2TqNrs2hlaX1wr/zSugCYxlC/nQWkowXbs8XilqlIpv1lSaRIT CodA== X-Forwarded-Encrypted: i=1; AJvYcCXm1Y/pHGhcP5er975e1wnrVlDVNw7MIYIy30yoX1Xm4i7I81/WLqnJYI90ZwOgku7jINkGyBvacq6dLmI=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1OsFhZgfWD3WwoVIhdZ3FHbt8R2xrutBgN98maO9nqc+jFc2R 0jRJ2qmO7GX4Bmp/RZQ5lGgNlzKc6CM6J1xZ6p+8nRi3yfyOyPVM+xn4MC7hsmdaJN6bYPOv/yc a9WkkWK/61Q== X-Received: from dybhr7.prod.google.com ([2002:a05:7300:e2c7:b0:2be:1a3c:a2e8]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:4181:b0:2be:1365:b6db with SMTP id 5a478bee46e88-2be1365dd7fmr1835551eec.17.1772495120836; Mon, 02 Mar 2026 15:45:20 -0800 (PST) Date: Mon, 2 Mar 2026 15:45:15 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog Message-ID: <20260302234515.565623-1-irogers@google.com> Subject: [PATCH v1] perf trace: Avoid an ERR_PTR in syscall_stats From: Ian Rogers To: howardchu95@gmail.com Cc: acme@kernel.org, adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, irogers@google.com, james.clark@linaro.org, jolsa@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mark.rutland@arm.com, mingo@redhat.com, namhyung@kernel.org, peterz@infradead.org, wangguangju@hygon.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" hashmap__new may return an ERR_PTR and previously this would be assigned to syscall_stats meaning all use of syscall_stats needs to test for NULL (uninitialized) or an ERR_PTR. Given the only reason hashmap__new can fail is ENOMEM, just use NULL to indicate the allocation failure and avoid the code having to test for NULL and IS_ERR. Fixes: 96f202eab813 (perf trace: Fix IS_ERR() vs NULL check bug) Signed-off-by: Ian Rogers --- tools/perf/builtin-trace.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 295b272c6c29..7ff85fa90d98 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1565,7 +1565,9 @@ static bool syscall_id_equal(long key1, long key2, vo= id *ctx __maybe_unused) =20 static struct hashmap *alloc_syscall_stats(void) { - return hashmap__new(syscall_id_hash, syscall_id_equal, NULL); + struct hashmap *result =3D hashmap__new(syscall_id_hash, syscall_id_equal= , NULL); + + return IS_ERR(result) ? NULL : result; } =20 static void delete_syscall_stats(struct hashmap *syscall_stats) @@ -1573,7 +1575,7 @@ static void delete_syscall_stats(struct hashmap *sysc= all_stats) struct hashmap_entry *pos; size_t bkt; =20 - if (IS_ERR(syscall_stats)) + if (!syscall_stats) return; =20 hashmap__for_each_entry(syscall_stats, pos, bkt) @@ -1589,7 +1591,7 @@ static struct thread_trace *thread_trace__new(struct = trace *trace) ttrace->files.max =3D -1; if (trace->summary) { ttrace->syscall_stats =3D alloc_syscall_stats(); - if (IS_ERR(ttrace->syscall_stats)) + if (!ttrace->syscall_stats) zfree(&ttrace); } } @@ -4464,7 +4466,7 @@ static int trace__run(struct trace *trace, int argc, = const char **argv) =20 if (trace->summary_mode =3D=3D SUMMARY__BY_TOTAL && !trace->summary_bpf) { trace->syscall_stats =3D alloc_syscall_stats(); - if (IS_ERR(trace->syscall_stats)) + if (!trace->syscall_stats) goto out_delete_evlist; } =20 @@ -4771,7 +4773,7 @@ static int trace__replay(struct trace *trace) =20 if (trace->summary_mode =3D=3D SUMMARY__BY_TOTAL) { trace->syscall_stats =3D alloc_syscall_stats(); - if (IS_ERR(trace->syscall_stats)) + if (!trace->syscall_stats) goto out; } =20 --=20 2.53.0.473.g4a7958ca14-goog