diff mbox series

cxl/mem: return -EFAULT if copy_to_user() fails

Message ID YC+K3kgzqm20zCWY@mwanda
State New, archived
Headers show
Series cxl/mem: return -EFAULT if copy_to_user() fails | expand

Commit Message

Dan Carpenter Feb. 19, 2021, 9:54 a.m. UTC
The copy_to_user() function returns the number of bytes remaining to be
copied, but we want to return -EFAULT if the copy doesn't complete.

Fixes: b754ffbbc0ee ("cxl/mem: Add basic IOCTL interface")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/cxl/mem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Dan Williams Feb. 19, 2021, 3:39 p.m. UTC | #1
On Fri, Feb 19, 2021 at 1:55 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> The copy_to_user() function returns the number of bytes remaining to be
> copied, but we want to return -EFAULT if the copy doesn't complete.
>
> Fixes: b754ffbbc0ee ("cxl/mem: Add basic IOCTL interface")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---

Looks good, Dan, thanks!
diff mbox series

Patch

diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c
index 8331a2fc7667..d73ab363ad71 100644
--- a/drivers/cxl/mem.c
+++ b/drivers/cxl/mem.c
@@ -745,7 +745,10 @@  static int cxl_send_cmd(struct cxl_memdev *cxlmd,
 	if (rc)
 		return rc;
 
-	return copy_to_user(s, &send, sizeof(send));
+	if (copy_to_user(s, &send, sizeof(send)))
+		return -EFAULT;
+
+	return 0;
 }
 
 static long __cxl_memdev_ioctl(struct cxl_memdev *cxlmd, unsigned int cmd,