mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: LABBE Corentin <clabbe.montjoie@gmail.com>
To: acme@ghostprotocols.net, davem@davemloft.net
Cc: LABBE Corentin <clabbe.montjoie@gmail.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH 02/11] net: llc: fix a setting of error value to size_t
Date: Fri, 23 Oct 2015 14:10:27 +0200	[thread overview]
Message-ID: <1445602236-24130-3-git-send-email-clabbe.montjoie@gmail.com> (raw)
In-Reply-To: <1445602236-24130-1-git-send-email-clabbe.montjoie@gmail.com>

The variable copied is a size_t, so setting a negative value to it is
invalid.
The patch add an "err" variable for getting the error code.

Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
---
 net/llc/af_llc.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index 8dab4e5..79b915d 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -719,9 +719,10 @@ static int llc_ui_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 	unsigned long used;
 	int target;	/* Read at least this many bytes */
 	long timeo;
+	int err = 0;
 
 	lock_sock(sk);
-	copied = -ENOTCONN;
+	err = -ENOTCONN;
 	if (unlikely(sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_LISTEN))
 		goto out;
 
@@ -745,9 +746,8 @@ static int llc_ui_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 		 * and move it down to the bottom of the loop
 		 */
 		if (signal_pending(current)) {
-			if (copied)
-				break;
-			copied = timeo ? sock_intr_errno(timeo) : -EAGAIN;
+			if (!copied)
+				err = timeo ? sock_intr_errno(timeo) : -EAGAIN;
 			break;
 		}
 
@@ -775,7 +775,7 @@ static int llc_ui_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 				break;
 
 			if (sk->sk_err) {
-				copied = sock_error(sk);
+				err = sock_error(sk);
 				break;
 			}
 			if (sk->sk_shutdown & RCV_SHUTDOWN)
@@ -787,13 +787,15 @@ static int llc_ui_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 					 * This occurs when user tries to read
 					 * from never connected socket.
 					 */
-					copied = -ENOTCONN;
+					err = -ENOTCONN;
+					copied = 0;
 					break;
 				}
 				break;
 			}
 			if (!timeo) {
-				copied = -EAGAIN;
+				err = -EAGAIN;
+				copied = 0;
 				break;
 			}
 		}
@@ -823,7 +825,7 @@ static int llc_ui_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 			if (rc) {
 				/* Exception. Bailout! */
 				if (!copied)
-					copied = -EFAULT;
+					err = -EFAULT;
 				break;
 			}
 		}
@@ -850,6 +852,8 @@ static int llc_ui_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 
 out:
 	release_sock(sk);
+	if (err)
+		return err;
 	return copied;
 copy_uaddr:
 	if (uaddr != NULL && skb != NULL) {
-- 
2.4.10


  parent reply	other threads:[~2015-10-23 12:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-23 12:10 LABBE Corentin
2015-10-23 12:10 ` [PATCH 01/11] net: change len parameter type for memcpy_[to|from]_msg LABBE Corentin
2015-10-23 12:10 ` LABBE Corentin [this message]
2015-10-23 12:10 ` [PATCH 03/11] net: llc: change copied to size_t in llc_ui_sendmsg LABBE Corentin
2015-10-23 12:10 ` [PATCH 04/11] net: packet: change vnet_hdr_len from int to size_t LABBE Corentin
2015-10-23 13:35   ` Michael S. Tsirkin
2015-10-23 12:10 ` [PATCH 05/11] net: irda: change chunk " LABBE Corentin
2015-10-23 12:10 ` [PATCH 06/11] net: ipv6: set the length parameter of rawv6_send_hdrinc() " LABBE Corentin
2015-10-23 12:10 ` [PATCH 07/11] net: caif: change chunk from int " LABBE Corentin
2015-10-23 12:10 ` [PATCH 08/11] net: bluetooth: change the len parameter of sco_send_frame() " LABBE Corentin
2015-10-23 12:30   ` kbuild test robot
2015-10-23 12:36   ` kbuild test robot
2015-10-23 12:40   ` kbuild test robot
2015-10-25 19:54   ` Marcel Holtmann
2015-10-23 12:10 ` [PATCH 09/11] net: ipv6: hlen could be set as size_t LABBE Corentin
2015-10-23 12:33   ` kbuild test robot
2015-10-23 12:46   ` kbuild test robot
2015-10-23 12:10 ` [PATCH 10/11] net: ipv4: " LABBE Corentin
2015-10-23 12:43   ` kbuild test robot
2015-10-23 13:08   ` David Miller
2015-10-23 13:21     ` LABBE Corentin
2015-10-23 13:51       ` David Miller
2015-10-23 12:10 ` [PATCH 11/11] crypto: algif: Change some variable to size_t LABBE Corentin
2015-11-17 14:08   ` Herbert Xu

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=1445602236-24130-3-git-send-email-clabbe.montjoie@gmail.com \
    --to=clabbe.montjoie@gmail.com \
    --cc=acme@ghostprotocols.net \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@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

all inboxes | Powered by JetHome®