Repository navigation
Keeping a GPIO pin exported after a sysfs write - #76
DeathCamel58 wants to merge 3 commits into
Conversation
PR Summary by QodoKeep legacy sysfs GPIO outputs exported until no longer needed
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
Code Review by Qodo
1.
|
…g unused pins The previous commit leaves a pin exported after a write, which raised two problems in review: - gpio_node() decided between "gpio<n>" and "GPIO<n>" (Fullhan) from the first pin it was asked about and cached the answer. With the new "export only if the node is missing" check, that first question came before the export, so on Fullhan kernels the lowercase name was cached and the direction write then failed. The format is now cached only once a node actually exists, and a pin with no node yet is exported before its name is resolved. - Output pins were never unexported, so /api/night disabling night mode, or moving a pin, left the old one exported at its last level. /api/night now releases a pin that is no longer in use through a new gpio_release(). It does not release in gpio_deinit(): the night thread calls that every time it stops, and every /api/night request restarts it, so doing so there would drop the IR LEDs on each request. tst/gpio-sysfs runs the sysfs path against a fake sysfs in a temporary directory (once for each node name) and fails on the previous commit: first write on a not-yet-exported pin, no re-export on later writes, and release. Tested on an Amcrest IP4M-1026E (Ambarella S3L, Linux 3.10, lowercase nodes): GPIO 5 stays "out hi" while night mode is on, is released by /api/night?enable=0 and by moving irled_pin, and is back after re-enabling. The Fullhan naming is covered only by the fake sysfs; it has not been run on a Fullhan camera.
|
I pushed a second commit, dbd2a80. It answers the two findings from the automated review of the first commit. I don't expect that review to run again, so here is how each is handled, and one thing I can't test myself. 1. First write on a Fullhan kernel (the node name was cached too early). Right: with the new "export only if the node is missing" check, 2. Pins stay exported after night mode is turned off or a pin is moved. Fixed in Tests. Could someone with a Fullhan camera test this? I don't have one, so the
Please report the SoC, |
The previous commit let /api/night release a pin that was no longer in use, by unexporting any pin with a sysfs node. Review of that commit found four problems with it, which share one cause: nothing recorded who exported a pin. - A client could make Divinus unexport a pin another component holds: moving irled_pin to that pin and away again made the old assignment look like ours to release. - A pin assigned and driven in the same request (irled_pin=5&irled=true&enable=0) was never in the list of old pins and stayed exported. - The Fullhan white-lamp pin (GPIO 11, driven by fh_lamp_enable) was not in the list of pins night mode uses. - A normal shutdown never reached the release at all. gpio_write() now records the pins it exports itself, and only those are ever unexported: gpio_release() ignores any other pin, and gpio_release_unused() lets go of every recorded pin that is not in a list of pins still in use. /api/night passes it the pins night mode drives (new night_pins(), which includes the Fullhan lamp pin on the F1) when night mode stays on, and none when it is switched off, so a pin assigned and driven within one request is released too. main() releases whatever is still recorded after the night thread stops. gpio_deinit() still does not, for the reason in the previous commit: the night thread calls it every time /api/night restarts it. tst/gpio-sysfs now also covers a pin exported by someone else being left alone (written to, but never unexported), release of everything not in use, and a released pin being ours again when it is exported again. The new checks fail on the previous commit. Tested on an Amcrest IP4M-1026E (Ambarella S3L, Linux 3.10) with Majestic's leftover exports on the pins, one of them kept as a pin Divinus did not export: enable=0 released the two Divinus exported and left the other; enable=1 brought them back; moving irled_pin away released it; irled_pin=5&irled=true&enable=0 in one request left nothing of ours exported; SIGTERM released both and again left the other. The Fullhan lamp pin and the Fullhan naming have not been run on a Fullhan camera; they are covered only by the fake sysfs and by reading the code.
|
Thanks for the re-review. The first two findings are marked resolved. It found four more, all about the new
Clients can release another GPIO user's pin. A pin this process did not export is never unexported, so moving One night request leaves a new LED lit ( The Fullhan white-lamp pin stays exported. The new Normal shutdown leaves night pins exported. |
gpio_write() (the sysfs path, kernels older than 4.8) exports the pin, writes the value, then unexports it. On kernels where freeing the line makes the pin controller turn it back into an input (seen on Ambarella S3L, Linux 3.10), the level is lost right after the write: IR LEDs switch off immediately and IR-cut pulses don't hold, while /api/night still reports irled: true.
This leaves the pin exported after a write, and only exports it when its sysfs node isn't there yet, so later writes don't log "Unable to export".
Tested on an Amcrest IP4M-1026E (S3L, OV4689): with night mode on, GPIO 5 stays out hi in /sys/kernel/debug/gpio and the IR LEDs stay lit. Without the change they dropped to input right after "on". Not run on other platforms; gpio_read() still unexports.
The same text is saved in logs/pr-gpio-keep-exported.md.