Skip to contentSkip to conversation

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

PATCH Superseded Dan Carpenter 2 participants 2 messages Feb 19, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

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")
---
 drivers/cxl/mem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/cxl/mem.c +4 -1
index 8331a2fc7667..d73ab363ad71 100644
@@ -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,
Signature · 1 line
2.30.0
#1 lore raw
Quoted 7 lines · Dan Carpenter

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")

---

Looks good, Dan, thanks!