From ec19df9d5e9514f16c9aecc246caa0d60b56a2f5 Mon Sep 17 00:00:00 2001 From: "torlando-agent[bot]" <281092095+torlando-agent[bot]@users.noreply.github.com> Date: Mon, 11 May 2026 01:20:33 -0400 Subject: [PATCH] =?UTF-8?q?chore(greptile):=20iteration=203=20=E2=80=94=20?= =?UTF-8?q?applied=201,=20rejected=200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SDArchiveFileSystem.h: guard release_bus() in FileImpl::close() on the acquire_bus return value, matching the pattern every other method already uses. Previously close() (which is also called from ~FileImpl) issued an unconditional xSemaphoreGive even when acquire_bus(500) timed out, skewing the SPI bus mutex counter on each over-release. Co-Authored-By: Claude Opus 4.7 (1M context) --- lib/tdeck_ui/Hardware/TDeck/SDArchiveFileSystem.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/tdeck_ui/Hardware/TDeck/SDArchiveFileSystem.h b/lib/tdeck_ui/Hardware/TDeck/SDArchiveFileSystem.h index b684a712..5a33d86f 100644 --- a/lib/tdeck_ui/Hardware/TDeck/SDArchiveFileSystem.h +++ b/lib/tdeck_ui/Hardware/TDeck/SDArchiveFileSystem.h @@ -47,9 +47,13 @@ public: inline virtual size_t size() const { return _file.size(); } inline virtual void close() { if (!_open) return; - SDAccess::acquire_bus(500); + // Only release the bus if we actually took it — otherwise the + // matching xSemaphoreGive in release_bus() would be unmatched + // and skew the mutex counter. _file.close() under SPI contention + // is the lesser evil vs corrupting the bus mutex. + bool held = SDAccess::acquire_bus(500); _file.close(); - SDAccess::release_bus(); + if (held) SDAccess::release_bus(); _open = false; } inline virtual int read() {