mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Karl Mehltretter <kmehltretter@gmail.com>
To: Eddie James <eajames@linux.ibm.com>
Cc: Karl Mehltretter <kmehltretter@gmail.com>,
	Ninad Palsule <ninad@linux.ibm.com>,
	Joel Stanley <joel@jms.id.au>,
	linux-fsi@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH] fsi: i2cr-scom: Return -EFAULT on usercopy failures
Date: Mon, 14 Sep 2026 08:24:26 +0200	[thread overview]
Message-ID: <20260914062426.14140-1-kmehltretter@gmail.com> (raw)

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


             reply	other threads:[~2026-09-14  6:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14  6:24 Karl Mehltretter [this message]
2026-10-15  5:54 ` Karl Mehltretter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260914062426.14140-1-kmehltretter@gmail.com \
    --to=kmehltretter@gmail.com \
    --cc=eajames@linux.ibm.com \
    --cc=joel@jms.id.au \
    --cc=linux-fsi@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ninad@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®