platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] platform/x86: apple-gmux: return -EFAULT if copy fails
@ 2023-03-10 12:31 Dan Carpenter
  2023-03-14 11:13 ` Orlando Chamberlain
  2023-03-16 12:24 ` Hans de Goede
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2023-03-10 12:31 UTC (permalink / raw)
  To: Orlando Chamberlain; +Cc: Mark Gross, platform-driver-x86, kernel-janitors

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


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

* Re: [PATCH] platform/x86: apple-gmux: return -EFAULT if copy fails
  2023-03-10 12:31 [PATCH] platform/x86: apple-gmux: return -EFAULT if copy fails Dan Carpenter
@ 2023-03-14 11:13 ` Orlando Chamberlain
  2023-03-16 12:24 ` Hans de Goede
  1 sibling, 0 replies; 3+ messages in thread
From: Orlando Chamberlain @ 2023-03-14 11:13 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Mark Gross, platform-driver-x86, kernel-janitors

On Fri, 10 Mar 2023 15:31:13 +0300
Dan Carpenter <error27@gmail.com> wrote:

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

I didn't realise that, thanks for fixing it!

Reviewed-by: Orlando Chamberlain <orlandlch.dev@gmail.com>
> 
> 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;


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

* Re: [PATCH] platform/x86: apple-gmux: return -EFAULT if copy fails
  2023-03-10 12:31 [PATCH] platform/x86: apple-gmux: return -EFAULT if copy fails Dan Carpenter
  2023-03-14 11:13 ` Orlando Chamberlain
@ 2023-03-16 12:24 ` Hans de Goede
  1 sibling, 0 replies; 3+ messages in thread
From: Hans de Goede @ 2023-03-16 12:24 UTC (permalink / raw)
  To: Dan Carpenter, Orlando Chamberlain
  Cc: Mark Gross, platform-driver-x86, kernel-janitors

Hi,

On 3/10/23 13:31, Dan Carpenter wrote:
> 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>

Thank you for your patch, I've applied this patch to my review-hans 
branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my
local branch there, which might take a while.

Once I've run some tests on this branch the patches there will be
added to the platform-drivers-x86/for-next branch and eventually
will be included in the pdx86 pull-request to Linus for the next
merge-window.

Regards,

Hans


> ---
>  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;


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

end of thread, other threads:[~2023-03-16 12:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-10 12:31 [PATCH] platform/x86: apple-gmux: return -EFAULT if copy fails Dan Carpenter
2023-03-14 11:13 ` Orlando Chamberlain
2023-03-16 12:24 ` Hans de Goede

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