Skip to contentSkip to conversation

Bluetooth: fix incorrect nonblock bitmask in bt_sock_wait_ready()

PATCH Superseded [email protected] 3 participants 6 messages Feb 24, 2022 – Mar 14, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: fix incorrect nonblock bitmask in bt_sock_wait_ready()

From: Gavin Li <[email protected]>

Callers pass msg->msg_flags as flags, which contains MSG_DONTWAIT instead of O_NONBLOCK.

---
 include/net/bluetooth/bluetooth.h | 2 +-
 net/bluetooth/af_bluetooth.c      | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
include/net/bluetooth/bluetooth.h +1 -1
index a647e5fabdbd6..87f0bba39b0f7 100644
@@ -343,7 +343,7 @@ int  bt_sock_stream_recvmsg(struct socket *sock, struct msghdr *msg,
 __poll_t bt_sock_poll(struct file *file, struct socket *sock, poll_table *wait);
 int  bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
 int  bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo);
-int  bt_sock_wait_ready(struct sock *sk, unsigned long flags);
+int  bt_sock_wait_ready(struct sock *sk, unsigned int flags);
 
 void bt_accept_enqueue(struct sock *parent, struct sock *sk, bool bh);
 void bt_accept_unlink(struct sock *sk);
net/bluetooth/af_bluetooth.c +2 -2
index ee319779781e6..69374321130e4 100644
@@ -568,7 +568,7 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
 EXPORT_SYMBOL(bt_sock_wait_state);
 
 /* This function expects the sk lock to be held when called */
-int bt_sock_wait_ready(struct sock *sk, unsigned long flags)
+int bt_sock_wait_ready(struct sock *sk, unsigned int flags)
 {
 	DECLARE_WAITQUEUE(wait, current);
 	unsigned long timeo;
@@ -576,7 +576,7 @@ int bt_sock_wait_ready(struct sock *sk, unsigned long flags)
 
 	BT_DBG("sk %p", sk);
 
-	timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
+	timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT);
 
 	add_wait_queue(sk_sleep(sk), &wait);
 	set_current_state(TASK_INTERRUPTIBLE);
Signature · 1 line
2.34.1
#1 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=617495

---Test result---

Test Summary:

CheckPatch                    PASS      1.94 seconds
GitLint                       PASS      1.00 seconds
SubjectPrefix                 PASS      0.83 seconds
BuildKernel                   PASS      36.68 seconds
BuildKernel32                 PASS      32.49 seconds
Incremental Build with patchesPASS      46.70 seconds
TestRunner: Setup             PASS      556.83 seconds
TestRunner: l2cap-tester      PASS      15.42 seconds
TestRunner: bnep-tester       PASS      7.09 seconds
TestRunner: mgmt-tester       PASS      118.87 seconds
TestRunner: rfcomm-tester     PASS      9.20 seconds
TestRunner: sco-tester        PASS      9.41 seconds
TestRunner: smp-tester        PASS      9.20 seconds
TestRunner: userchan-tester   PASS      7.50 seconds

---
Regards,
Linux Bluetooth

maintainer
#2 lore raw
In reply to [email protected]

Hi Gavin,

Quoted 27 lines

Callers pass msg->msg_flags as flags, which contains MSG_DONTWAIT instead of O_NONBLOCK.

---
include/net/bluetooth/bluetooth.h | 2 +-
net/bluetooth/af_bluetooth.c | 4 ++--

2 files changed, 3 insertions(+), 3 deletions(-)
include/net/bluetooth/bluetooth.h +1 -1
index a647e5fabdbd6..87f0bba39b0f7 100644
@@ -343,7 +343,7 @@ int  bt_sock_stream_recvmsg(struct socket *sock, struct msghdr *msg,
 __poll_t bt_sock_poll(struct file *file, struct socket *sock, poll_table *wait);
 int  bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
 int  bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo);
-int  bt_sock_wait_ready(struct sock *sk, unsigned long flags);
+int  bt_sock_wait_ready(struct sock *sk, unsigned int flags);
 
 void bt_accept_enqueue(struct sock *parent, struct sock *sk, bool bh);
 void bt_accept_unlink(struct sock *sk);
net/bluetooth/af_bluetooth.c +0 -0
index ee319779781e6..69374321130e4 100644

net/bluetooth/af_bluetooth.c int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo) · line 571

Quoted 5 lines
net/bluetooth/af_bluetooth.c +1 -1
@@ -568,7 +568,7 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
 EXPORT_SYMBOL(bt_sock_wait_state);
 
 /* This function expects the sk lock to be held when called */
-int bt_sock_wait_ready(struct sock *sk, unsigned long flags)
+int bt_sock_wait_ready(struct sock *sk, unsigned int flags)

can we then also do s/flags/msg_flags/ then.

net/bluetooth/af_bluetooth.c int bt_sock_wait_ready(struct sock *sk, unsigned long flags) · line 579

Quoted 9 lines
net/bluetooth/af_bluetooth.c +1 -1
 {
 	DECLARE_WAITQUEUE(wait, current);
 	unsigned long timeo;
@@ -576,7 +576,7 @@ int bt_sock_wait_ready(struct sock *sk, unsigned long flags)
 
 	BT_DBG("sk %p", sk);
 
-	timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
+	timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT);

Since sock_sndtimeo() is taking a bool. This might be better !!(flags & MSG_DONTWAIT).

Regards

Marcel

author
#3 lore raw

Hi Marcel,

Thanks for reviewing this quickly.

Quoted 7 lines
Quoted 7 lines
net/bluetooth/af_bluetooth.c +0 -0
index ee319779781e6..69374321130e4 100644
@@ -568,7 +568,7 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
 EXPORT_SYMBOL(bt_sock_wait_state);
 
Quoted 5 lines

net/bluetooth/af_bluetooth.c int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo) · line 571

Quoted 3 lines
net/bluetooth/af_bluetooth.c +1 -1
 /* This function expects the sk lock to be held when called */
-int bt_sock_wait_ready(struct sock *sk, unsigned long flags)
+int bt_sock_wait_ready(struct sock *sk, unsigned int flags)

can we then also do s/flags/msg_flags/ then.

I prefer keeping it as flags because all other net code also uses flags, msg_flags only appears
in msg->msg_flags.

Quoted 8 lines

net/bluetooth/af_bluetooth.c int bt_sock_wait_ready(struct sock *sk, unsigned long flags) · line 579

Quoted 6 lines
net/bluetooth/af_bluetooth.c +1 -1
@@ -576,7 +576,7 @@ int bt_sock_wait_ready(struct sock *sk, unsigned long flags)
 
      BT_DBG("sk %p", sk);
 
-     timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
+     timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT);

Since sock_sndtimeo() is taking a bool. This might be better !!(flags & MSG_DONTWAIT).

It appears to be well-known in the net code that sock_sndtimeo takes a bool, since no other
uses of it do the "!!" conversion.

Let me know what you think. I can make the changes if needed but I was just trying my best
to match the currently existing convention.

Best,
Gavin

author
#4 lore raw

Hi Marcel,

Please let me know what you think with regards to the comments above.

Best,
Gavin

Quoted 39 lines · Gavin Li

Hi Marcel,

Thanks for reviewing this quickly.

Quoted 7 lines
Quoted 7 lines
net/bluetooth/af_bluetooth.c +0 -0
index ee319779781e6..69374321130e4 100644
@@ -568,7 +568,7 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
 EXPORT_SYMBOL(bt_sock_wait_state);
 
Quoted 5 lines

net/bluetooth/af_bluetooth.c int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo) · line 571

Quoted 3 lines
net/bluetooth/af_bluetooth.c +1 -1
 /* This function expects the sk lock to be held when called */
-int bt_sock_wait_ready(struct sock *sk, unsigned long flags)
+int bt_sock_wait_ready(struct sock *sk, unsigned int flags)

can we then also do s/flags/msg_flags/ then.

I prefer keeping it as flags because all other net code also uses flags, msg_flags only appears
in msg->msg_flags.

Quoted 8 lines

net/bluetooth/af_bluetooth.c int bt_sock_wait_ready(struct sock *sk, unsigned long flags) · line 579

Quoted 6 lines
net/bluetooth/af_bluetooth.c +1 -1
@@ -576,7 +576,7 @@ int bt_sock_wait_ready(struct sock *sk, unsigned long flags)
 
      BT_DBG("sk %p", sk);
 
-     timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
+     timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT);

Since sock_sndtimeo() is taking a bool. This might be better !!(flags & MSG_DONTWAIT).

It appears to be well-known in the net code that sock_sndtimeo takes a bool, since no other
uses of it do the "!!" conversion.

Let me know what you think. I can make the changes if needed but I was just trying my best
to match the currently existing convention.

Best,
Gavin

maintainer
#5 lore raw
In reply to Gavin Li

Hi Gavin,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
net/bluetooth/af_bluetooth.c +0 -0
index ee319779781e6..69374321130e4 100644
@@ -568,7 +568,7 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
 EXPORT_SYMBOL(bt_sock_wait_state);
 
Quoted 8 lines
Quoted 5 lines

net/bluetooth/af_bluetooth.c int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo) · line 571

Quoted 3 lines
net/bluetooth/af_bluetooth.c +1 -1
 /* This function expects the sk lock to be held when called */
-int bt_sock_wait_ready(struct sock *sk, unsigned long flags)
+int bt_sock_wait_ready(struct sock *sk, unsigned int flags)

can we then also do s/flags/msg_flags/ then.

I prefer keeping it as flags because all other net code also uses flags, msg_flags only appears
in msg->msg_flags.

while that might be true, I find it a lot clearer if the variable is msg_flags.

Quoted 8 lines
Quoted 8 lines

net/bluetooth/af_bluetooth.c int bt_sock_wait_ready(struct sock *sk, unsigned long flags) · line 579

Quoted 6 lines
net/bluetooth/af_bluetooth.c +1 -1
@@ -576,7 +576,7 @@ int bt_sock_wait_ready(struct sock *sk, unsigned long flags)
 
     BT_DBG("sk %p", sk);
 
-     timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
+     timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT);

Since sock_sndtimeo() is taking a bool. This might be better !!(flags & MSG_DONTWAIT).

Quoted 7 lines

It appears to be well-known in the net code that sock_sndtimeo takes a bool, since no other
uses of it do the "!!" conversion.

Let me know what you think. I can make the changes if needed but I was just trying my best
to match the currently existing convention.

And other code in the kernel makes sure to clearly turn something into a bool. You get 0x00 and 0x40.

Regards

Marcel