diff mbox series

[for-rc,v2] IB/hfi1: Restore allocated resources on failed copyout

Message ID 167354736291.2132367.10894218740150168180.stgit@awfm-02.cornelisnetworks.com (mailing list archive)
State Accepted
Headers show
Series [for-rc,v2] IB/hfi1: Restore allocated resources on failed copyout | expand

Commit Message

Dennis Dalessandro Jan. 12, 2023, 6:16 p.m. UTC
From: Dean Luick <dean.luick@cornelisnetworks.com>

Fix a resource leak if an error occurs.

Fixes: f404ca4c7ea8 ("IB/hfi1: Refactor hfi_user_exp_rcv_setup() IOCTL")
Signed-off-by: Dean Luick <dean.luick@cornelisnetworks.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>

---

Changes from v1:
Do not call copy_to_user() again if the first one failed.
---
 drivers/infiniband/hw/hfi1/file_ops.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Leon Romanovsky Jan. 15, 2023, 10:08 a.m. UTC | #1
On Thu, 12 Jan 2023 13:16:02 -0500, Dennis Dalessandro wrote:
> Fix a resource leak if an error occurs.
> 
> 

Applied, thanks!

[1/1] IB/hfi1: Restore allocated resources on failed copyout
      https://git.kernel.org/rdma/rdma/c/1d58ae793452b2

Best regards,
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/hfi1/file_ops.c
index f5f9269fdc16..7c5d487ec916 100644
--- a/drivers/infiniband/hw/hfi1/file_ops.c
+++ b/drivers/infiniband/hw/hfi1/file_ops.c
@@ -1318,12 +1318,15 @@  static int user_exp_rcv_setup(struct hfi1_filedata *fd, unsigned long arg,
 		addr = arg + offsetof(struct hfi1_tid_info, tidcnt);
 		if (copy_to_user((void __user *)addr, &tinfo.tidcnt,
 				 sizeof(tinfo.tidcnt)))
-			return -EFAULT;
+			ret = -EFAULT;
 
 		addr = arg + offsetof(struct hfi1_tid_info, length);
-		if (copy_to_user((void __user *)addr, &tinfo.length,
+		if (!ret && copy_to_user((void __user *)addr, &tinfo.length,
 				 sizeof(tinfo.length)))
 			ret = -EFAULT;
+
+		if (ret)
+			hfi1_user_exp_rcv_invalid(fd, &tinfo);
 	}
 
 	return ret;