gpio: share line requests across read/write instances on the same pin#31508
Open
andig wants to merge 3 commits into
Open
gpio: share line requests across read/write instances on the same pin#31508andig wants to merge 3 commits into
andig wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="plugin/gpio_linux.go" line_range="40-41" />
<code_context>
+
+ key := chip + ":" + strconv.Itoa(pin)
+
+ if sl, ok := lines[key]; ok {
+ if output && !sl.isOutput {
+ if err := sl.line.Reconfigure(gpiocdev.AsOutput(0)); err != nil {
+ return nil, fmt.Errorf("failed to reconfigure GPIO: %w", err)
</code_context>
<issue_to_address>
**issue (bug_risk):** Line reconfiguration should be synchronized with sharedLine.mu to avoid races with concurrent reads/writes.
In `acquireLine`, reconfiguration of an existing line only holds `linesMu` while calling `sl.line.Reconfigure` and updating `sl.isOutput`, whereas getters/setters use `sl.mu`. This allows `Value`/`SetValue` to run concurrently with reconfiguration, risking races at the driver/kernel level. Please also hold `sl.mu` when reconfiguring (e.g., lock `sl.mu` before `Reconfigure` and updating `isOutput`) so all accesses to `sl.line` use the same mutex.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Member
Author
|
/build |
|
✅ Build finished.
|
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #31506
PR #27815 replaced go-rpio (direct register mmap, no exclusive line ownership) with go-gpiocdev (Linux GPIO character-device uAPI, exclusive per-line requests). Any config using the same GPIO pin for both a read function and a write function - as switchsocket configs commonly do, reading back a relay's own driven state on the same pin used to switch it - now fails at startup with "failed to open GPIO: device or resource busy", since the second RequestLine call for that pin is rejected by the kernel.
Not unit-tested: this file is
//go:build linux-only and talks to real/dev/gpiochipNhardware, consistent with it having no existing tests before this change. Verified viaGOOS=linux GOARCH=arm(64) go build/vetand golangci-lint.