Messages in this thread | | | Subject | Re: [PATCH v3 3/5] perf stat: Helper functions for PCIe root ports list in iostat mode | From | Alexander Antonov <> | Date | Mon, 1 Feb 2021 20:55:42 +0300 |
| |
On 1/29/2021 11:26 AM, Namhyung Kim wrote: > Hello, > > On Tue, Jan 26, 2021 at 5:06 PM Alexander Antonov > <alexander.antonov@linux.intel.com> 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 <alexander.antonov@linux.intel.com> >> --- > [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 >>
| |