mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Akhilesh Patil <akhilesh@ee.iitb.ac.in>
To: saeedm@nvidia.com, itayavr@nvidia.com, dave.jiang@intel.com,
	alison.schofield@intel.com, jgg@ziepe.ca,
	Jonathan.Cameron@huawei.com, Markus.Elfring@web.de
Cc: linux-kernel@vger.kernel.org, akhileshpatilvnit@gmail.com,
	skhan@linuxfoundation.org
Subject: [PATCH v2] fwctl: mlx5: fix memory alloc/free in mlx5ctl_fw_rpc()
Date: Sat, 16 Aug 2025 11:49:54 +0530	[thread overview]
Message-ID: <aKAjCoF9cT3VEbSE@bhairav-test.ee.iitb.ac.in> (raw)
In-Reply-To: <aJjiRqLx9TEg2NFj@bhairav-test.ee.iitb.ac.in>

Use kvfree() to free memory allocated by kvzalloc() instead of kfree().
Avoid potential memory management issue considering kvzalloc() can
internally choose to use either kmalloc() or vmalloc() based on memory
request and current system memory state. Hence, use more appropriate
kvfree() which automatically determines correct free method to avoid
potential hard to debug memory issues.
Fix this issue discovered by running spatch static analysis tool using
coccinelle script - scripts/coccinelle/api/kfree_mismatch.cocci

Fixes: 52929c2142041 ("fwctl/mlx5: Support for communicating with mlx5 fw")
Signed-off-by: Akhilesh Patil <akhilesh@ee.iitb.ac.in>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
---
changes v1 -> v2:
- Update commit message with details on why this issue needs to be fixed
  as suggested by Alison <alison.schofield@intel.com>
- Update commit message with details on how this issue was discovered
  using coccinelle scripts as suggested by Markus <Markus.Elfring@web.de>
- Carry forward Reviewd-by tag from Dave Jiang <dave.jiang@intel.com>
---
 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-16  6:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-10 18:17 [PATCH] " 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
2025-08-16  4:47   ` Akhilesh Patil
2025-08-16  6:19 ` Akhilesh Patil [this message]
2025-08-18 18:33   ` [PATCH v2] " 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=aKAjCoF9cT3VEbSE@bhairav-test.ee.iitb.ac.in \
    --to=akhilesh@ee.iitb.ac.in \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=Markus.Elfring@web.de \
    --cc=akhileshpatilvnit@gmail.com \
    --cc=alison.schofield@intel.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®