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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53BFAC433F5 for ; Tue, 28 Dec 2021 23:55:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232013AbhL1XzJ (ORCPT ); Tue, 28 Dec 2021 18:55:09 -0500 Received: from mail-lj1-f174.google.com ([209.85.208.174]:37658 "EHLO mail-lj1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231929AbhL1XzJ (ORCPT ); Tue, 28 Dec 2021 18:55:09 -0500 Received: by mail-lj1-f174.google.com with SMTP id k27so32990214ljc.4; Tue, 28 Dec 2021 15:55:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CKJz/AtcJmpCiEvIzViyhh95QG7qUmjpMJgihccbkCs=; b=PvDVzKTaqiPh2OqgLIJCiu7WbBrGDGQBZJGTF+b1Y7U06FAYwwDooPNg4zdYP6/eap hgq76x1yk7fnQDavBI1/7u6vJcwpnF77n2u5gjx9/A9LMU950TbWSBAIdigdzJ3VCvJ+ ua4nrsU3qb4WkaVi0k9aJbfKaICy2eDZbezTwzrZja94uSrrO0NUG/CtVgU1gXDKSuQQ 3oc6hLXb8npUHlKfwslmGNZfzeW7H8kJP6h4fP0OL4rMLtRXBLRqFNrPCPikocxWTZVX AKFYezzL6KzfUEhC5F2/1pD3cHkjFrWjCzvZprsYSacURrHAq7mQCImy5GMGMStsaNTv cHTA== X-Gm-Message-State: AOAM530Rir0L6E3SGbrDC36txGO/lWZMDaaDLXHQgX1RjV3AR0qDzJY9 XoOWRjuHNU5StAbKGOT1befZ40QR3PAQcf6VEMw= X-Google-Smtp-Source: ABdhPJzeVaNtQh2PYBhyRcZvRYpN27TgPCYnrsUr+ZHkFSjQrU+k1+FkqGmEwkHUIhVBUf8j36D39viYfLBFnidZBQI= X-Received: by 2002:a2e:a288:: with SMTP id k8mr7061145lja.204.1640735707979; Tue, 28 Dec 2021 15:55:07 -0800 (PST) MIME-Version: 1.0 References: <20211223074541.3318938-1-irogers@google.com> <20211223074541.3318938-23-irogers@google.com> In-Reply-To: <20211223074541.3318938-23-irogers@google.com> From: Namhyung Kim Date: Tue, 28 Dec 2021 15:54:56 -0800 Message-ID: Subject: Re: [PATCH v2 22/48] perf cpumap: Trim the cpu_aggr_map To: Ian Rogers Cc: Andi Kleen , Jiri Olsa , 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 , linux-kernel , Vineet Singh , James Clark , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Stephane Eranian Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org On Wed, Dec 22, 2021 at 11:47 PM Ian Rogers wrote: > > cpu_aggr_map__new removes duplicates, when this happens shrink the > array. > > Reviewed-by: James Clark > Signed-off-by: Ian Rogers > --- > tools/perf/util/cpumap.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c > index 8a72ee996722..985c87f1f1ca 100644 > --- a/tools/perf/util/cpumap.c > +++ b/tools/perf/util/cpumap.c > @@ -185,7 +185,12 @@ struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus, > c->nr++; > } > } > - > + /* Trim. */ > + if (c->nr != cpus->nr) { > + c = realloc(c, sizeof(struct cpu_aggr_map) + sizeof(struct aggr_cpu_id) * c->nr); > + if (!c) > + return NULL; This leaks the original 'c'. Maybe we can just use it in case of a failure. Thanks, Namhyung > + } > /* ensure we process id in increasing order */ > qsort(c->map, c->nr, sizeof(struct aggr_cpu_id), aggr_cpu_id__cmp); > > -- > 2.34.1.307.g9b7440fafd-goog >