Subject: [PATCH][CAN]: Fix copy_from_user() results interpretation.

From: Pavel Emelyanov <[email-masked]>
Date: Fri, 25 Apr 2008 16:42:14 +0400

Sorry for the noise, I had to check this right after facing this problem
with the copy_to_user()...

Both copy_to_ and _from_user return the number of bytes, that failed to
reach their destination, not the 0/-EXXX values.

Other net/ code handles this correctly.

Signed-off-by: Pavel Emelyanov <[email-masked]>

---

diff --git a/net/can/raw.c b/net/can/raw.c
index ead50c7..2be8c6e 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -438,12 +438,12 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
 			err = copy_from_user(filter, optval, optlen);
 			if (err) {
 				kfree(filter);
-				return err;
+				return -EFAULT;
 			}
 		} else if (count == 1) {
 			err = copy_from_user(&sfilter, optval, optlen);
 			if (err)
-				return err;
+				return -EFAULT;
 		}
 
 		lock_sock(sk);
@@ -495,7 +495,7 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
 
 		err = copy_from_user(&err_mask, optval, optlen);
 		if (err)
-			return err;
+			return -EFAULT;
 
 		err_mask &= CAN_ERR_MASK;
 
@@ -531,7 +531,8 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
 		if (optlen != sizeof(ro->loopback))
 			return -EINVAL;
 
-		err = copy_from_user(&ro->loopback, optval, optlen);
+		err = copy_from_user(&ro->loopback, optval, optlen) ?
+			-EFAULT : 0;
 
 		break;
 
@@ -539,7 +540,8 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
 		if (optlen != sizeof(ro->recv_own_msgs))
 			return -EINVAL;
 
-		err = copy_from_user(&ro->recv_own_msgs, optval, optlen);
+		err = copy_from_user(&ro->recv_own_msgs, optval, optlen) ?
+			-EFAULT : 0;
 
 		break;