Linux-i3c Archive on
 help / color / Atom feed
From: Wenwen Wang <>
To: Wenwen Wang <>
Cc: "open list:I3C SUBSYSTEM" <>,
	open list <>,
	Boris Brezillon <>
Subject: [PATCH] i3c: master: fix a memory leak bug
Date: Sun, 11 Aug 2019 13:33:06 -0500
Message-ID: <> (raw)

In i3c_master_getmwl_locked(), the buffer used for the dest payload data is
allocated using kzalloc() in i3c_ccc_cmd_dest_init(). Later on, the length
of the dest payload data is checked against 'sizeof(*mwl)'. If they are not
equal, -EIO is returned to indicate the error. However, the allocated
buffer is not deallocated on this path, leading to a memory leak.

To fix the above issue, free the buffer before returning the error.

Signed-off-by: Wenwen Wang <>
 drivers/i3c/master.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index d6f8b03..562f69f 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -1084,8 +1084,10 @@ static int i3c_master_getmwl_locked(struct i3c_master_controller *master,
 	if (ret)
 		goto out;
-	if (dest.payload.len != sizeof(*mwl))
-		return -EIO;
+	if (dest.payload.len != sizeof(*mwl)) {
+		ret = -EIO;
+		goto out;
+	}
 	info->max_write_len = be16_to_cpu(mwl->len);

linux-i3c mailing list

                 reply index

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

Reply instructions:

You may reply publically 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:

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

  git send-email \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-i3c Archive on

Archives are clonable:
	git clone --mirror linux-i3c/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-i3c linux-i3c/ \
	public-inbox-index linux-i3c

Newsgroup available over NNTP:

AGPL code for this site: git clone public-inbox