Commit 2323d7ba authored by Wenwen Wang's avatar Wenwen Wang Committed by Doug Ledford

infiniband: hfi1: fix memory leaks

In fault_opcodes_write(), 'data' is allocated through kcalloc(). However,
it is not deallocated in the following execution if an error occurs,
leading to memory leaks. To fix this issue, introduce the 'free_data' label
to free 'data' before returning the error.
Signed-off-by: default avatarWenwen Wang <wenwen@cs.uga.edu>
Reviewed-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Acked-by: default avatarDennis Dalessandro <dennis.dalessandro@intel.com>
Link: https://lore.kernel.org/r/1566154486-3713-1-git-send-email-wenwen@cs.uga.eduSigned-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent b08afa06
...@@ -141,12 +141,14 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf, ...@@ -141,12 +141,14 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf,
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
copy = min(len, datalen - 1); copy = min(len, datalen - 1);
if (copy_from_user(data, buf, copy)) if (copy_from_user(data, buf, copy)) {
return -EFAULT; ret = -EFAULT;
goto free_data;
}
ret = debugfs_file_get(file->f_path.dentry); ret = debugfs_file_get(file->f_path.dentry);
if (unlikely(ret)) if (unlikely(ret))
return ret; goto free_data;
ptr = data; ptr = data;
token = ptr; token = ptr;
for (ptr = data; *ptr; ptr = end + 1, token = ptr) { for (ptr = data; *ptr; ptr = end + 1, token = ptr) {
...@@ -195,6 +197,7 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf, ...@@ -195,6 +197,7 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf,
ret = len; ret = len;
debugfs_file_put(file->f_path.dentry); debugfs_file_put(file->f_path.dentry);
free_data:
kfree(data); kfree(data);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment