From: Wenwen Wang Date: Sun, 11 Aug 2019 18:33:06 +0000 (-0500) Subject: i3c: master: fix a memory leak bug X-Git-Tag: v5.4-rc1~195^2~1 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=7afe9a4e56658bd659660ea10671831664469e5f;p=linux.git i3c: master: fix a memory leak bug 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 Signed-off-by: Boris Brezillon --- diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index a38fdf325d30..8ff527263f46 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1041,8 +1041,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);