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 X-Spam-Level: X-Spam-Status: No, score=-10.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C13CC433DB for ; Mon, 1 Feb 2021 17:58:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE15364E9C for ; Mon, 1 Feb 2021 17:58:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232644AbhBAR5y (ORCPT ); Mon, 1 Feb 2021 12:57:54 -0500 Received: from mga11.intel.com ([192.55.52.93]:60307 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232415AbhBAR5e (ORCPT ); Mon, 1 Feb 2021 12:57:34 -0500 IronPort-SDR: YcIfYK9xlP6WlzpSxjKdr5HYS8WaeJ+px3/RFnt0Yr+hehFr2Bu6wpWANnAc9COMeugljhW+r7 5FgIi55SOANg== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="177217669" X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="177217669" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 09:55:48 -0800 IronPort-SDR: /aYXIKv6iQ7ryKOpqm45AA34jmqJYoPWMaoOpjgwB/mVaMS39tKVgzsdomiD22tH3FzslIwHwG wxKrBSoiPEgg== X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="391017369" Received: from aantonov-mobl.ccr.corp.intel.com (HELO [10.249.230.90]) ([10.249.230.90]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 09:55:44 -0800 Subject: Re: [PATCH v3 3/5] perf stat: Helper functions for PCIe root ports list in iostat mode To: Namhyung Kim Cc: Arnaldo Carvalho de Melo , linux-kernel , Jiri Olsa , Andi Kleen , Alexander Shishkin , Mark Rutland , Ian Rogers , Ingo Molnar , Peter Zijlstra References: <20210126080619.30275-1-alexander.antonov@linux.intel.com> <20210126080619.30275-4-alexander.antonov@linux.intel.com> From: Alexander Antonov Message-ID: <01d8c8f5-da91-983d-dc3a-9c1c8c3633de@linux.intel.com> Date: Mon, 1 Feb 2021 20:55:42 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/29/2021 11:26 AM, Namhyung Kim wrote: > Hello, > > On Tue, Jan 26, 2021 at 5:06 PM Alexander Antonov > wrote: >> Introduce helper functions to control PCIe root ports list. >> These helpers will be used in the follow-up patch. >> >> Signed-off-by: Alexander Antonov >> --- > [SNIP] >> +static int iio_root_ports_list_insert(struct iio_root_ports_list *list, >> + struct iio_root_port * const rp) >> +{ >> + struct iio_root_port **tmp_buf; >> + >> + if (list && rp) { >> + rp->idx = list->nr_entries++; >> + /* One more for NULL.*/ >> + tmp_buf = realloc(list->rps, >> + (list->nr_entries + 1) * sizeof(*list->rps)); > Why is this +1 needed since you already have the number of > entries in the list? > > Thanks, > Namhyung Hello, My first approach for iteration through root ports list was using NULL-terminated array. And seems like I just forgot to remove this code. I will fix it. Thank you, Alexander > >> + if (!tmp_buf) { >> + pr_err("Failed to realloc memory\n"); >> + return -ENOMEM; >> + } >> + tmp_buf[rp->idx] = rp; >> + tmp_buf[list->nr_entries] = NULL; >> + list->rps = tmp_buf; >> + } >> + return 0; >> +} >> -- >> 2.19.1 >>