platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: Orlando Chamberlain <orlandoch.dev@gmail.com>
Cc: Mark Gross <markgross@kernel.org>,
	platform-driver-x86@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: [PATCH] platform/x86: apple-gmux: return -EFAULT if copy fails
Date: Fri, 10 Mar 2023 15:31:13 +0300	[thread overview]
Message-ID: <0bdfa8c2-cb22-4bec-8773-584060613043@kili.mountain> (raw)

The copy_to/from_user() functions return the number of bytes remaining
to be copied, but we want to return -EFAULT to the user.

Fixes: ce3fef2eb235 ("platform/x86: apple-gmux: add debugfs interface")
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
 drivers/platform/x86/apple-gmux.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c
index 787cf2a7e268..77e63d2da7b6 100644
--- a/drivers/platform/x86/apple-gmux.c
+++ b/drivers/platform/x86/apple-gmux.c
@@ -694,7 +694,6 @@ static ssize_t gmux_selected_port_data_write(struct file *file,
 		const char __user *userbuf, size_t count, loff_t *ppos)
 {
 	struct apple_gmux_data *gmux_data = file->private_data;
-	int ret;
 
 	if (*ppos)
 		return -EINVAL;
@@ -702,16 +701,16 @@ static ssize_t gmux_selected_port_data_write(struct file *file,
 	if (count == 1) {
 		u8 data;
 
-		ret = copy_from_user(&data, userbuf, 1);
-		if (ret)
-			return ret;
+		if (copy_from_user(&data, userbuf, 1))
+			return -EFAULT;
+
 		gmux_write8(gmux_data, gmux_data->selected_port, data);
 	} else if (count == 4) {
 		u32 data;
 
-		ret = copy_from_user(&data, userbuf, 4);
-		if (ret)
-			return ret;
+		if (copy_from_user(&data, userbuf, 4))
+			return -EFAULT;
+
 		gmux_write32(gmux_data, gmux_data->selected_port, data);
 	} else
 		return -EINVAL;
-- 
2.39.1


             reply	other threads:[~2023-03-10 12:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-10 12:31 Dan Carpenter [this message]
2023-03-14 11:13 ` [PATCH] platform/x86: apple-gmux: return -EFAULT if copy fails Orlando Chamberlain
2023-03-16 12:24 ` Hans de Goede

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=0bdfa8c2-cb22-4bec-8773-584060613043@kili.mountain \
    --to=error27@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=markgross@kernel.org \
    --cc=orlandoch.dev@gmail.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).