linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Alok Tiwari <alok.a.tiwari@oracle.com>
Cc: <will@kernel.org>, <mark.rutland@arm.com>,
	<linux-cxl@vger.kernel.org>, <linux-perf-users@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 1/3] perf/cxlpmu: Fix devm_kcalloc() argument order in cxl_pmu_probe()
Date: Wed, 25 Jun 2025 09:59:30 +0100	[thread overview]
Message-ID: <20250625095930.00004f6f@huawei.com> (raw)
In-Reply-To: <20250624194350.109790-2-alok.a.tiwari@oracle.com>

On Tue, 24 Jun 2025 12:43:38 -0700
Alok Tiwari <alok.a.tiwari@oracle.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@huawei.com>
> 
> Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.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;
>  


  reply	other threads:[~2025-06-25  9:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-24 19:43 [PATCH v2 0/3] perf/cxlpmu: Fix allocation argument order and minor formatting Alok Tiwari
2025-06-24 19:43 ` [PATCH v2 1/3] perf/cxlpmu: Fix devm_kcalloc() argument order in cxl_pmu_probe() Alok Tiwari
2025-06-25  8:59   ` Jonathan Cameron [this message]
2025-06-24 19:43 ` [PATCH v2 2/3] perf/cxlpmu: Remove unintended newline from IRQ name format string Alok Tiwari
2025-06-25  9:04   ` Jonathan Cameron
2025-06-24 19:43 ` [PATCH v2 3/3] perf/cxlpmu: Fix typos in cxl_pmu.c comments and documentation Alok Tiwari
2025-06-25  9:05   ` Jonathan Cameron
2025-07-14 15:10 ` [PATCH v2 0/3] perf/cxlpmu: Fix allocation argument order and minor formatting Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250625095930.00004f6f@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=alok.a.tiwari@oracle.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).