Skip to content
This repository was archived by the owner on Feb 20, 2026. It is now read-only.

fix: stability improvements and wlanSendCommand error handling#28

Open
akoscz wants to merge 4 commits intohmtheboy154:mainfrom
akoscz:stability-fixes-v2
Open

fix: stability improvements and wlanSendCommand error handling#28
akoscz wants to merge 4 commits intohmtheboy154:mainfrom
akoscz:stability-fixes-v2

Conversation

@akoscz
Copy link
Copy Markdown

@akoscz akoscz commented Feb 4, 2026

Summary

Two stability fixes for the mt7902 driver, improving error handling and fixing compiler warnings.

Depends on #23 (branched from fix-fortify-source-overflow).

Changes

1. fix: stability improvements and compiler warning fixes

  • Add missing NULL check after kalMemAlloc() in wlanQueryPdMcr() to prevent NULL pointer dereference under memory pressure
  • Use fallthrough macro instead of /* Fall through */ comment in p2pFuncValidateRxActionFrame() to fix -Wimplicit-fallthrough warning
  • Add block scope around variable declaration in kalProcessCfg80211RxPkt() to fix -Wc23-extensions warning on kernel 6.1+

2. fix: check wlanSendCommand return value before waiting for response

Three call sites (wlanQueryNicCapability, wlanQueryPdMcr, wlanQueryNicCapabilityV2) were ignoring the return value of wlanSendCommand(). If the send fails, the code proceeds to wait for a response that will never arrive, leading to a timeout or hang. Now checks the return value and bails out with proper resource cleanup on failure.

Automatically detect if the kernel was built with clang by checking
CONFIG_CC_IS_CLANG in the kernel's autoconf.h. This ensures the driver
is built with the same compiler toolchain as the kernel, which is
required for ABI compatibility.

Changes:
- Add compiler detection to Makefile and Makefile.x86
- Set CC=clang and LLVM=1 flags when clang kernel detected
- Apply compiler-specific warning suppressions
- Use LLVM_FLAGS variable to reduce duplication

Tested on CachyOS with clang-built 6.18.8-3-cachyos kernel.
…CE warning

Fixes hmtheboy154#21

The kernel's FORTIFY_SOURCE detected a buffer overflow when copying
SSIDs into the aucOptInfo field because it was declared as a 1-byte
array (old-style flexible array pattern) but used to store up to 32
bytes.

Changes:
- include/nic/mac.h: Change aucOptInfo[1] to aucOptInfo[] (C99 flexible
  array member)
- mgmt/ais_fsm.c: Change buffer size from +31 to +ELEM_MAX_LEN_SSID to
  maintain correct 32-byte SSID capacity after sizeof change

The dynamic allocation in wlan_oid.c (u4SetBufferLen + sizeof(*prSSIDIE))
now allocates exactly the right amount instead of 1 byte over.
- Use C99 flexible array member for SUB_ELEMENT.aucOptInfo to eliminate
  FORTIFY_SOURCE warnings about writes beyond field size
- Update buffer size in aisSendNeighborRequest() to use ELEM_MAX_LEN_SSID
  constant instead of hardcoded 31
- Add missing NULL check after kalMemAlloc() in wlanQueryPdMcr() to
  prevent NULL pointer dereference under memory pressure
- Use fallthrough macro instead of comment for switch case fallthrough
  to fix -Wimplicit-fallthrough warning
- Add block scope around variable declaration after case label to fix
  -Wc23-extensions warning in kalProcessCfg80211RxPkt()
Add error checking for wlanSendCommand() calls in:
- wlanQueryNicCapability()
- wlanQueryPdMcr()
- wlanQueryNicCapabilityV2()

Previously these functions called wlanSendCommand() without checking
if it succeeded, then waited for a response that would never come if
the command failed to send.

The check handles both WLAN_STATUS_SUCCESS and WLAN_STATUS_PENDING as
success cases, since wlanSendCommand() returns PENDING for query
commands that need a response. WLAN_STATUS_FAILURE and
WLAN_STATUS_RESOURCES are treated as errors.

On failure, resources are properly cleaned up (prCmdInfo and aucBuffer
where applicable) before returning.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant