diff mbox series

Bluetooth: move adv_instance_cnt read within the device lock

Message ID f181dc17-3b27-436b-15c1-832feb573d25@ugent.be
State Accepted
Commit 4bd80d7a4039ac605a1e9ae767d2b01dbfc9b61e
Headers show
Series Bluetooth: move adv_instance_cnt read within the device lock | expand

Commit Message

Niels Dossche Feb. 12, 2022, 11:14 p.m. UTC
The field adv_instance_cnt is always accessed within a device lock,
except in the function add_advertising. A concurrent remove of an
advertisement with adding another one could result in the if check
"if a new instance was actually added" to not trigger, resulting
in not triggering the "advertising added event".

Signed-off-by: Niels Dossche <niels.dossche@ugent.be>
---
 net/bluetooth/mgmt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

bluez.test.bot@gmail.com Feb. 13, 2022, 12:01 a.m. UTC | #1
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=613797

---Test result---

Test Summary:
CheckPatch                    PASS      1.68 seconds
GitLint                       PASS      1.07 seconds
SubjectPrefix                 PASS      0.91 seconds
BuildKernel                   PASS      35.36 seconds
BuildKernel32                 PASS      31.22 seconds
Incremental Build with patchesPASS      42.65 seconds
TestRunner: Setup             PASS      553.92 seconds
TestRunner: l2cap-tester      PASS      15.31 seconds
TestRunner: bnep-tester       PASS      7.08 seconds
TestRunner: mgmt-tester       PASS      118.06 seconds
TestRunner: rfcomm-tester     PASS      8.97 seconds
TestRunner: sco-tester        PASS      8.99 seconds
TestRunner: smp-tester        PASS      8.89 seconds
TestRunner: userchan-tester   PASS      7.37 seconds



---
Regards,
Linux Bluetooth
Marcel Holtmann March 4, 2022, 3:31 p.m. UTC | #2
Hi Niels,

> The field adv_instance_cnt is always accessed within a device lock,
> except in the function add_advertising. A concurrent remove of an
> advertisement with adding another one could result in the if check
> "if a new instance was actually added" to not trigger, resulting
> in not triggering the "advertising added event".
> 
> Signed-off-by: Niels Dossche <niels.dossche@ugent.be>
> ---
> net/bluetooth/mgmt.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel
diff mbox series

Patch

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 37087cf7dc5a..e0dc72f147b4 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -8046,7 +8046,7 @@  static int add_advertising(struct sock *sk, struct hci_dev *hdev,
 	u32 flags;
 	u8 status;
 	u16 timeout, duration;
-	unsigned int prev_instance_cnt = hdev->adv_instance_cnt;
+	unsigned int prev_instance_cnt;
 	u8 schedule_instance = 0;
 	struct adv_info *next_instance;
 	int err;
@@ -8097,6 +8097,8 @@  static int add_advertising(struct sock *sk, struct hci_dev *hdev,
 		goto unlock;
 	}
 
+	prev_instance_cnt = hdev->adv_instance_cnt;
+
 	err = hci_add_adv_instance(hdev, cp->instance, flags,
 				   cp->adv_data_len, cp->data,
 				   cp->scan_rsp_len,