From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 8CCDAC48295 for ; Fri, 2 Feb 2024 23:41:34 +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=u/F67/GG/nXQSdBSszAAQ45vqfqtRe07pocxBlfBZGM=; b=yVCgzxaCirxyOx 9bRH57OnNY8Ol91pmpq9JbibF7SiR2R99+3EtMitDs2fgKTEZR430NG1MbkcZ4yhcD8oJshqZnf/c y2fcD0VA1oLWeiDRvcSeTdMwz+aE+is3U9vLx3isdYHrVj1l90ww1licheBCjkKtK7jE0KXBUmAAz bL9Vnb/qpX2xOWS1Q4CpSMh1eSruPyphUggN7ohczrtR41lqnTwf/riujPGGDSXVaPrmQnYVulfCw X9X5xHNELBo8heN2jUu6ahGb094ZWFgTiMWaNQxPUYNk3oIgA/CwrRmUQI88Z8yrdqOznGmv5kCAM Ycmsmqoa5q7qAySF8RGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rW39r-0000000DoSq-1BQU; Fri, 02 Feb 2024 23:41:19 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rW39n-0000000DoPr-2EUh for linux-arm-kernel@lists.infradead.org; Fri, 02 Feb 2024 23:41:16 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dc6dbdcfd39so4523759276.2 for ; Fri, 02 Feb 2024 15:41:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917274; x=1707522074; 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=wOc7/ot5clrlqkd/XVVApb41eylij+dgoGLfSlWPOp0=; b=WQqF7bE8FYX6oJJ+/OtTGkfNqmByv+2VS4rrsE2vVd/tnePjLGbsfN39RQuKkntvWG 53alqWKJW/x4oEWTggEMnzkGvQCFIFgCY/AHYHmvildncOPElYAZn/kuemZJmgW6KjxQ 11ZFOaK2Y/qprtQjrUlRbAvZYPIWcAdeMZX2Bvvy5Sd5vk0pQHOvg1AuJatrVOHLcirk pAqJ9rEQ/rKTDxsCx8aPeFLxXCjrXSKRbAGZmUwlxKRzqr8TFxFtdoiCpsH2jyNv2zSy Z3GJdDuGJ4aDZjShE1D9NFgEHzjfuDN18DtXkqNShoIoXLVPW9cq4maLWxXa3pWY7R10 v2UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917274; x=1707522074; 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=wOc7/ot5clrlqkd/XVVApb41eylij+dgoGLfSlWPOp0=; b=jqWL7cdEBAo2oqrzO/zb8Yy9bSFke1K4GirTl5k6LuYOGXTBBntlZtsPRFnbuoen6h i8OSTbqcJq+DmPs9l7QwEJXzJpgqvzKD5pnM0C/FTr/iNvOBzvovmAGWlxF+S2pwq3pe DrC2AKzgBzLRKkCX2LWy+fjZV2JR/AchSkQ6xVV30c+wvx0Kb7f+2S8076/jW7psj32u AAue0Vfc+TNzqgD2gVg4x0625t7Xf1K6LoeQKaxcVIHHZvpFK2ApdR93C3uFfs7qITAI ocOJcY0QlmqKxd9xkR97rnFjt+J0MZQe4m8yEMkVyA/vUQQGBLbJ38jTdatn8pjBUW2Y o/4w== X-Gm-Message-State: AOJu0Yxr2nt1Xrgn0aZSqSC1pOvk6+QOI62oM5in3XY8sj8p0+A65//f 0ymbljACLw3xs9VcBHk83UTT6oAHx6TFBbvnqfjFBKTvnFBYkMMRBKmRUSwGpGBJLqNa4wgVRUa UFRQ1UQ== X-Google-Smtp-Source: AGHT+IHFL6+6WJT+TDjsN0v4AycgXqtEdFuE4PFoyenBnNnNjcCA2pFf3NUeukXxzibAja4cMAtIanSVNF3E X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a05:6902:1b08:b0:dc2:398d:a671 with SMTP id eh8-20020a0569021b0800b00dc2398da671mr1024554ybb.10.1706917274174; Fri, 02 Feb 2024 15:41:14 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:51 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-3-irogers@google.com> Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 2/8] libperf cpumap: Ensure empty cpumap is NULL from alloc From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , 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-20240202_154115_597681_4D9DC82F X-CRM114-Status: GOOD ( 14.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Closes: https://lore.kernel.org/lkml/2cd09e7c-eb88-6726-6169-647dcd0a8101@arm.com/ Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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); -- 2.43.0.594.gd9cf4e227d-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel