Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subsys/bluetooth/host/rfcomm.c: Missing unlock #11149

Closed
himanshujha199640 opened this issue Nov 6, 2018 · 10 comments
Closed

subsys/bluetooth/host/rfcomm.c: Missing unlock #11149

himanshujha199640 opened this issue Nov 6, 2018 · 10 comments
Assignees
Labels
area: Bluetooth bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug Waiting for response Waiting for author's response

Comments

@himanshujha199640
Copy link
Collaborator

Found using coccinelle.
#11148

himanshu@himanshu-Vostro-3559:~/zephyr$ spatch -D report --sp-file scripts/coccinelle/mini_lock.cocci --very-quiet subsys/
subsys/bluetooth/host/rfcomm.c:519:2-8: preceding lock on line 516
diff -u -p subsys/bluetooth/host/rfcomm.c /tmp/nothing/bluetooth/host/rfcomm.c
--- subsys/bluetooth/host/rfcomm.c
+++ /tmp/nothing/bluetooth/host/rfcomm.c
@@ -513,10 +513,8 @@ static void rfcomm_check_fc(struct bt_rf
 
 	BT_DBG("Wait for credits or MSC FC %p", dlc);
 	/* Wait for credits or MSC FC */
-	k_sem_take(&dlc->tx_credits, K_FOREVER);
 
 	if (dlc->session->cfc == BT_RFCOMM_CFC_SUPPORTED) {
-		return;
 	}
 
 	k_sem_take(&dlc->session->fc, K_FOREVER);
@@ -527,7 +525,6 @@ static void rfcomm_check_fc(struct bt_rf
 	 * with 1, is received.
 	 */
 	k_sem_give(&dlc->session->fc);
-	k_sem_give(&dlc->tx_credits);
 }
@nashif nashif added bug The issue is a bug, or the PR is fixing a bug and removed bug The issue is a bug, or the PR is fixing a bug labels Nov 8, 2018
@galak galak added the priority: low Low impact/importance bug label Nov 20, 2018
@jhedberg
Copy link
Member

@jkanakkx any chance you could take a look at this? It seems you were the last one to touch these lines of code.

@jhedberg
Copy link
Member

I took a look at the rfcomm.c code, and I'm not completely certain if the proposed fix is the correct one. We'd really need a comment from the code author for this. @jkanakkx would you have a chance to look at this?

@galak
Copy link
Collaborator

galak commented Dec 13, 2018

Seems like a simple fix would be:

diff --git a/subsys/bluetooth/host/rfcomm.c b/subsys/bluetooth/host/rfcomm.c
index 66549f7c5a..b9cc05016b 100644
--- a/subsys/bluetooth/host/rfcomm.c
+++ b/subsys/bluetooth/host/rfcomm.c
@@ -516,6 +516,7 @@ static void rfcomm_check_fc(struct bt_rfcomm_dlc *dlc)
        k_sem_take(&dlc->tx_credits, K_FOREVER);
 
        if (dlc->session->cfc == BT_RFCOMM_CFC_SUPPORTED) {
+               k_sem_give(&dlc->tx_credits);
                return;
        }
 

@jhedberg
Copy link
Member

@galak it might seem so, but I'm not convinced after looking at the code that leaving the semaphore taken in this branch wasn't intentional. There are other places in rfcomm.c which will give it back as well.

@himanshujha199640
Copy link
Collaborator Author

@galak it might seem so, but I'm not convinced after looking at the code that leaving the semaphore taken in this branch wasn't intentional. There are other places in rfcomm.c which will give it back as well.

Agreed!
And I added a similar comment in the script about the false positives:
https://github.com/zephyrproject-rtos/zephyr/blob/master/scripts/coccinelle/mini_lock.cocci#L3

Such cases are hard to script/automate in coccinelle with all nested functions
wounded up.

@jhedberg
Copy link
Member

jhedberg commented Feb 1, 2019

@jkanakkx have you had a chance to look at this? It'd be good to get a comment from the original author (you) whether the semaphore handling is intentional or a bug.

@carlescufi
Copy link
Member

@jhedberg could you find a way to close this one? Thanks!

@galak galak added this to the future milestone Mar 28, 2019
@nashif nashif removed this from the future milestone May 21, 2019
@nashif nashif added the Waiting for response Waiting for author's response label Mar 11, 2020
@nashif
Copy link
Member

nashif commented Mar 11, 2020

@jhedberg ping.

@jhedberg
Copy link
Member

jhedberg commented Mar 11, 2020

@jhedberg ping.

@nashif I don't have any update on this one. I wonder if we could assign it to those who insisted on keeping BR/EDR support in the tree when we proposed to remove it.

@jhedberg
Copy link
Member

..or then just close it since it hasn't been definitely proven that it's a bug

@nashif nashif closed this as completed Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug Waiting for response Waiting for author's response
Projects
None yet
Development

No branches or pull requests

5 participants