[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250625095930.00004f6f@huawei.com>
Date: Wed, 25 Jun 2025 09:59:30 +0100
From: Jonathan Cameron <Jonathan.Cameron@...wei.com>
To: Alok Tiwari <alok.a.tiwari@...cle.com>
CC: <will@...nel.org>, <mark.rutland@....com>, <linux-cxl@...r.kernel.org>,
<linux-perf-users@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 1/3] perf/cxlpmu: Fix devm_kcalloc() argument order
in cxl_pmu_probe()
On Tue, 24 Jun 2025 12:43:38 -0700
Alok Tiwari <alok.a.tiwari@...cle.com> wrote:
> The previous code mistakenly swapped the count and size parameters.
> This fix corrects the argument order in devm_kcalloc() to follow the
> conventional count, size form, avoiding potential confusion or bugs.
>
> Previous usage:
> devm_kcalloc(dev, sizeof(*info->hw_events), info->num_counters,
> GFP_KERNEL);
>
> New usage:
> devm_kcalloc(dev, info->num_counters, sizeof(*info->hw_events),
> GFP_KERNEL);
Too much detail! The sentence above would have been enough given
we have the code change to see how it applied.
>
> Previous incorrect order could lead to unexpected memory allocation
> behavior. This fix ensures correct allocation of hw_event structure.
It doesn't actually make any real difference. Look at the implementation
of devm_kmalloc_array() What it does is make it harder to reason about the
code and for that it is worth fixing up.
Anyhow none of that really matters.
Reviewed-by: Jonathan Cameron <jonathan.cameron@...wei.com>
>
> Signed-off-by: Alok Tiwari <alok.a.tiwari@...cle.com>
> ---
> drivers/perf/cxl_pmu.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/perf/cxl_pmu.c b/drivers/perf/cxl_pmu.c
> index d6693519eaee2..8998c0a2f3a2d 100644
> --- a/drivers/perf/cxl_pmu.c
> +++ b/drivers/perf/cxl_pmu.c
> @@ -834,8 +834,8 @@ static int cxl_pmu_probe(struct device *dev)
> if (rc)
> return rc;
>
> - info->hw_events = devm_kcalloc(dev, sizeof(*info->hw_events),
> - info->num_counters, GFP_KERNEL);
> + info->hw_events = devm_kcalloc(dev, info->num_counters,
> + sizeof(*info->hw_events), GFP_KERNEL);
> if (!info->hw_events)
> return -ENOMEM;
>
Powered by blists - more mailing lists