From patchwork Thu Dec 30 07:20:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701295 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 88BBDC433F5 for ; Thu, 30 Dec 2021 07:47:47 +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:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=hcmy7TpRF3EVlnnAhJJY8Dn/5ZJG+6n/7hpFZ664Kbo=; b=2ifGIK5OR2fRO71LNNHjoSyiQP XhPiJywqod6/huC8cxfvvWcMFKhX1U4yXm2dj5G4FxOovnuPusEBTmDxp0OrTndJWAOwKsVn+74b5 SWKxS2X1+qcuzYezzi1qS6Z7q29iHe3AM4en9QJ0CpJfEIqyu5yADMgC/6Bwhpi+qZP4PNYPgis+3 tA7Io6sLZH5ZARt7FuQ29t8o/ClJ0HVF/DpD6/PVhCAHm9H45J1jvyB65zVkqAu+t8lO84JxQIeJN jpC3VT5cIvLmUr5+8j/rAg1+FdiVmDgXyFLcNawL4NOVoeIRgGwoX8nnYk0TMozZVKaXR4CQLTCFS eqKdnjgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2q8e-003sm0-CV; Thu, 30 Dec 2021 07:46:17 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plC-003k5j-9Z for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:03 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id p140-20020a257492000000b0060dbb88d8abso11651397ybc.15 for ; Wed, 29 Dec 2021 23:22:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=zx3eoMgk2E9Q1m2Vv8UqlZ4wRR3W4iMt/10PWukXDj0=; b=gd7scXcBk1yTnVwoiPe+9oH6SNITUOkpUrx9WTCnO9LW819DoLCEjIc4CjYDRfgbW8 kpIcIaA0WXGx0A1JkH3+CNaDGqB3LbKNQy/dC69uwrapr1aB0K7K+nY8k+xsnN6eF4lR /nyWdqgi8c2eNr7SAmJDNL7ryVZ8uPy9AsDhfVRqK6mGUAbGuF5gKBfiymoyOc/lCu7g ZsKeKPIcAATBQs1wSFE96jQMWMX35qGZpKg86Ex1PLsLGuQ6bIj5+xVqZF25J4HmYKNJ 9nc93dAkDv96SzZ07Mn1s0PVaixDu0PPpFVxb1RLChglabm5T7WAiOU71z4oo0XVwMfL 9YlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=zx3eoMgk2E9Q1m2Vv8UqlZ4wRR3W4iMt/10PWukXDj0=; b=jgf5Co7Ju3333at1hAdraB1HHsy2MJIx3FEmuCFMWd1q8OxvMWH2TKgSt2MjgbPqQi sZK1BbWuCWiqxZkvGWXQIeRwCpdnXTDSN7YwmmcgNGNtcSH163jprdu8d3xK7g2+0VfI B9slajKzgCy8wBXEr6DKaAsQ8abHvN6/CAfncl5UrjfcvBZCIggBkfCl75FxskirVHIt QqOt3OYpKie354/rZ0T5UOBo7mhyvdhuVWH/uwruAfHqJXPg8Rgk1nVbaIewBl0/UGUa /bGZHiRKYgBv0sdhoAz6GcBnXM4c5SObD/1QbUflCvD7MghSAFTdgpSXx601BO5F6Ok2 ywWA== X-Gm-Message-State: AOAM532bzOEr1jGKu2eM8Q0HVJ/l57c1YCh77tuYWX6ihHkB3QUWftXT CDMj1ASXoxxzEQ7s74cQyHJG84inn0Eb X-Google-Smtp-Source: ABdhPJzroPIw7lL2p5xUk8nN/ROAI6MwcBgq9IhE3TcIDiuJTiQS4g8XAkhZduxh5XtQBLj5zuKGhd8qgHpF X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:7b41:: with SMTP id w62mr37995471ybc.164.1640848920800; Wed, 29 Dec 2021 23:22:00 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:15 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-35-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 33/48] libperf: Allow NULL in perf_cpu_map__idx From: Ian Rogers To: Andi Kleen , Jiri Olsa , Namhyung Kim , John Garry , Kajol Jain , "Paul A . Clarke" , Arnaldo Carvalho de Melo , Riccardo Mancini , Kan Liang , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Vineet Singh , James Clark , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232202_369974_3EE61E22 X-CRM114-Status: GOOD ( 11.97 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Return -1, not found, if NULL is passed. Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 3c36a06771af..eacea3ab965a 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -270,8 +270,13 @@ bool perf_cpu_map__empty(const struct perf_cpu_map *map) int perf_cpu_map__idx(const struct perf_cpu_map *cpus, int cpu) { - int low = 0, high = cpus->nr; + int low, high; + if (!cpus) + return -1; + + low = 0; + high = cpus->nr; while (low < high) { int idx = (low + high) / 2, cpu_at_idx = cpus->map[idx];