Skip to content

Commit

Permalink
net: remove noblock parameter from skb_recv_datagram()
Browse files Browse the repository at this point in the history
skb_recv_datagram() has two parameters 'flags' and 'noblock' that are
merged inside skb_recv_datagram() by 'flags | (noblock ? MSG_DONTWAIT : 0)'

As 'flags' may contain MSG_DONTWAIT as value most callers split the 'flags'
into 'flags' and 'noblock' with finally obsolete bit operations like this:

skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, flags & MSG_DONTWAIT, &rc);

And this is not even done consistently with the 'flags' parameter.

This patch removes the obsolete and costly splitting into two parameters
and only performs bit operations when really needed on the caller side.

One missing conversion thankfully reported by kernel test robot. I missed
to enable kunit tests to build the mctp code.

Reported-by: kernel test robot <[email protected]>
Signed-off-by: Oliver Hartkopp <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
hartkopp authored and davem330 committed Apr 6, 2022
1 parent 0b5c21b commit f4b41f0
Show file tree
Hide file tree
Showing 37 changed files with 57 additions and 70 deletions.
2 changes: 1 addition & 1 deletion drivers/isdn/mISDN/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ mISDN_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
if (sk->sk_state == MISDN_CLOSED)
return 0;

skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &err);
skb = skb_recv_datagram(sk, flags, &err);
if (!skb)
return err;

Expand Down
3 changes: 1 addition & 2 deletions drivers/net/ppp/pppoe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,7 @@ static int pppoe_recvmsg(struct socket *sock, struct msghdr *m,
goto end;
}

skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
flags & MSG_DONTWAIT, &error);
skb = skb_recv_datagram(sk, flags, &error);
if (error < 0)
goto end;

Expand Down
3 changes: 1 addition & 2 deletions include/linux/skbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -3836,8 +3836,7 @@ struct sk_buff *__skb_try_recv_datagram(struct sock *sk,
struct sk_buff *__skb_recv_datagram(struct sock *sk,
struct sk_buff_head *sk_queue,
unsigned int flags, int *off, int *err);
struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
int *err);
struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned int flags, int *err);
__poll_t datagram_poll(struct file *file, struct socket *sock,
struct poll_table_struct *wait);
int skb_copy_datagram_iter(const struct sk_buff *from, int offset,
Expand Down
3 changes: 1 addition & 2 deletions net/appletalk/ddp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1753,8 +1753,7 @@ static int atalk_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
int err = 0;
struct sk_buff *skb;

skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
flags & MSG_DONTWAIT, &err);
skb = skb_recv_datagram(sk, flags, &err);
lock_sock(sk);

if (!skb)
Expand Down
2 changes: 1 addition & 1 deletion net/atm/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ int vcc_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
!test_bit(ATM_VF_READY, &vcc->flags))
return 0;

skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &error);
skb = skb_recv_datagram(sk, flags, &error);
if (!skb)
return error;

Expand Down
3 changes: 1 addition & 2 deletions net/ax25/af_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -1669,8 +1669,7 @@ static int ax25_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
}

/* Now we can treat all alike */
skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
flags & MSG_DONTWAIT, &err);
skb = skb_recv_datagram(sk, flags, &err);
if (skb == NULL)
goto out;

Expand Down
3 changes: 1 addition & 2 deletions net/bluetooth/af_bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ EXPORT_SYMBOL(bt_accept_dequeue);
int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
int flags)
{
int noblock = flags & MSG_DONTWAIT;
struct sock *sk = sock->sk;
struct sk_buff *skb;
size_t copied;
Expand All @@ -263,7 +262,7 @@ int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
if (flags & MSG_OOB)
return -EOPNOTSUPP;

skb = skb_recv_datagram(sk, flags, noblock, &err);
skb = skb_recv_datagram(sk, flags, &err);
if (!skb) {
if (sk->sk_shutdown & RCV_SHUTDOWN)
return 0;
Expand Down
3 changes: 1 addition & 2 deletions net/bluetooth/hci_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,6 @@ static void hci_sock_cmsg(struct sock *sk, struct msghdr *msg,
static int hci_sock_recvmsg(struct socket *sock, struct msghdr *msg,
size_t len, int flags)
{
int noblock = flags & MSG_DONTWAIT;
struct sock *sk = sock->sk;
struct sk_buff *skb;
int copied, err;
Expand All @@ -1470,7 +1469,7 @@ static int hci_sock_recvmsg(struct socket *sock, struct msghdr *msg,
if (sk->sk_state == BT_CLOSED)
return 0;

skb = skb_recv_datagram(sk, flags, noblock, &err);
skb = skb_recv_datagram(sk, flags, &err);
if (!skb)
return err;

Expand Down
2 changes: 1 addition & 1 deletion net/caif/caif_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static int caif_seqpkt_recvmsg(struct socket *sock, struct msghdr *m,
if (flags & MSG_OOB)
goto read_error;

skb = skb_recv_datagram(sk, flags, 0 , &ret);
skb = skb_recv_datagram(sk, flags, &ret);
if (!skb)
goto read_error;
copylen = skb->len;
Expand Down
5 changes: 1 addition & 4 deletions net/can/bcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1632,12 +1632,9 @@ static int bcm_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
struct sock *sk = sock->sk;
struct sk_buff *skb;
int error = 0;
int noblock;
int err;

noblock = flags & MSG_DONTWAIT;
flags &= ~MSG_DONTWAIT;
skb = skb_recv_datagram(sk, flags, noblock, &error);
skb = skb_recv_datagram(sk, flags, &error);
if (!skb)
return error;

Expand Down
4 changes: 1 addition & 3 deletions net/can/isotp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,6 @@ static int isotp_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
struct sock *sk = sock->sk;
struct sk_buff *skb;
struct isotp_sock *so = isotp_sk(sk);
int noblock = flags & MSG_DONTWAIT;
int ret = 0;

if (flags & ~(MSG_DONTWAIT | MSG_TRUNC | MSG_PEEK))
Expand All @@ -1056,8 +1055,7 @@ static int isotp_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
if (!so->bound)
return -EADDRNOTAVAIL;

flags &= ~MSG_DONTWAIT;
skb = skb_recv_datagram(sk, flags, noblock, &ret);
skb = skb_recv_datagram(sk, flags, &ret);
if (!skb)
return ret;

Expand Down
2 changes: 1 addition & 1 deletion net/can/j1939/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ static int j1939_sk_recvmsg(struct socket *sock, struct msghdr *msg,
return sock_recv_errqueue(sock->sk, msg, size, SOL_CAN_J1939,
SCM_J1939_ERRQUEUE);

skb = skb_recv_datagram(sk, flags, 0, &ret);
skb = skb_recv_datagram(sk, flags, &ret);
if (!skb)
return ret;

Expand Down
6 changes: 1 addition & 5 deletions net/can/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,16 +846,12 @@ static int raw_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
struct sock *sk = sock->sk;
struct sk_buff *skb;
int err = 0;
int noblock;

noblock = flags & MSG_DONTWAIT;
flags &= ~MSG_DONTWAIT;

if (flags & MSG_ERRQUEUE)
return sock_recv_errqueue(sk, msg, size,
SOL_CAN_RAW, SCM_CAN_RAW_ERRQUEUE);

skb = skb_recv_datagram(sk, flags, noblock, &err);
skb = skb_recv_datagram(sk, flags, &err);
if (!skb)
return err;

Expand Down
5 changes: 2 additions & 3 deletions net/core/datagram.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,11 @@ struct sk_buff *__skb_recv_datagram(struct sock *sk,
EXPORT_SYMBOL(__skb_recv_datagram);

struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned int flags,
int noblock, int *err)
int *err)
{
int off = 0;

return __skb_recv_datagram(sk, &sk->sk_receive_queue,
flags | (noblock ? MSG_DONTWAIT : 0),
return __skb_recv_datagram(sk, &sk->sk_receive_queue, flags,
&off, err);
}
EXPORT_SYMBOL(skb_recv_datagram);
Expand Down
6 changes: 4 additions & 2 deletions net/ieee802154/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ static int raw_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
int err = -EOPNOTSUPP;
struct sk_buff *skb;

skb = skb_recv_datagram(sk, flags, noblock, &err);
flags |= (noblock ? MSG_DONTWAIT : 0);
skb = skb_recv_datagram(sk, flags, &err);
if (!skb)
goto out;

Expand Down Expand Up @@ -703,7 +704,8 @@ static int dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
struct dgram_sock *ro = dgram_sk(sk);
DECLARE_SOCKADDR(struct sockaddr_ieee802154 *, saddr, msg->msg_name);

skb = skb_recv_datagram(sk, flags, noblock, &err);
flags |= (noblock ? MSG_DONTWAIT : 0);
skb = skb_recv_datagram(sk, flags, &err);
if (!skb)
goto out;

Expand Down
3 changes: 2 additions & 1 deletion net/ipv4/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,8 @@ int ping_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock,
if (flags & MSG_ERRQUEUE)
return inet_recv_error(sk, msg, len, addr_len);

skb = skb_recv_datagram(sk, flags, noblock, &err);
flags |= (noblock ? MSG_DONTWAIT : 0);
skb = skb_recv_datagram(sk, flags, &err);
if (!skb)
goto out;

Expand Down
3 changes: 2 additions & 1 deletion net/ipv4/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,8 @@ static int raw_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
goto out;
}

skb = skb_recv_datagram(sk, flags, noblock, &err);
flags |= (noblock ? MSG_DONTWAIT : 0);
skb = skb_recv_datagram(sk, flags, &err);
if (!skb)
goto out;

Expand Down
3 changes: 2 additions & 1 deletion net/ipv6/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,8 @@ static int rawv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
if (np->rxpmtu && np->rxopt.bits.rxpmtu)
return ipv6_recv_rxpmtu(sk, msg, len, addr_len);

skb = skb_recv_datagram(sk, flags, noblock, &err);
flags |= (noblock ? MSG_DONTWAIT : 0);
skb = skb_recv_datagram(sk, flags, &err);
if (!skb)
goto out;

Expand Down
3 changes: 1 addition & 2 deletions net/iucv/af_iucv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,6 @@ static void iucv_process_message_q(struct sock *sk)
static int iucv_sock_recvmsg(struct socket *sock, struct msghdr *msg,
size_t len, int flags)
{
int noblock = flags & MSG_DONTWAIT;
struct sock *sk = sock->sk;
struct iucv_sock *iucv = iucv_sk(sk);
unsigned int copied, rlen;
Expand All @@ -1242,7 +1241,7 @@ static int iucv_sock_recvmsg(struct socket *sock, struct msghdr *msg,

/* receive/dequeue next skb:
* the function understands MSG_PEEK and, thus, does not dequeue skb */
skb = skb_recv_datagram(sk, flags, noblock, &err);
skb = skb_recv_datagram(sk, flags, &err);
if (!skb) {
if (sk->sk_shutdown & RCV_SHUTDOWN)
return 0;
Expand Down
2 changes: 1 addition & 1 deletion net/key/af_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -3696,7 +3696,7 @@ static int pfkey_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
if (flags & ~(MSG_PEEK|MSG_DONTWAIT|MSG_TRUNC|MSG_CMSG_COMPAT))
goto out;

skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &err);
skb = skb_recv_datagram(sk, flags, &err);
if (skb == NULL)
goto out;

Expand Down
3 changes: 2 additions & 1 deletion net/l2tp/l2tp_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ static int l2tp_ip_recvmsg(struct sock *sk, struct msghdr *msg,
if (flags & MSG_OOB)
goto out;

skb = skb_recv_datagram(sk, flags, noblock, &err);
flags |= (noblock ? MSG_DONTWAIT : 0);
skb = skb_recv_datagram(sk, flags, &err);
if (!skb)
goto out;

Expand Down
3 changes: 2 additions & 1 deletion net/l2tp/l2tp_ip6.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,8 @@ static int l2tp_ip6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
if (flags & MSG_ERRQUEUE)
return ipv6_recv_error(sk, msg, len, addr_len);

skb = skb_recv_datagram(sk, flags, noblock, &err);
flags |= (noblock ? MSG_DONTWAIT : 0);
skb = skb_recv_datagram(sk, flags, &err);
if (!skb)
goto out;

Expand Down
3 changes: 1 addition & 2 deletions net/l2tp/l2tp_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ static int pppol2tp_recvmsg(struct socket *sock, struct msghdr *msg,
goto end;

err = 0;
skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
flags & MSG_DONTWAIT, &err);
skb = skb_recv_datagram(sk, flags, &err);
if (!skb)
goto end;

Expand Down
2 changes: 1 addition & 1 deletion net/mctp/af_mctp.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static int mctp_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
if (flags & ~(MSG_DONTWAIT | MSG_TRUNC | MSG_PEEK))
return -EOPNOTSUPP;

skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &rc);
skb = skb_recv_datagram(sk, flags, &rc);
if (!skb)
return rc;

Expand Down
8 changes: 4 additions & 4 deletions net/mctp/test/route-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,15 @@ static void mctp_test_route_input_sk(struct kunit *test)
if (params->deliver) {
KUNIT_EXPECT_EQ(test, rc, 0);

skb2 = skb_recv_datagram(sock->sk, 0, 1, &rc);
skb2 = skb_recv_datagram(sock->sk, MSG_DONTWAIT, &rc);
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, skb2);
KUNIT_EXPECT_EQ(test, skb->len, 1);

skb_free_datagram(sock->sk, skb2);

} else {
KUNIT_EXPECT_NE(test, rc, 0);
skb2 = skb_recv_datagram(sock->sk, 0, 1, &rc);
skb2 = skb_recv_datagram(sock->sk, MSG_DONTWAIT, &rc);
KUNIT_EXPECT_PTR_EQ(test, skb2, NULL);
}

Expand Down Expand Up @@ -423,7 +423,7 @@ static void mctp_test_route_input_sk_reasm(struct kunit *test)
rc = mctp_route_input(&rt->rt, skb);
}

skb2 = skb_recv_datagram(sock->sk, 0, 1, &rc);
skb2 = skb_recv_datagram(sock->sk, MSG_DONTWAIT, &rc);

if (params->rx_len) {
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, skb2);
Expand Down Expand Up @@ -582,7 +582,7 @@ static void mctp_test_route_input_sk_keys(struct kunit *test)
rc = mctp_route_input(&rt->rt, skb);

/* (potentially) receive message */
skb2 = skb_recv_datagram(sock->sk, 0, 1, &rc);
skb2 = skb_recv_datagram(sock->sk, MSG_DONTWAIT, &rc);

if (params->deliver)
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, skb2);
Expand Down
3 changes: 1 addition & 2 deletions net/netlink/af_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,6 @@ static int netlink_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
struct scm_cookie scm;
struct sock *sk = sock->sk;
struct netlink_sock *nlk = nlk_sk(sk);
int noblock = flags & MSG_DONTWAIT;
size_t copied;
struct sk_buff *skb, *data_skb;
int err, ret;
Expand All @@ -1941,7 +1940,7 @@ static int netlink_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,

copied = 0;

skb = skb_recv_datagram(sk, flags, noblock, &err);
skb = skb_recv_datagram(sk, flags, &err);
if (skb == NULL)
goto out;

Expand Down
3 changes: 2 additions & 1 deletion net/netrom/af_netrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,8 @@ static int nr_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
}

/* Now we can treat all alike */
if ((skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, flags & MSG_DONTWAIT, &er)) == NULL) {
skb = skb_recv_datagram(sk, flags, &er);
if (!skb) {
release_sock(sk);
return er;
}
Expand Down
3 changes: 1 addition & 2 deletions net/nfc/llcp_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,6 @@ static int llcp_sock_sendmsg(struct socket *sock, struct msghdr *msg,
static int llcp_sock_recvmsg(struct socket *sock, struct msghdr *msg,
size_t len, int flags)
{
int noblock = flags & MSG_DONTWAIT;
struct sock *sk = sock->sk;
unsigned int copied, rlen;
struct sk_buff *skb, *cskb;
Expand All @@ -842,7 +841,7 @@ static int llcp_sock_recvmsg(struct socket *sock, struct msghdr *msg,
if (flags & (MSG_OOB))
return -EOPNOTSUPP;

skb = skb_recv_datagram(sk, flags, noblock, &err);
skb = skb_recv_datagram(sk, flags, &err);
if (!skb) {
pr_err("Recv datagram failed state %d %d %d",
sk->sk_state, err, sock_error(sk));
Expand Down
3 changes: 1 addition & 2 deletions net/nfc/rawsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,14 @@ static int rawsock_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
static int rawsock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
int flags)
{
int noblock = flags & MSG_DONTWAIT;
struct sock *sk = sock->sk;
struct sk_buff *skb;
int copied;
int rc;

pr_debug("sock=%p sk=%p len=%zu flags=%d\n", sock, sk, len, flags);

skb = skb_recv_datagram(sk, flags, noblock, &rc);
skb = skb_recv_datagram(sk, flags, &rc);
if (!skb)
return rc;

Expand Down
2 changes: 1 addition & 1 deletion net/packet/af_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -3421,7 +3421,7 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
* but then it will block.
*/

skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &err);
skb = skb_recv_datagram(sk, flags, &err);

/*
* An error occurred so return it. Because skb_recv_datagram()
Expand Down
Loading

0 comments on commit f4b41f0

Please sign in to comment.