mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: mdshahid03@gmail.com
To: Andi Shyti <andi.shyti@kernel.org>
Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	Mohammad Shahid <mdshahid03@gmail.com>
Subject: [PATCH] i2c: scmi: fix memory leak on invalid block length
Date: Fri, 20 Nov 2026 11:11:38 +0530	[thread overview]
Message-ID: <20261120054138.194076-1-mdshahid03@gmail.com> (raw)

From: Mohammad Shahid <mdshahid03@gmail.com>

When the returned block length is invalid,the function returns
-EPROTO directly without freeing the ACPI response buffer.

Use goto out instead, so the allocated buffer is freed before
returning the error.

Signed-off-by: Mohammad Shahid <mdshahid03@gmail.com>
---
 drivers/i2c/busses/i2c-scmi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-scmi.c b/drivers/i2c/busses/i2c-scmi.c
index 37442c9ee222..b65771d31a28 100644
--- a/drivers/i2c/busses/i2c-scmi.c
+++ b/drivers/i2c/busses/i2c-scmi.c
@@ -248,8 +248,10 @@ acpi_smbus_cmi_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
 			result = -EIO;
 			goto out;
 		}
-		if (len == 0 || len > I2C_SMBUS_BLOCK_MAX)
-			return -EPROTO;
+		if (len == 0 || len > I2C_SMBUS_BLOCK_MAX) {
+			result = -EPROTO;
+			goto out;
+		}
 		data->block[0] = len;
 		memcpy(data->block + 1, obj->buffer.pointer, len);
 		break;
-- 
2.43.0


                 reply	other threads:[~2026-11-20  5:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261120054138.194076-1-mdshahid03@gmail.com \
    --to=mdshahid03@gmail.com \
    --cc=andi.shyti@kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.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

all inboxes | Powered by JetHome®