Commit 01e97e65 authored by Al Viro's avatar Al Viro

new helper: msg_data_left()

convert open-coded instances
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent a2dd3793
...@@ -56,8 +56,8 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg, ...@@ -56,8 +56,8 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
ctx->more = 0; ctx->more = 0;
while (iov_iter_count(&msg->msg_iter)) { while (msg_data_left(msg)) {
int len = iov_iter_count(&msg->msg_iter); int len = msg_data_left(msg);
if (len > limit) if (len > limit)
len = limit; len = limit;
......
...@@ -641,7 +641,7 @@ static int skcipher_recvmsg_sync(struct socket *sock, struct msghdr *msg, ...@@ -641,7 +641,7 @@ static int skcipher_recvmsg_sync(struct socket *sock, struct msghdr *msg,
long copied = 0; long copied = 0;
lock_sock(sk); lock_sock(sk);
while (iov_iter_count(&msg->msg_iter)) { while (msg_data_left(msg)) {
sgl = list_first_entry(&ctx->tsgl, sgl = list_first_entry(&ctx->tsgl,
struct skcipher_sg_list, list); struct skcipher_sg_list, list);
sg = sgl->sg; sg = sgl->sg;
...@@ -655,7 +655,7 @@ static int skcipher_recvmsg_sync(struct socket *sock, struct msghdr *msg, ...@@ -655,7 +655,7 @@ static int skcipher_recvmsg_sync(struct socket *sock, struct msghdr *msg,
goto unlock; goto unlock;
} }
used = min_t(unsigned long, ctx->used, iov_iter_count(&msg->msg_iter)); used = min_t(unsigned long, ctx->used, msg_data_left(msg));
used = af_alg_make_sg(&ctx->rsgl, &msg->msg_iter, used); used = af_alg_make_sg(&ctx->rsgl, &msg->msg_iter, used);
err = used; err = used;
......
...@@ -357,13 +357,13 @@ static void handle_tx(struct vhost_net *net) ...@@ -357,13 +357,13 @@ static void handle_tx(struct vhost_net *net)
iov_iter_init(&msg.msg_iter, WRITE, vq->iov, out, len); iov_iter_init(&msg.msg_iter, WRITE, vq->iov, out, len);
iov_iter_advance(&msg.msg_iter, hdr_size); iov_iter_advance(&msg.msg_iter, hdr_size);
/* Sanity check */ /* Sanity check */
if (!iov_iter_count(&msg.msg_iter)) { if (!msg_data_left(&msg)) {
vq_err(vq, "Unexpected header len for TX: " vq_err(vq, "Unexpected header len for TX: "
"%zd expected %zd\n", "%zd expected %zd\n",
len, hdr_size); len, hdr_size);
break; break;
} }
len = iov_iter_count(&msg.msg_iter); len = msg_data_left(&msg);
zcopy_used = zcopy && len >= VHOST_GOODCOPY_LEN zcopy_used = zcopy && len >= VHOST_GOODCOPY_LEN
&& (nvq->upend_idx + 1) % UIO_MAXIOV != && (nvq->upend_idx + 1) % UIO_MAXIOV !=
......
...@@ -139,6 +139,11 @@ static inline struct cmsghdr * cmsg_nxthdr (struct msghdr *__msg, struct cmsghdr ...@@ -139,6 +139,11 @@ static inline struct cmsghdr * cmsg_nxthdr (struct msghdr *__msg, struct cmsghdr
return __cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg); return __cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg);
} }
static inline size_t msg_data_left(struct msghdr *msg)
{
return iov_iter_count(&msg->msg_iter);
}
/* "Socket"-level control message types: */ /* "Socket"-level control message types: */
#define SCM_RIGHTS 0x01 /* rw: access rights (array of int) */ #define SCM_RIGHTS 0x01 /* rw: access rights (array of int) */
......
...@@ -673,7 +673,7 @@ int skb_copy_and_csum_datagram_msg(struct sk_buff *skb, ...@@ -673,7 +673,7 @@ int skb_copy_and_csum_datagram_msg(struct sk_buff *skb,
if (!chunk) if (!chunk)
return 0; return 0;
if (iov_iter_count(&msg->msg_iter) < chunk) { if (msg_data_left(msg) < chunk) {
if (__skb_checksum_complete(skb)) if (__skb_checksum_complete(skb))
goto csum_error; goto csum_error;
if (skb_copy_datagram_msg(skb, hlen, msg, chunk)) if (skb_copy_datagram_msg(skb, hlen, msg, chunk))
......
...@@ -1119,7 +1119,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) ...@@ -1119,7 +1119,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
sg = !!(sk->sk_route_caps & NETIF_F_SG); sg = !!(sk->sk_route_caps & NETIF_F_SG);
while (iov_iter_count(&msg->msg_iter)) { while (msg_data_left(msg)) {
int copy = 0; int copy = 0;
int max = size_goal; int max = size_goal;
...@@ -1163,8 +1163,8 @@ new_segment: ...@@ -1163,8 +1163,8 @@ new_segment:
} }
/* Try to append data to the end of skb. */ /* Try to append data to the end of skb. */
if (copy > iov_iter_count(&msg->msg_iter)) if (copy > msg_data_left(msg))
copy = iov_iter_count(&msg->msg_iter); copy = msg_data_left(msg);
/* Where to copy to? */ /* Where to copy to? */
if (skb_availroom(skb) > 0) { if (skb_availroom(skb) > 0) {
...@@ -1221,7 +1221,7 @@ new_segment: ...@@ -1221,7 +1221,7 @@ new_segment:
tcp_skb_pcount_set(skb, 0); tcp_skb_pcount_set(skb, 0);
copied += copy; copied += copy;
if (!iov_iter_count(&msg->msg_iter)) { if (!msg_data_left(msg)) {
tcp_tx_timestamp(sk, skb); tcp_tx_timestamp(sk, skb);
goto out; goto out;
} }
......
...@@ -564,8 +564,8 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, ...@@ -564,8 +564,8 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
max &= ~(call->conn->size_align - 1UL); max &= ~(call->conn->size_align - 1UL);
chunk = max; chunk = max;
if (chunk > iov_iter_count(&msg->msg_iter) && !more) if (chunk > msg_data_left(msg) && !more)
chunk = iov_iter_count(&msg->msg_iter); chunk = msg_data_left(msg);
space = chunk + call->conn->size_align; space = chunk + call->conn->size_align;
space &= ~(call->conn->size_align - 1UL); space &= ~(call->conn->size_align - 1UL);
...@@ -608,11 +608,11 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, ...@@ -608,11 +608,11 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
sp = rxrpc_skb(skb); sp = rxrpc_skb(skb);
/* append next segment of data to the current buffer */ /* append next segment of data to the current buffer */
if (iov_iter_count(&msg->msg_iter) > 0) { if (msg_data_left(msg) > 0) {
int copy = skb_tailroom(skb); int copy = skb_tailroom(skb);
ASSERTCMP(copy, >, 0); ASSERTCMP(copy, >, 0);
if (copy > iov_iter_count(&msg->msg_iter)) if (copy > msg_data_left(msg))
copy = iov_iter_count(&msg->msg_iter); copy = msg_data_left(msg);
if (copy > sp->remain) if (copy > sp->remain)
copy = sp->remain; copy = sp->remain;
...@@ -633,7 +633,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, ...@@ -633,7 +633,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
/* add the packet to the send queue if it's now full */ /* add the packet to the send queue if it's now full */
if (sp->remain <= 0 || if (sp->remain <= 0 ||
(iov_iter_count(&msg->msg_iter) == 0 && !more)) { (msg_data_left(msg) == 0 && !more)) {
struct rxrpc_connection *conn = call->conn; struct rxrpc_connection *conn = call->conn;
uint32_t seq; uint32_t seq;
size_t pad; size_t pad;
...@@ -663,7 +663,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, ...@@ -663,7 +663,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
sp->hdr.serviceId = conn->service_id; sp->hdr.serviceId = conn->service_id;
sp->hdr.flags = conn->out_clientflag; sp->hdr.flags = conn->out_clientflag;
if (iov_iter_count(&msg->msg_iter) == 0 && !more) if (msg_data_left(msg) == 0 && !more)
sp->hdr.flags |= RXRPC_LAST_PACKET; sp->hdr.flags |= RXRPC_LAST_PACKET;
else if (CIRC_SPACE(call->acks_head, call->acks_tail, else if (CIRC_SPACE(call->acks_head, call->acks_tail,
call->acks_winsz) > 1) call->acks_winsz) > 1)
...@@ -679,11 +679,10 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, ...@@ -679,11 +679,10 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
memcpy(skb->head, &sp->hdr, memcpy(skb->head, &sp->hdr,
sizeof(struct rxrpc_header)); sizeof(struct rxrpc_header));
rxrpc_queue_packet(call, skb, rxrpc_queue_packet(call, skb, !msg_data_left(msg) && !more);
iov_iter_count(&msg->msg_iter) == 0 && !more);
skb = NULL; skb = NULL;
} }
} while (iov_iter_count(&msg->msg_iter) > 0); } while (msg_data_left(msg) > 0);
success: success:
ret = copied; ret = copied;
......
...@@ -612,7 +612,7 @@ EXPORT_SYMBOL(__sock_tx_timestamp); ...@@ -612,7 +612,7 @@ EXPORT_SYMBOL(__sock_tx_timestamp);
static inline int sock_sendmsg_nosec(struct socket *sock, struct msghdr *msg) static inline int sock_sendmsg_nosec(struct socket *sock, struct msghdr *msg)
{ {
int ret = sock->ops->sendmsg(sock, msg, iov_iter_count(&msg->msg_iter)); int ret = sock->ops->sendmsg(sock, msg, msg_data_left(msg));
BUG_ON(ret == -EIOCBQUEUED); BUG_ON(ret == -EIOCBQUEUED);
return ret; return ret;
} }
...@@ -620,7 +620,7 @@ static inline int sock_sendmsg_nosec(struct socket *sock, struct msghdr *msg) ...@@ -620,7 +620,7 @@ static inline int sock_sendmsg_nosec(struct socket *sock, struct msghdr *msg)
int sock_sendmsg(struct socket *sock, struct msghdr *msg) int sock_sendmsg(struct socket *sock, struct msghdr *msg)
{ {
int err = security_socket_sendmsg(sock, msg, int err = security_socket_sendmsg(sock, msg,
iov_iter_count(&msg->msg_iter)); msg_data_left(msg));
return err ?: sock_sendmsg_nosec(sock, msg); return err ?: sock_sendmsg_nosec(sock, msg);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment