Skip to content

Commit 18ce65e

Browse files
Uzair Nawazgvisor-bot
authored andcommitted
Fix checklock errors discovered by #12347
The changes in #12347 led to additional errors being reported in existing code. This PR addresses those issues with additional annotations. FUTURE_COPYBARA_INTEGRATE_REVIEW=#12379 from uzairnawaz:fix-new-checklock-errors 74be08b PiperOrigin-RevId: 844243954
1 parent e79ac37 commit 18ce65e

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

pkg/tcpip/transport/tcp/endpoint.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ func (e *Endpoint) LockUser() {
688688
// Finally just give up and wait for the Lock.
689689
e.mu.Lock()
690690
e.ownedByUser.Store(1)
691+
return // +checklocksforce: this locks e.snd.ep.mu
691692
}
692693

693694
// UnlockUser will check if there are any segments already queued for processing
@@ -753,6 +754,7 @@ func (e *Endpoint) AssertLockHeld(locked *Endpoint) {
753754
if e != locked {
754755
panic("AssertLockHeld failed: locked endpoint != asserting endpoint")
755756
}
757+
return // +checklocksforce
756758
}
757759

758760
// TryLock is a helper that calls TryLock on the endpoint's mutex and

tools/checklocks/test/branches.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"math/rand"
1919
)
2020

21-
func testInconsistentReturn(tc *oneGuardStruct) { // +checklocksfail
21+
func testInconsistentReturn(tc *oneGuardStruct) { // +checklocksfail:2
2222
if x := rand.Intn(10); x%2 == 1 {
2323
tc.mu.Lock()
2424
}
@@ -39,7 +39,7 @@ func testConsistentBranching(tc *oneGuardStruct) {
3939
}
4040
}
4141

42-
func testInconsistentBranching(tc *oneGuardStruct) { // +checklocksfail:2
42+
func testInconsistentBranching(tc *oneGuardStruct) { // +checklocksfail:3
4343
// We traverse the control flow graph in all consistent ways. We cannot
4444
// determine however, that the first if block and second if block will
4545
// evaluate to the same condition. Therefore, there are two consistent

tools/checklocks/test/methods.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func standaloneFunctionWithGuard(a *testMethodsWithParameters) {
9696
a.guardedField = 1
9797
a.mu.Unlock()
9898
a.guardedField = 1 // +checklocksfail
99+
return // +checklocksfail
99100
}
100101

101102
type testMethodsWithEmbedded struct {

0 commit comments

Comments
 (0)