mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fsi: i2cr-scom: Return -EFAULT on usercopy failures
@ 2026-09-14  6:24 Karl Mehltretter
  2026-10-15  5:54 ` Karl Mehltretter
  0 siblings, 1 reply; 2+ messages in thread
From: Karl Mehltretter @ 2026-09-14  6:24 UTC (permalink / raw)
  To: Eddie James
  Cc: Karl Mehltretter, Ninad Palsule, Joel Stanley, linux-fsi, linux-kernel

copy_to_user() and copy_from_user() return the number of bytes that were
not copied. i2cr_scom_read() and i2cr_scom_write() return that value
directly, so a usercopy fault is reported as a successful short I/O.

Return -EFAULT when either copy fails.

A temporary KUnit test called i2cr_scom_write() with an invalid user
pointer. The unmodified kernel returned 8. With this change it returned
-EFAULT. Both versions were booted under QEMU.

Fixes: c0b34bed0bbf ("fsi: Add I2C Responder SCOM driver")
Assisted-by: LLM
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
 drivers/fsi/i2cr-scom.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/fsi/i2cr-scom.c b/drivers/fsi/i2cr-scom.c
index 83b3c03..7edd3e5 100644
--- a/drivers/fsi/i2cr-scom.c
+++ b/drivers/fsi/i2cr-scom.c
@@ -46,7 +46,7 @@ static ssize_t i2cr_scom_read(struct file *filep, char __user *buf, size_t len,
 
 	ret = copy_to_user(buf, &data, len);
 	if (ret)
-		return ret;
+		return -EFAULT;
 
 	return len;
 }
@@ -63,7 +63,7 @@ static ssize_t i2cr_scom_write(struct file *filep, const char __user *buf, size_
 
 	ret = copy_from_user(&data, buf, len);
 	if (ret)
-		return ret;
+		return -EFAULT;
 
 	ret = fsi_master_i2cr_write(scom->i2cr, (u32)*offset, data);
 	if (ret)

base-commit: 22098763a10d9c1340827fcf6edab66f153b27f0
-- 
2.53.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-15  5:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-14  6:24 [PATCH] fsi: i2cr-scom: Return -EFAULT on usercopy failures Karl Mehltretter
2026-10-15  5:54 ` Karl Mehltretter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®