Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4007376pxb; Mon, 1 Feb 2021 10:00:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4CvedpdWOr/12H0O9M4g6knagpjuKA0BkK4Gn2HKKNb6+cUF4qmbQMTsA7hOt8EAR57vk X-Received: by 2002:a17:906:c049:: with SMTP id bm9mr18207842ejb.535.1612202408201; Mon, 01 Feb 2021 10:00:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612202408; cv=none; d=google.com; s=arc-20160816; b=VVtHKmU9TAu3uAZHrcwr4kIk+maYopLfoRiVEgQoiLH+nQ4E5XMNQmhYaX/qbckL5N EtDHFocVVB2uu0n4pIdQ1h/yIlqosKZGKy7R5n6rM3IYwAOKwPYV27i2dTCq4bcVWvkQ kqbGOrk44svCOVrpsm3wOwLnVzVEJziuTI2zBpx6qlVU/8qpTi2BE525SSNQP0G6uIcb 4KGDtMycgds8k2K6wvJsJgxfoGOB2ND1S7NPHzpUhvFZXE4CITNER5k9FHuICvh9EKNR p/S5jNjLNb2NyzXWXtPNlVGHWAUPy0sTxFHfCKwxNxpfCPq8Hh+F3WFoKeSFqQWiwflk h8vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:ironport-sdr:ironport-sdr; bh=1MYmOXBuHsY+my7RuTkObVE9XKjQM2HmY+g77dpIlH8=; b=d3L0be8aKTxyDC4FL+85k4AmVQRYejmGCPWYDlwQZi5FYjNnG4/PYLYkd8KuQ41M9X xzlJSFwo9hWXvPve1tJmo0PngEdeV0pCF9JJz7tv4G/ELxwrhSxM23xydTnE75u9Owp3 Fcr8mIS3OenuinMeemDs7ZYKVSkJ27+qp76YvU+teIrJ1mFEpwzORrGpEWpzwTt8ioOw LNTk9d4rw1Z0S/QaTJtM0MaZQWSzc0MsnLTk8Ku/EYrp4SiP7v5+F6q//dCYpbhyAs9h H2+sXiu1/Iuxr1qS2wZEbYhkL+Xy7bslTYPHriOf7loTi9GJCH0Mon3MWUGhtFK5ShyI 7/Lw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b12si10781262edz.497.2021.02.01.09.59.39; Mon, 01 Feb 2021 10:00:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232546AbhBAR5i (ORCPT + 99 others); Mon, 1 Feb 2021 12:57:38 -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 >>