Skip to content

Commit b2bc649

Browse files
GoodLuck612gregkh
authored andcommitted
RDMA/mlx5: Fix memory leak in GET_DATA_DIRECT_SYSFS_PATH handler
[ Upstream commit 9b9d253 ] 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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent bf4454d commit b2bc649

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/infiniband/hw/mlx5/std_types.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_GET_DATA_DIRECT_SYSFS_PATH)(
195195
int out_len = uverbs_attr_get_len(attrs,
196196
MLX5_IB_ATTR_GET_DATA_DIRECT_SYSFS_PATH);
197197
u32 dev_path_len;
198-
char *dev_path;
198+
char *dev_path = NULL;
199199
int ret;
200200

201201
c = to_mucontext(ib_uverbs_get_ucontext(attrs));
@@ -223,9 +223,9 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_GET_DATA_DIRECT_SYSFS_PATH)(
223223

224224
ret = uverbs_copy_to(attrs, MLX5_IB_ATTR_GET_DATA_DIRECT_SYSFS_PATH, dev_path,
225225
dev_path_len);
226-
kfree(dev_path);
227226

228227
end:
228+
kfree(dev_path);
229229
mutex_unlock(&dev->data_direct_lock);
230230
return ret;
231231
}

0 commit comments

Comments
 (0)