Fishwaldo opened a new pull request, #19744:
URL: https://github.com/apache/nuttx/pull/19744

   ## Summary
   
   Two independent HID keyboard fixes.
   
   **`HIDKBD_NOGETREPORT` did not build on its own.** The option reads keyboard 
reports with `DRVR_ASYNCH()`, and that macro only exists when `USBHOST_ASYNCH` 
is set. It selected neither, so enabling it alone fails at the call site with 
nothing pointing at the missing second option:
   
   ```
   usbhost/usbhost_hidkbd.c:1199:17: error: implicit declaration of function 
'DRVR_ASYNCH'
   ```
   
   It now selects it.
   
   **A keyboard that fails to enumerate asserts.** `usbhost_destroy()` 
unregisters the keyboard unconditionally, and it also runs for a device that 
never got as far as being registered — an enumeration that failed part way 
through, or a device unplugged while it was still being set up. The upper half 
does not tolerate that:
   
   ```c
   /* drivers/input/keyboard_upper.c:382 */
   DEBUGASSERT(lower->priv != NULL);
   ```
   
   `keyboard_register()` sets `lower->priv` (line 356), so it is precisely the 
record of whether registration happened. The fix tests it before undoing 
anything.
   
   ## Impact
   
   - **User visible:** a keyboard that attaches but does not finish enumerating 
is cleaned up and forgotten, instead of asserting and resetting the board. 
Previously one flaky device could stop the system.
   - **Build:** `CONFIG_HIDKBD_NOGETREPORT=y` compiles by itself, where before 
it also required knowing to set `CONFIG_USBHOST_ASYNCH=y`.
   - **Configurations affected:** `CONFIG_USBHOST_HIDKBD` only. The guard adds 
one pointer test on a teardown path.
   - **Compatibility:** none. A configuration that already set both options is 
unchanged.
   - **Hardware, documentation, security:** unaffected.
   
   ## Testing
   
   **Host:** macOS 15.5 (Apple Silicon). **Board:** ESWIN EIC7700X (RISC-V, 4 
cores SMP), whose xHCI support will be upstreamed later.
   
   ### Build fix — reproducible in tree, no hardware
   
   ```
   tools/configure.sh -E qemu-intel64:jumbo
   kconfig-tweak --enable CONFIG_USBHOST_HIDKBD
   kconfig-tweak --enable CONFIG_HIDKBD_NOGETREPORT
   make olddefconfig && make
   ```
   
   **Before:** `CONFIG_USBHOST_ASYNCH` stays unset and the build fails with the 
`DRVR_ASYNCH` error above. **After:** the `select` pulls 
`CONFIG_USBHOST_ASYNCH=y` in and the same configuration builds clean.
   
   ### Teardown fix — on hardware
   
   This was found during development, not by inspection: an old low-speed USB 
keyboard on hand would intermittently attach and then fail to finish 
enumerating, and every time it did, the board asserted and reset. That 
intermittency is also why the log below uses an injected failure rather than 
the keyboard itself — waiting on a device that misbehaves only sometimes makes 
for evidence nobody can check.
   
   To make it deterministic I returned an error from `usbhost_devinit()` 
immediately before `keyboard_register()`, which is exactly the case that 
keyboard produced. Both runs are the same tree, board and injection; only 
`usbhost_hidkbd.c` differs.
   
   **Before (without this patch)** — the board reaches NSH, then asserts and is 
reset by the watchdog:
   
   ```
   dump_assert_info: Assertion failed lower->priv != ((void*)0):
     at file: input/keyboard_upper.c:382 task(CPU0): kbdpoll
   
   === [ 50.82s] NSH reached ===
   ##### CMD 1: uname -a
   ##### END 1 (REBOOTED (firmware banner seen mid-command), 12.41s)
   ```
   
   Note the task: the assertion fires in `kbdpoll`, not in the enumeration path.
   
   **After (with this patch)** — same injected failure, no assertion, system 
responsive:
   
   ```
   ##### CMD 1: uname -a
   NuttX  13.0.0 risc-v starpro64
   ##### END 1 (ok, 1.60s)
   ##### CMD 2: ls /dev
    sda  ttyACM0
   ```
   
   The keyboard is correctly absent — registration never happened — while the 
other USB devices on the same bus are unaffected. Without the injection, the 
same board enumerates that keyboard normally and `/dev/kbda` reports keys.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to