Message ID | 20240201042236.1538928-3-irogers@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show
Return-Path: <linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org> 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 07699C4828D for <linux-arm-kernel@archiver.kernel.org>; Thu, 1 Feb 2024 04:23:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+thjuj/7Zg5PrGM5GgU0en46CUQib0p/Fkz94XE9gSQ=; b=TsL/47FzLxCRKc M8gz6hOFy/YrOqk9kKtTbcF6ge44LpMLNhw4OuTMjf+ytCTB3hqgZCawNJoeEKYQlG11la1heXrWD W6x1MNrvUod+Tp6BSunIqVJILX1Uo/pq+lXDucjtWz4cc7Ivjt0fE8l1iTMjB9rzahhaNEfbf86P6 bbiMntoqQro6Mn6akLgr9xdiHX9SA+LzQv+HavlqPpIu73WbD0sey6rvttn6UwzwLkym7Ry+m9IN0 ofpgLrsLLF+ZDt2u60FTohPAxjxNHGy4ZDzaeGQaTIxj0Q+zZE/z1oEYqKdwuhKivSDc0Szxp6tWB YCpVYMg99F/IiUQGVTzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVObR-00000006UTN-2eq4; Thu, 01 Feb 2024 04:23:05 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVObG-00000006UL1-4A6T for linux-arm-kernel@lists.infradead.org; Thu, 01 Feb 2024 04:22:56 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5efe82b835fso10625227b3.0 for <linux-arm-kernel@lists.infradead.org>; Wed, 31 Jan 2024 20:22:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706761374; x=1707366174; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=1JXSUMX5bbfgnckmTRSZnaB9bhkcugUHtNJBG9b4Oo4=; b=JtGjYZuF+Y0FOL2U9Mc0edgAsa//8ssCJU97HbCT0GVIQ7+qZHodKXIsm/NrTxsakI 0K+RjFKIOX7dnUhW8uylnPV2wOXAg6C24t9W7cPJQpqD9z0DGFvH8VEcKNSOR8lUYLgf wYOfUnSSB8oMSPYi53UOw2bCdIPIQKW8gVNP7Zn8/By9diZvCT0BiEcza6jRCK4yitQG dZL7/upVVFIL11DYWahcvGbyJ6X4uLeQKDtn4Fm/pv02ppaPZYuLN9YgvEan9BiWHZ6+ 6Z5WZOFDi4WLznS7S7FI5ZV2c0eLdQHjVv2thRwjczoFl5+KTlAxeEB3tGVgaYnzTyNN 4xeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706761374; x=1707366174; h=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=1JXSUMX5bbfgnckmTRSZnaB9bhkcugUHtNJBG9b4Oo4=; b=epOQN8cU4sVFaGDsbhZjIW25w3jWfYogdU+FhGeJKpXarcnlr3Ptv73vIVcsQifH7C IeOP3RdUmWOUrJUjiFSz5i3JKh15Kz/Rv+B+VHGfQvfUNqr6VEhxOXEWc7bXxPFgIfe7 etH80Syzw5ycM9/mWkkWr0v8BemOY4dO6h0ZPI7G09Lu/K5FszPU75dfVViPXz5iPYQK NMf5FoHi34fC5v+47Ggt718ci7o3tIygMl7oLAUeHryLJjSNYSVBGk9dP6LOPbqSjkyQ ticb37Kzcqa8/jnyyRqSm9xFrpIHuI+CtDJQrvU+rtFh5jBWKrEMkJCVrL4UI5FYCl/X gy/g== X-Gm-Message-State: AOJu0YwzGWjMgydP73nhnSjku2gGcXyR9oU/KD3y4hfL43eZBCy/vJ5v b82QXnoz+N5QvZAymYz5CtpO5FdQaGwpnFNlN6bhqoEMvqR6huScSeDMKNvQNS7sAKE7bNEmMgf QSFEFng== X-Google-Smtp-Source: AGHT+IFTJVPGgTJjz0vfAK3znBckhM+C3f96ATL1D3c1AModrSqCIkbFIqSfHTHrXRFHdRJrEfI2dhkZAVZt X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:16c5:1feb:bf99:a5d1]) (user=irogers job=sendgmr) by 2002:a81:9a92:0:b0:5ff:a41c:1d19 with SMTP id r140-20020a819a92000000b005ffa41c1d19mr780347ywg.9.1706761373658; Wed, 31 Jan 2024 20:22:53 -0800 (PST) Date: Wed, 31 Jan 2024 20:22:30 -0800 In-Reply-To: <20240201042236.1538928-1-irogers@google.com> Message-Id: <20240201042236.1538928-3-irogers@google.com> Mime-Version: 1.0 References: <20240201042236.1538928-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Subject: [PATCH v2 2/8] libperf cpumap: Ensure empty cpumap is NULL from alloc From: Ian Rogers <irogers@google.com> To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Arnaldo Carvalho de Melo <acme@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>, Ian Rogers <irogers@google.com>, Adrian Hunter <adrian.hunter@intel.com>, Suzuki K Poulose <suzuki.poulose@arm.com>, Mike Leach <mike.leach@linaro.org>, James Clark <james.clark@arm.com>, Leo Yan <leo.yan@linaro.org>, John Garry <john.g.garry@oracle.com>, Will Deacon <will@kernel.org>, Thomas Gleixner <tglx@linutronix.de>, Darren Hart <dvhart@infradead.org>, Davidlohr Bueso <dave@stgolabs.net>, " =?utf-8?q?Andr=C3=A9_Almeida?= " <andrealmeid@igalia.com>, Kan Liang <kan.liang@linux.intel.com>, K Prateek Nayak <kprateek.nayak@amd.com>, Sean Christopherson <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com>, Kajol Jain <kjain@linux.ibm.com>, Athira Rajeev <atrajeev@linux.vnet.ibm.com>, Andrew Jones <ajones@ventanamicro.com>, Alexandre Ghiti <alexghiti@rivosinc.com>, Atish Patra <atishp@rivosinc.com>, "Steinar H. Gunderson" <sesse@google.com>, Yang Jihong <yangjihong1@huawei.com>, Yang Li <yang.lee@linux.alibaba.com>, Changbin Du <changbin.du@huawei.com>, Sandipan Das <sandipan.das@amd.com>, Ravi Bangoria <ravi.bangoria@amd.com>, Paran Lee <p4ranlee@gmail.com>, Nick Desaulniers <ndesaulniers@google.com>, Huacai Chen <chenhuacai@kernel.org>, Yanteng Si <siyanteng@loongson.cn>, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240131_202255_093764_EBE5FAE6 X-CRM114-Status: GOOD ( 13.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: <linux-arm-kernel.lists.infradead.org> List-Unsubscribe: <http://lists.infradead.org/mailman/options/linux-arm-kernel>, <mailto:linux-arm-kernel-request@lists.infradead.org?subject=unsubscribe> List-Archive: <http://lists.infradead.org/pipermail/linux-arm-kernel/> List-Post: <mailto:linux-arm-kernel@lists.infradead.org> List-Help: <mailto:linux-arm-kernel-request@lists.infradead.org?subject=help> List-Subscribe: <http://lists.infradead.org/mailman/listinfo/linux-arm-kernel>, <mailto:linux-arm-kernel-request@lists.infradead.org?subject=subscribe> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" <linux-arm-kernel-bounces@lists.infradead.org> Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org |
Series |
Clean up libperf cpumap's empty function
|
expand
|
diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index ba49552952c5..cae799ad44e1 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -18,9 +18,13 @@ void perf_cpu_map__set_nr(struct perf_cpu_map *map, int nr_cpus) struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus) { - RC_STRUCT(perf_cpu_map) *cpus = malloc(sizeof(*cpus) + sizeof(struct perf_cpu) * nr_cpus); + RC_STRUCT(perf_cpu_map) *cpus; struct perf_cpu_map *result; + if (nr_cpus == 0) + return NULL; + + cpus = malloc(sizeof(*cpus) + sizeof(struct perf_cpu) * nr_cpus); if (ADD_RC_CHK(result, cpus)) { cpus->nr = nr_cpus; refcount_set(&cpus->refcnt, 1);
Potential corner cases could cause a cpumap to be allocated with size 0, but an empty cpumap should be represented as NULL. Add a path in perf_cpu_map__alloc to ensure this. Suggested-by: James Clark <james.clark@arm.com> Closes: https://lore.kernel.org/lkml/2cd09e7c-eb88-6726-6169-647dcd0a8101@arm.com/ Signed-off-by: Ian Rogers <irogers@google.com> --- tools/lib/perf/cpumap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)