Commit d1b7f325 authored by Wenwen Wang's avatar Wenwen Wang Committed by Greg Kroah-Hartman

infiniband: hfi1: fix a memory leak bug

[ Upstream commit b08afa06 ]

In fault_opcodes_read(), 'data' is not deallocated if debugfs_file_get()
fails, leading to a memory leak. To fix this bug, 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/1566156571-4335-1-git-send-email-wenwen@cs.uga.eduSigned-off-by: default avatarDoug Ledford <dledford@redhat.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent adb87027
...@@ -214,7 +214,7 @@ static ssize_t fault_opcodes_read(struct file *file, char __user *buf, ...@@ -214,7 +214,7 @@ static ssize_t fault_opcodes_read(struct file *file, char __user *buf,
return -ENOMEM; return -ENOMEM;
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;
bit = find_first_bit(fault->opcodes, bitsize); bit = find_first_bit(fault->opcodes, bitsize);
while (bit < bitsize) { while (bit < bitsize) {
zero = find_next_zero_bit(fault->opcodes, bitsize, bit); zero = find_next_zero_bit(fault->opcodes, bitsize, bit);
...@@ -232,6 +232,7 @@ static ssize_t fault_opcodes_read(struct file *file, char __user *buf, ...@@ -232,6 +232,7 @@ static ssize_t fault_opcodes_read(struct file *file, char __user *buf,
data[size - 1] = '\n'; data[size - 1] = '\n';
data[size] = '\0'; data[size] = '\0';
ret = simple_read_from_buffer(buf, len, pos, data, size); ret = simple_read_from_buffer(buf, len, pos, data, size);
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