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

fix: reorder HIF init before WiFi wake-up to prevent NULL pointer crash#24

Open
akoscz wants to merge 2 commits intohmtheboy154:mainfrom
akoscz:fix-null-ptr-wlanwakeupwifi
Open

fix: reorder HIF init before WiFi wake-up to prevent NULL pointer crash#24
akoscz wants to merge 2 commits intohmtheboy154:mainfrom
akoscz:fix-null-ptr-wlanwakeupwifi

Conversation

@akoscz
Copy link
Copy Markdown

@akoscz akoscz commented Feb 3, 2026

Summary

  • Reorders initialization in wlanAdapterStart() so halHifSwInfoInit() is called before wlanWakeUpWiFi()
  • Prevents NULL pointer dereference when WiFi hardware is already ON at boot

Problem

When WiFi hardware is already powered on during driver probe (e.g., after unclean shutdown), wlanWakeUpWiFi() calls wlanPowerOffWifi() to reset the hardware. This sends commands through TX DMA rings, but halHifSwInfoInit() (which allocates these rings) wasn't called until after wlanWakeUpWiFi() returned.

Note: HAL_HIF_INIT inside wlanWakeUpWiFi() is a no-op for PCIE - the real allocation happens in halHifSwInfoInit().

Test plan

  • Build driver successfully
  • Boot system after unclean shutdown (WiFi hardware left ON)
  • Verify driver loads without NULL pointer crash
  • Verify WiFi connects normally

Fixes #22

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.
When WiFi hardware is already powered on during driver initialization
(e.g., after a system crash or when firmware persists across reboots),
wlanWakeUpWiFi() calls wlanPowerOffWifi() to cleanly reset the hardware.
However, wlanPowerOffWifi() sends commands through the TX DMA rings,
which are allocated in halHifSwInfoInit().

The original initialization order in wlanAdapterStart() was:
  1. wlanWakeUpWiFi() - may call wlanPowerOffWifi() if WiFi is ON
  2. halHifSwInfoInit() - allocates TX DMA rings

This caused a NULL pointer dereference in halWpdmaWriteCmd() when
accessing pTxCell->AllocVa on uninitialized TX rings.

Fix by reordering initialization so halHifSwInfoInit() is called before
wlanWakeUpWiFi(), ensuring TX DMA rings are always available before any
code attempts to send commands.

Fixes hmtheboy154#22
@wmealing
Copy link
Copy Markdown

wmealing commented Feb 3, 2026

I have seen this on my systems. Please continue your own testing. I hope to validate this shortly.

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.

NULL pointer dereference in halWpdmaWriteCmd when WiFi already ON at boot

2 participants