Skip to content

Commit b3078c3

Browse files
committed
Revert "Merge pull request #7 from ZaparooProject/fix-deadlocks"
This reverts commit a6e5239, reversing changes made to 583c8d6.
1 parent a6e5239 commit b3078c3

File tree

17 files changed

+90
-680
lines changed

17 files changed

+90
-680
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ jobs:
3939
run: go mod download
4040

4141
- name: Run tests
42-
run: go test -v -race -timeout 60s ./...
43-
44-
- name: Run deadlock detection tests
45-
run: go test -v -timeout 30s -tags deadlock ./...
42+
run: go test -v -race ./...
4643

4744
lint:
4845
runs-on: ubuntu-latest

.golangci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ linters:
5656
- diagnostic
5757
- style
5858
- performance
59-
staticcheck:
60-
checks: ["all", "SA2003", "SA6002", "SA6005"]
6159
gocyclo:
6260
min-complexity: 15
6361
funlen:

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ readtag:
2626
# Run tests
2727
test:
2828
@echo "Running tests..."
29-
$(GOTEST) -v -race -timeout 60s -coverprofile=coverage.txt -covermode=atomic ./...
30-
29+
$(GOTEST) -v -race -coverprofile=coverage.txt -covermode=atomic ./...
3130

3231
# Run tests with coverage report
3332
coverage: test

cmd/nfctest/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/ZaparooProject/go-pn532"
2828
)
2929

30-
// Mode represents the operating modes for NFC testing
30+
// Operating modes
3131
type Mode int
3232

3333
const (

detection/detector.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// along with go-pn532; if not, write to the Free Software Foundation,
1919
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2020

21-
// Package detection provides device detection and management functionality for PN532 devices
2221
package detection
2322

2423
import (

detection/i2c/detect_linux.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//go:build linux
22

3-
// Package i2c provides I2C device detection functionality for Linux systems
43
package i2c
54

65
import (

detection/spi/detector.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// along with go-pn532; if not, write to the Free Software Foundation,
1919
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2020

21-
// Package spi provides SPI device detection and management functionality
2221
package spi
2322

2423
import (

detection/uart/detector.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// along with go-pn532; if not, write to the Free Software Foundation,
1919
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2020

21-
// Package uart provides UART device detection functionality
2221
package uart
2322

2423
import (

internal/frame/constants.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// along with go-pn532; if not, write to the Free Software Foundation,
1919
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2020

21-
// Package frame provides frame manipulation and protocol constants for PN532 communication
2221
package frame
2322

2423
// Frame direction constants - these indicate the direction of data flow

mifare.go

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,9 @@ func (t *MIFARETag) clearRemainingBlocks(startBlock uint8) error {
727727
func (t *MIFARETag) ResetAuthState() error {
728728
// SECURITY: Thread-safe state clearing
729729
t.authMutex.Lock()
730-
defer t.authMutex.Unlock()
731730
t.lastAuthSector = -1
732731
t.lastAuthKeyType = 0
732+
t.authMutex.Unlock()
733733

734734
// Force PN532 to reset by attempting to re-detect the tag
735735
// This clears any internal authentication state in the PN532 chip
@@ -769,20 +769,18 @@ func (t *MIFARETag) Authenticate(sector uint8, keyType byte, key []byte) error {
769769
_, err := t.device.SendDataExchange(cmd)
770770
if err != nil {
771771
// SECURITY: Thread-safe state clearing on failure
772-
func() {
773-
t.authMutex.Lock()
774-
defer t.authMutex.Unlock()
775-
t.lastAuthSector = -1
776-
t.lastAuthKeyType = 0
777-
}()
772+
t.authMutex.Lock()
773+
t.lastAuthSector = -1
774+
t.lastAuthKeyType = 0
775+
t.authMutex.Unlock()
778776
return fmt.Errorf("authentication failed: %w", err)
779777
}
780778

781779
// SECURITY: Thread-safe state update on success
782780
t.authMutex.Lock()
783-
defer t.authMutex.Unlock()
784781
t.lastAuthSector = int(sector)
785782
t.lastAuthKeyType = keyType
783+
t.authMutex.Unlock()
786784

787785
return nil
788786
}
@@ -804,12 +802,10 @@ func (t *MIFARETag) AuthenticateRobust(sector uint8, keyType byte, key []byte) e
804802
// If standard auth failed, try Chinese clone unlock sequences
805803
if t.tryChineseCloneUnlock(sector) {
806804
// Clone unlock successful, tag is accessible without auth
807-
func() {
808-
t.authMutex.Lock()
809-
defer t.authMutex.Unlock()
810-
t.lastAuthSector = int(sector)
811-
t.lastAuthKeyType = keyType
812-
}()
805+
t.authMutex.Lock()
806+
t.lastAuthSector = int(sector)
807+
t.lastAuthKeyType = keyType
808+
t.authMutex.Unlock()
813809
return nil
814810
}
815811

@@ -878,12 +874,10 @@ func (t *MIFARETag) applyRetryStrategy(level retryLevel, _ error) error {
878874
}
879875

880876
// Clear authentication state
881-
func() {
882-
t.authMutex.Lock()
883-
defer t.authMutex.Unlock()
884-
t.lastAuthSector = -1
885-
t.lastAuthKeyType = 0
886-
}()
877+
t.authMutex.Lock()
878+
t.lastAuthSector = -1
879+
t.lastAuthKeyType = 0
880+
t.authMutex.Unlock()
887881

888882
return nil
889883

@@ -899,12 +893,10 @@ func (t *MIFARETag) applyRetryStrategy(level retryLevel, _ error) error {
899893
time.Sleep(50 * time.Millisecond)
900894
}
901895

902-
func() {
903-
t.authMutex.Lock()
904-
defer t.authMutex.Unlock()
905-
t.lastAuthSector = -1
906-
t.lastAuthKeyType = 0
907-
}()
896+
t.authMutex.Lock()
897+
t.lastAuthSector = -1
898+
t.lastAuthKeyType = 0
899+
t.authMutex.Unlock()
908900

909901
return nil
910902

0 commit comments

Comments
 (0)