diff mbox

[v2] parisc: perf: return -EFAULT on error

Message ID 20161210090625.GA12892@elgon.mountain (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Dan Carpenter Dec. 10, 2016, 9:06 a.m. UTC
The copy_from_user() returns the number of bytes remaining to be copied
but we want to return -EFAULT if it's non-zero.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: Fix unused variable warning.  Thanks, Bojan.

--
To unsubscribe from this list: send the line "unsubscribe linux-parisc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Helge Deller Dec. 10, 2016, 8:40 p.m. UTC | #1
On 10.12.2016 10:06, Dan Carpenter wrote:
> The copy_from_user() returns the number of bytes remaining to be copied
> but we want to return -EFAULT if it's non-zero.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks Dan!
I'll add it to my next push request for the parisc architecture.

Helge


> ---
> v2: Fix unused variable warning.  Thanks, Bojan.
> 
> diff --git a/arch/parisc/kernel/perf.c b/arch/parisc/kernel/perf.c
> index 518f4f5f1f43..6eabce62463b 100644
> --- a/arch/parisc/kernel/perf.c
> +++ b/arch/parisc/kernel/perf.c
> @@ -301,7 +301,6 @@ static ssize_t perf_read(struct file *file, char __user *buf, size_t cnt, loff_t
>  static ssize_t perf_write(struct file *file, const char __user *buf, size_t count, 
>  	loff_t *ppos)
>  {
> -	int err;
>  	size_t image_size;
>  	uint32_t image_type;
>  	uint32_t interface_type;
> @@ -320,8 +319,8 @@ static ssize_t perf_write(struct file *file, const char __user *buf, size_t coun
>  	if (count != sizeof(uint32_t))
>  		return -EIO;
>  
> -	if ((err = copy_from_user(&image_type, buf, sizeof(uint32_t))) != 0) 
> -		return err;
> +	if (copy_from_user(&image_type, buf, sizeof(uint32_t)))
> +		return -EFAULT;
>  
>  	/* Get the interface type and test type */
>     	interface_type = (image_type >> 16) & 0xffff;
> --
> To unsubscribe from this list: send the line "unsubscribe linux-parisc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-parisc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/arch/parisc/kernel/perf.c b/arch/parisc/kernel/perf.c
index 518f4f5f1f43..6eabce62463b 100644
--- a/arch/parisc/kernel/perf.c
+++ b/arch/parisc/kernel/perf.c
@@ -301,7 +301,6 @@  static ssize_t perf_read(struct file *file, char __user *buf, size_t cnt, loff_t
 static ssize_t perf_write(struct file *file, const char __user *buf, size_t count, 
 	loff_t *ppos)
 {
-	int err;
 	size_t image_size;
 	uint32_t image_type;
 	uint32_t interface_type;
@@ -320,8 +319,8 @@  static ssize_t perf_write(struct file *file, const char __user *buf, size_t coun
 	if (count != sizeof(uint32_t))
 		return -EIO;
 
-	if ((err = copy_from_user(&image_type, buf, sizeof(uint32_t))) != 0) 
-		return err;
+	if (copy_from_user(&image_type, buf, sizeof(uint32_t)))
+		return -EFAULT;
 
 	/* Get the interface type and test type */
    	interface_type = (image_type >> 16) & 0xffff;