Skip to content

fix(hidraw): check ioctl errno in featureReport (HIDIOCSFEATURE failures were silently swallowed)#381

Merged
BANANASJIM merged 1 commit into
mainfrom
fix/hidraw-featurereport-errno
Jun 7, 2026
Merged

fix(hidraw): check ioctl errno in featureReport (HIDIOCSFEATURE failures were silently swallowed)#381
BANANASJIM merged 1 commit into
mainfrom
fix/hidraw-featurereport-errno

Conversation

@BANANASJIM

Copy link
Copy Markdown
Owner

What

HidrawDevice.featureReport guarded the HIDIOCSFEATURE ioctl with if (rc < 0). linux.ioctl returns usize (unsigned), so the guard was always false — every feature-report failure (ENODEV/EPIPE on unplug, EINVAL, EBADF, ...) returned OK.

The device-init handshake (src/init.zig) calls featureReport and relies on the returned error to abort init; it never saw the failure.

Fix

  • Interpret the raw syscall return with linux.E.init(rc) and branch on errno != .SUCCESS.
  • Map ENODEV/EPIPEWriteError.Disconnected, all others → WriteError.Io.
  • posix.errno is unsuitable here: under libc linkage it reads the C errno global, which a raw linux.ioctl syscall never sets, so it reported SUCCESS for a -EBADF return (this is also why the naive port of the guard still passed silently).

Test plan

  • Added Layer-0 regression hidraw: featureReport surfaces ioctl errno as error: featureReport over fd=-1 (EBADF) must return WriteError.Io.
  • Falsifiable: against the old if (rc < 0) code (libc-linked, as CI builds), the test fails with expected error.Io, found void.
  • ./scripts/padctl-docker test → EXIT=0 (1635 tests pass).
  • zig fmt --check src/io/hidraw.zig clean.

refs: audit HIGH

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@BANANASJIM, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 3 minutes and 13 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fec7cef7-9761-4f79-ab4b-bf7e6e7ee4e0

📥 Commits

Reviewing files that changed from the base of the PR and between 8e1c4d6 and 5a6ff05.

📒 Files selected for processing (1)
  • src/io/hidraw.zig
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/hidraw-featurereport-errno

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…res were silently swallowed)

- linux.ioctl returns usize, so the `if (rc < 0)` guard was always false;
  every HIDIOCSFEATURE failure (ENODEV/EPIPE on unplug, EINVAL, EBADF, ...)
  returned OK and the device-init handshake in init.zig never saw the error.
- Interpret the raw syscall return with linux.E.init(rc) and branch on
  errno != .SUCCESS, mapping ENODEV/EPIPE to Disconnected and the rest to Io.
- posix.errno is unsuitable here: under libc linkage it reads the C errno
  global, which a raw linux.ioctl syscall never sets, so it reported SUCCESS
  for a -EBADF return.

Test plan:
- Added Layer-0 regression "hidraw: featureReport surfaces ioctl errno as
  error": featureReport over fd=-1 (EBADF) must return WriteError.Io.
  Falsifiable: against the old `if (rc < 0)` code (libc-linked) it fails with
  "expected error.Io, found void".
- `./scripts/padctl-docker test` → EXIT=0 (1635 tests).
- `zig fmt --check src/io/hidraw.zig` clean.

refs: audit HIGH
@BANANASJIM BANANASJIM force-pushed the fix/hidraw-featurereport-errno branch from d1158b2 to 5a6ff05 Compare June 7, 2026 04:30
@BANANASJIM BANANASJIM merged commit a05fd5b into main Jun 7, 2026
41 of 42 checks passed
@BANANASJIM BANANASJIM deleted the fix/hidraw-featurereport-errno branch June 7, 2026 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant