Skip to content

Commit ee998cd

Browse files
GoodLuck612Sasha Levin
authored andcommitted
RDMA/mlx5: Fix memory leak in GET_DATA_DIRECT_SYSFS_PATH handler
[ Upstream commit 9b9d253908478f504297ac283c514e5953ddafa6 ] The UVERBS_HANDLER(MLX5_IB_METHOD_GET_DATA_DIRECT_SYSFS_PATH) function allocates memory for the device path using kobject_get_path(). If the length of the device path exceeds the output buffer length, the function returns -ENOSPC but does not free the allocated memory, resulting in a memory leak. Add a kfree() call to the error path to ensure the allocated memory is properly freed. Compile tested only. Issue found using a prototype static analysis tool and code review. Fixes: ec7ad65 ("RDMA/mlx5: Introduce GET_DATA_DIRECT_SYSFS_PATH ioctl") Signed-off-by: Zilin Guan <zilin@seu.edu.cn> Link: https://patch.msgid.link/20260126074801.627898-1-zilin@seu.edu.cn Signed-off-by: Leon Romanovsky <leon@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d533425 commit ee998cd

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/infiniband/hw/mlx5/std_types.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_GET_DATA_DIRECT_SYSFS_PATH)(
214214
int out_len = uverbs_attr_get_len(attrs,
215215
MLX5_IB_ATTR_GET_DATA_DIRECT_SYSFS_PATH);
216216
u32 dev_path_len;
217-
char *dev_path;
217+
char *dev_path = NULL;
218218
int ret;
219219

220220
c = to_mucontext(ib_uverbs_get_ucontext(attrs));
@@ -242,9 +242,9 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_GET_DATA_DIRECT_SYSFS_PATH)(
242242

243243
ret = uverbs_copy_to(attrs, MLX5_IB_ATTR_GET_DATA_DIRECT_SYSFS_PATH, dev_path,
244244
dev_path_len);
245-
kfree(dev_path);
246245

247246
end:
247+
kfree(dev_path);
248248
mutex_unlock(&dev->data_direct_lock);
249249
return ret;
250250
}

0 commit comments

Comments
 (0)