Skip to content

Commit 6601fc0

Browse files
DeanLuickrleon
authored andcommitted
IB/hfi1: Restore allocated resources on failed copyout
Fix a resource leak if an error occurs. Fixes: f404ca4 ("IB/hfi1: Refactor hfi_user_exp_rcv_setup() IOCTL") Signed-off-by: Dean Luick <[email protected]> Signed-off-by: Dennis Dalessandro <[email protected]> Link: https://lore.kernel.org/r/167354736291.2132367.10894218740150168180.stgit@awfm-02.cornelisnetworks.com Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 0f097f0 commit 6601fc0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/infiniband/hw/hfi1/file_ops.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,12 +1318,15 @@ static int user_exp_rcv_setup(struct hfi1_filedata *fd, unsigned long arg,
13181318
addr = arg + offsetof(struct hfi1_tid_info, tidcnt);
13191319
if (copy_to_user((void __user *)addr, &tinfo.tidcnt,
13201320
sizeof(tinfo.tidcnt)))
1321-
return -EFAULT;
1321+
ret = -EFAULT;
13221322

13231323
addr = arg + offsetof(struct hfi1_tid_info, length);
1324-
if (copy_to_user((void __user *)addr, &tinfo.length,
1324+
if (!ret && copy_to_user((void __user *)addr, &tinfo.length,
13251325
sizeof(tinfo.length)))
13261326
ret = -EFAULT;
1327+
1328+
if (ret)
1329+
hfi1_user_exp_rcv_invalid(fd, &tinfo);
13271330
}
13281331

13291332
return ret;

0 commit comments

Comments
 (0)