diff mbox series

fsi: i2cr-scom: Fix error code in read/write

Message ID ee554aa1-0257-4662-8da5-1ea6be2740e9@moroto.mountain
State New
Headers show
Series fsi: i2cr-scom: Fix error code in read/write | expand

Commit Message

Dan Carpenter Sept. 7, 2023, 9:55 a.m. UTC
The copy_to/from_user() functions return the number of bytes that they
were not able to copy but we want to return negative -EFAULT to the
user.

Fixes: c0b34bed0bbf ("fsi: Add I2C Responder SCOM driver")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/fsi/i2cr-scom.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Eddie James Oct. 2, 2023, 2:57 p.m. UTC | #1
On 9/7/23 04:55, Dan Carpenter wrote:
> The copy_to/from_user() functions return the number of bytes that they
> were not able to copy but we want to return negative -EFAULT to the
> user.


Thanks.

Reviewed-by: Eddie James <eajames@linux.ibm.com>


>
> Fixes: c0b34bed0bbf ("fsi: Add I2C Responder SCOM driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>   drivers/fsi/i2cr-scom.c | 10 ++++------
>   1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/fsi/i2cr-scom.c b/drivers/fsi/i2cr-scom.c
> index cb7e02213032..df1e1df40332 100644
> --- a/drivers/fsi/i2cr-scom.c
> +++ b/drivers/fsi/i2cr-scom.c
> @@ -45,9 +45,8 @@ static ssize_t i2cr_scom_read(struct file *filep, char __user *buf, size_t len,
>   	if (ret)
>   		return ret;
>   
> -	ret = copy_to_user(buf, &data, len);
> -	if (ret)
> -		return ret;
> +	if (copy_to_user(buf, &data, len))
> +		return -EFAULT;
>   
>   	return len;
>   }
> @@ -62,9 +61,8 @@ static ssize_t i2cr_scom_write(struct file *filep, const char __user *buf, size_
>   	if (len != sizeof(data))
>   		return -EINVAL;
>   
> -	ret = copy_from_user(&data, buf, len);
> -	if (ret)
> -		return ret;
> +	if (copy_from_user(&data, buf, len))
> +		return -EFAULT;
>   
>   	ret = fsi_master_i2cr_write(scom->i2cr, (u32)*offset, data);
>   	if (ret)
Dan Carpenter April 8, 2024, 9:57 a.m. UTC | #2
On Mon, Oct 02, 2023 at 09:57:22AM -0500, Eddie James wrote:
> 
> On 9/7/23 04:55, Dan Carpenter wrote:
> > The copy_to/from_user() functions return the number of bytes that they
> > were not able to copy but we want to return negative -EFAULT to the
> > user.
> 
> 
> Thanks.
> 
> Reviewed-by: Eddie James <eajames@linux.ibm.com>
> 

This was never merged.

regards,
dan carpenter


> 
> > 
> > Fixes: c0b34bed0bbf ("fsi: Add I2C Responder SCOM driver")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > ---
> >   drivers/fsi/i2cr-scom.c | 10 ++++------
> >   1 file changed, 4 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/fsi/i2cr-scom.c b/drivers/fsi/i2cr-scom.c
> > index cb7e02213032..df1e1df40332 100644
> > --- a/drivers/fsi/i2cr-scom.c
> > +++ b/drivers/fsi/i2cr-scom.c
> > @@ -45,9 +45,8 @@ static ssize_t i2cr_scom_read(struct file *filep, char __user *buf, size_t len,
> >   	if (ret)
> >   		return ret;
> > -	ret = copy_to_user(buf, &data, len);
> > -	if (ret)
> > -		return ret;
> > +	if (copy_to_user(buf, &data, len))
> > +		return -EFAULT;
> >   	return len;
> >   }
> > @@ -62,9 +61,8 @@ static ssize_t i2cr_scom_write(struct file *filep, const char __user *buf, size_
> >   	if (len != sizeof(data))
> >   		return -EINVAL;
> > -	ret = copy_from_user(&data, buf, len);
> > -	if (ret)
> > -		return ret;
> > +	if (copy_from_user(&data, buf, len))
> > +		return -EFAULT;
> >   	ret = fsi_master_i2cr_write(scom->i2cr, (u32)*offset, data);
> >   	if (ret)
diff mbox series

Patch

diff --git a/drivers/fsi/i2cr-scom.c b/drivers/fsi/i2cr-scom.c
index cb7e02213032..df1e1df40332 100644
--- a/drivers/fsi/i2cr-scom.c
+++ b/drivers/fsi/i2cr-scom.c
@@ -45,9 +45,8 @@  static ssize_t i2cr_scom_read(struct file *filep, char __user *buf, size_t len,
 	if (ret)
 		return ret;
 
-	ret = copy_to_user(buf, &data, len);
-	if (ret)
-		return ret;
+	if (copy_to_user(buf, &data, len))
+		return -EFAULT;
 
 	return len;
 }
@@ -62,9 +61,8 @@  static ssize_t i2cr_scom_write(struct file *filep, const char __user *buf, size_
 	if (len != sizeof(data))
 		return -EINVAL;
 
-	ret = copy_from_user(&data, buf, len);
-	if (ret)
-		return ret;
+	if (copy_from_user(&data, buf, len))
+		return -EFAULT;
 
 	ret = fsi_master_i2cr_write(scom->i2cr, (u32)*offset, data);
 	if (ret)