Skip to contentSkip to conversation

net/tls: Do not call msg_data_left() twice

PATCH In review Vakul Garg 2 participants 3 messages Jul 24, 2018 – Jul 25, 2018

Subsystems (3)
lore
Share & tools
lore

Vakul Garg

author
#0 lore raw

PATCH 1/1 net/tls: Do not call msg_data_left() twice

In function tls_sw_sendmsg(), msg_data_left() needs to be called only once. The second invocation of msg_data_left() for assigning variable try_to_copy can be removed and merged with the first one.

---
 net/tls/tls_sw.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/tls/tls_sw.c +1 -2
index 0c2d029c9d4c..fd51ce65b99c 100644
@@ -377,7 +377,7 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
 			goto send_end;
 	}
 
-	while (msg_data_left(msg)) {
+	while ((try_to_copy = msg_data_left(msg))) {
 		if (sk->sk_err) {
 			ret = -sk->sk_err;
 			goto send_end;
@@ -385,7 +385,6 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
 
 		orig_size = ctx->sg_plaintext_size;
 		full_record = false;
-		try_to_copy = msg_data_left(msg);
 		record_room = TLS_MAX_PAYLOAD_SIZE - ctx->sg_plaintext_size;
 		if (try_to_copy >= record_room) {
 			try_to_copy = record_room;
Signature · 1 line
2.13.6
#1 lore raw
Quoted 3 lines · Vakul Garg

In function tls_sw_sendmsg(), msg_data_left() needs to be called only once. The second invocation of msg_data_left() for assigning variable try_to_copy can be removed and merged with the first one.

You do realize that msg_data_left(msg) is simply msg->msg_iter.count? So I'm not at all sure that your change will be an overall win...

author
#2 lore raw

From: Al Viro
Sent: Wednesday, 25 July, 7:19 AM
Subject: Re: [PATCH net-next] net/tls: Do not call msg_data_left() twice
To: Vakul Garg
Cc: [email protected], [email protected], [email protected], [email protected], [email protected]

On Tue, Jul 24, 2018 at 04:41:18PM +0530, Vakul Garg wrote: > In function tls_sw_sendmsg(), msg_data_left() needs to be called only > once. The second invocation of msg_data_left() for assigning variable > try_to_copy can be removed and merged with the first one. You do realize that msg_data_left(msg) is simply msg->msg_iter.count? So I'm not at all sure that your change will be an overall win...

Agreed, msg_data_left is inexpensive. It's just that is pointless to call it again.