mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alison Schofield <alison.schofield@intel.com>
To: Akhilesh Patil <akhilesh@ee.iitb.ac.in>
Cc: <saeedm@nvidia.com>, <itayavr@nvidia.com>, <dave.jiang@intel.com>,
	<jgg@ziepe.ca>, <Jonathan.Cameron@huawei.com>,
	<linux-kernel@vger.kernel.org>, <akhileshpatilvnit@gmail.com>,
	<skhan@linuxfoundation.org>
Subject: Re: [PATCH] fwctl: mlx5: fix memory alloc/free in mlx5ctl_fw_rpc()
Date: Fri, 15 Aug 2025 11:59:05 -0700	[thread overview]
Message-ID: <aJ-DebbVy8-9cEt0@aschofie-mobl2.lan> (raw)
In-Reply-To: <aJjiRqLx9TEg2NFj@bhairav-test.ee.iitb.ac.in>

On Sun, Aug 10, 2025 at 11:47:42PM +0530, Akhilesh Patil wrote:
> Use kvfree() to free memory allocated by kvzalloc() instead of kfree().
> Avoid potential memory management issue by matching alloc/free routines.
> 
> Fixes: 52929c2142041 ("fwctl/mlx5: Support for communicating with mlx5 fw")
> Signed-off-by: Akhilesh Patil <akhilesh@ee.iitb.ac.in>

Hi Akhilesh,

How about making the commit message more specific about why this
patch is critical even when no immediate symptoms are observed. Based
on the current description, a developer might think "this works fine
in my testing, so it's not urgent."

This type bug is particularly dangerous because it can pass code review
and testing, then cause mysterious production failures that are extremely
difficult to trace back to the root cause.

If this sounds like I'm going overboard on an obvious fix, I am doing
so intentionally. I am encouraging you, as a new contributor, to show
that you looked into how kvzalloc() works. I believe it can use either
kmalloc() or vmalloc(). You don't need to be a memory alloc expert to
submit this fix, but demonstrate that you looked beyond a report in a
static analysis tool. Also, that's where the interesting learnings
appear.

Similar to what Markus mentioned, a simple message stating how this
was found is useful too.

--Alison


> ---
>  drivers/fwctl/mlx5/main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/fwctl/mlx5/main.c b/drivers/fwctl/mlx5/main.c
> index f93aa0cecdb9..4b379f695eb7 100644
> --- a/drivers/fwctl/mlx5/main.c
> +++ b/drivers/fwctl/mlx5/main.c
> @@ -345,7 +345,7 @@ static void *mlx5ctl_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
>  	 */
>  	if (ret && ret != -EREMOTEIO) {
>  		if (rpc_out != rpc_in)
> -			kfree(rpc_out);
> +			kvfree(rpc_out);
>  		return ERR_PTR(ret);
>  	}
>  	return rpc_out;
> -- 
> 2.34.1
> 

  parent reply	other threads:[~2025-08-15 18:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-10 18:17 Akhilesh Patil
2025-08-11 15:28 ` Dave Jiang
2025-08-15 14:40 ` Markus Elfring
2025-08-16  4:43   ` Akhilesh Patil
2025-08-15 18:59 ` Alison Schofield [this message]
2025-08-16  4:47   ` Akhilesh Patil
2025-08-16  6:19 ` [PATCH v2] " Akhilesh Patil
2025-08-18 18:33   ` Alison Schofield
2025-08-18 23:53   ` Jason Gunthorpe
2025-08-18 23:55   ` Jason Gunthorpe

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=aJ-DebbVy8-9cEt0@aschofie-mobl2.lan \
    --to=alison.schofield@intel.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=akhilesh@ee.iitb.ac.in \
    --cc=akhileshpatilvnit@gmail.com \
    --cc=dave.jiang@intel.com \
    --cc=itayavr@nvidia.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=saeedm@nvidia.com \
    --cc=skhan@linuxfoundation.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

all inboxes | Powered by JetHome®