This document has two parts. Part 1 abstracts four bug shapes found and fixed
in this repo (a Linux out-of-tree WiFi driver, rtl8852cu) into transferable
patterns — if you are an AI or a person auditing an unfamiliar codebase, that part
is written to be useful there too, not just here. Part 2 is a plain changelog of
everything else this collaboration committed that isn't a general pattern — included
for completeness, not because it generalizes.
If you only care about hunting for bugs elsewhere, read Part 1 and skip Part 2.
Three of the four are null-pointer-dereference or dead-guard shapes — a check that's supposed to prevent a bad state from being reached but doesn't, in practice; the fourth is about verifying bulk automated code transformations. All four share a common trait: they produce code that compiles cleanly and passes a casual review, and only fail at runtime under a specific condition that's easy to not think to test. That's what makes them worth documenting — a linter or a compiler will not catch any of them.
Shape: a pointer field inside a long-lived context struct is legitimately set to
NULL (or freed) by some "teardown" function — call it end(), abort(),
deinit(), reset(), stop(). Elsewhere, a different function dereferences that
same field without checking it — and that function is not called synchronously from
the same logical operation as the teardown, but is invoked asynchronously: from
a message handler, a timer callback, a completion callback, or anything dispatched
through a queue rather than a direct call stack.
The bug window: something gets queued or scheduled while the field is still valid. Before it is actually handled, the teardown function runs and nulls the field. The handler has no way to know this happened in between unless it explicitly re-checks — and in a codebase with its own hand-rolled dispatch engine (not a heavily-hardened third-party framework), that re-check is easy to forget in exactly one call site out of several.
Why it's worth grep-hunting rather than just code-reading: once you find one
instance, the same field almost always has more than one unguarded dereference
site, because one teardown function typically has several async consumers. In this
repo, finding the first instance (sctrl->scan_ch in phl/phl_cmd_scan.c) led
directly to finding two more unguarded sites for the same field in the same
file, and then, by repeating the exact same search on a structurally similar field
in a sibling file, six more sites in phl/phl_cmd_dispatch_engine.c.
phl/phl_cmd_scan.c — sctrl->scan_ch is nulled by _cmd_scan_end() and
_cmd_scan_req_deinit() during scan abort/teardown. MSG_EVT_LISTEN_STATE_EXPIRE
and MSG_EVT_SWCH_DONE are handled asynchronously via phl_disp_eng_send_msg() — a
message queued before teardown can still be dispatched after scan_ch went NULL.
The file's own author had already documented this hazard in one place but not propagated the guard everywhere:
/* For the first time, param->scan_ch would be NULL */
/* Current channel scan_mode */
if (sctrl->scan_ch && sctrl->scan_ch->scan_mode == BACKOP_MODE) {
tx_pause = false;
}...while a sibling function, reached via the async path, dereferenced the same field unguarded:
// before
scan_ch->pass_t = phl_get_passing_time_ms(scan_ch->start_t);// after
if (!scan_ch) {
PHL_ERR("%s :: scan_ch is NULL !\n", __func__);
return false;
}
scan_ch->pass_t = phl_get_passing_time_ms(scan_ch->start_t);Two more sites in the same file, same field, same fix shape:
// MSG_EVT_LISTEN_STATE_EXPIRE handler, passive branch
- if (phl_cmd_chk_ext_act_scan(param, sctrl_idx)) {
+ if (sctrl->scan_ch && phl_cmd_chk_ext_act_scan(param, sctrl_idx)) {// MSG_EVT_SWCH_DONE handler
- PHL_INFO("\tMSG_EVT_SWCH_DONE :: duration=%d\n", sctrl->scan_ch->duration);
+ if (sctrl->scan_ch)
+ PHL_INFO("\tMSG_EVT_SWCH_DONE :: duration=%d\n", sctrl->scan_ch->duration);Same shape, different object, in phl/phl_cmd_dispatch_engine.c. Per-slot pointers
in an array are nulled one at a time during teardown, and 4 functions in the file
already guarded it:
if (disp_eng->dispatcher[i] == NULL)
continue;...but 6 others didn't, including the lookup function used by nearly every public API in the file:
// before
(*dispr) = disp_eng->dispatcher[band_idx];
return RTW_PHL_STATUS_SUCCESS;// after
if (disp_eng->dispatcher[band_idx] == NULL)
return RTW_PHL_STATUS_FAILURE;
(*dispr) = disp_eng->dispatcher[band_idx];
return RTW_PHL_STATUS_SUCCESS;The fix in every case mirrors a guard idiom the same file already used somewhere else for the same field — no new style invented, just propagated.
Same shape again, a different subsystem. core/rtw_phl.c's rtw_hw_iface_deinit()
sets adapter->phl_role = NULL during interface teardown. phl/phl_chan.c funnels
almost every channel/bandwidth operation through this same field (passed down as
wifi_role or wrole), and it dereferenced it — via wifi_role->phl_com->... — with
no check at all:
// rtw_phl_cmd_set_ch_bw() — before
struct phl_info_t *phl_info = wifi_role->phl_com->phl_priv;
void *drv = wifi_role->phl_com->drv_priv;This one is confirmed live, not theoretical: it crashed on real hardware via the
legacy Wireless-Extensions ioctl path (SIOCSIWFREQ → rtw_wx_set_freq() →
set_bch_bwmode() → rtw_hw_set_ch_bw(), which passes a->phl_role straight through
as wifi_role), with a full kernel Oops naming this exact function and offset
(RIP: rtw_phl_cmd_set_ch_bw+0x2d/0x1d0 [8852cu]) and killing the calling process.
This pattern's own advice — "once you find one instance, the same field almost always
has more than one unguarded dereference site" — held again. Grepping the same
wifi_role->phl_com/wrole->phl_com shape in the same file turned up three more:
rtw_phl_cmd_chg_op_chdef()— identical shape, currently zero callers anywhere in the tree. Not a live bug today (nothing can reach it with a badwrole, because nothing reaches it at all), but guarded anyway for consistency, matching worked example 2's "propagate the same idiom" precedent above — cheap, and ready if a caller is added later.rtw_phl_get_cur_ch()— one real caller,proc_get_chan()incore/rtw_debug.c(a/proc/net/rtl8852cu/<if>/chanread handler). Unguarded internally.rtw_phl_get_cur_hal_chdef()— one real caller,rtw_get_oper_chdef(). This one turned out to be a false positive at the call site (see "Avoiding false positives" below) — the caller already checks!adapter->phl_rolebefore calling in. Guarded internally anyway, since the function is a general PHL-layer API that could gain other callers later, and the fix is free.
A fifth site turned up in a different file, by following this pattern's other piece of
advice — check sibling call sites, not just the function you started from.
proc_get_chan() itself, the caller of rtw_phl_get_cur_ch() above, dereferences
padapter->phl_role->rlink_num directly, one line before it ever calls the
(now-also-guarded) getter — so guarding the getter alone would not have closed this
one; the real fix has to be at this call site too:
// core/rtw_debug.c, proc_get_chan() — before
for (lidx = 0; lidx < padapter->phl_role->rlink_num; lidx++) {// after
if (!padapter->phl_role)
return 0;
for (lidx = 0; lidx < padapter->phl_role->rlink_num; lidx++) {A boundary worth naming explicitly, since it's not what this pattern's original framing calls out: the "asynchronous" risk category isn't only the driver's own internal message/dispatch queue. A raw ioctl syscall and a procfs read handler are also invoked with no ordering guarantee relative to whatever else the driver is doing internally — userspace can call either at literally any moment, including exactly the window where a teardown function has just nulled the field. Same shape, same fix, different (and easy to overlook) trigger mechanism.
os_dep/linux/ioctl_cfg80211.c's key-management callbacks (cfg80211_rtw_del_key(),
cfg80211_rtw_add_key(), cfg80211_rtw_set_default_key()) all open the same way:
_adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
struct security_priv *psecuritypriv = &padapter->securitypriv;— no check that rtw_netdev_priv(ndev) (a driver-specific double-indirection macro,
not the plain kernel netdev_priv()) actually returned a live adapter before
dereferencing it. Confirmed live via two byte-identical kernel Oopses, two hours apart
(journalctl -k, both showing CR2: 00000000000029d8 and
RIP: cfg80211_rtw_del_key+0x35/0x120 [8852cu]), both during a real disconnect from a
live AP — the fault address itself is the tell: 0x29d8 is exactly
offsetof into the adapter struct that a NULL base plus this function's field access
would produce, not a bare 0x0, which is what pinned this down to "the adapter
pointer is NULL" rather than some other field.
What makes the teardown side worth calling out on its own here: it isn't the driver's
own dispatch engine this time. rtw_disconnect() calls the cfg80211-core API
cfg80211_disconnected(), which is documented to defer its real work to a workqueue
rather than running inline — precisely so drivers can call it from restrictive
contexts. rtw_disconnect() then keeps running and finishes its own teardown. Some
time later — on a kworker thread, via cfg80211_event_work →
__cfg80211_disconnected() — cfg80211 core calls back into this driver's del_key op
as part of its own generic key-cleanup, by which point something rtw_disconnect()
already tore down is gone. Same race shape as this pattern's other examples, but the
async boundary is a framework callback whose timing the driver doesn't control at all,
not even indirectly through its own queue.
Two boots, two hours apart, byte-identical fault — reproducible, not a fluke. Found
without reproducing it live: the crash was still sitting in journalctl's persistent,
cross-boot log (journalctl --list-boots, then journalctl -b <N> -k), which is worth
remembering before assuming a "lost" crash needs a fresh repro to chase.
Fixed all three call sites with the same guard idiom already used in worked examples
1–3 (if (!padapter) { log; return; }), and checked the fourth sibling in the same
file, cfg80211_rtw_set_default_mgmt_key() — it doesn't touch padapter at all, so it
was already safe.
Shape: a lookup/accessor function has always been able to return NULL on a
miss (e.g. "no interface matches this address," "no entry found for this key") — and
some caller has always failed to check for it. This was never a live bug, because
the code path that hits the miss case was never actually exercised: it was gated
behind a feature flag, an #ifdef, or a mode that was off, uncompiled, or unused in
practice. The bug activates the moment that gate opens — a new feature is enabled, a
config flag flips, a previously-decorative code path starts actually running — and
the NULL-return case that was always theoretically possible becomes real.
Why this one is easy to miss in review: the diff that introduces the bug is often just the feature-flag flip itself, or an unrelated small addition — the actually- broken code was written and merged long before, and passed review because "it compiles and the tests didn't hit that path." A reviewer of the flag-flipping commit has no reason to suspect a function three call-levels away that they didn't touch.
In this repo, CONFIG_WIFI_MONITOR was newly enabled. That turned on a code path
where a received frame doesn't match any known interface (rtw_get_iface_by_macddr()
returns NULL for sniffed monitor-mode frames — there's no "owning" interface for a
frame you're just observing), which had never been exercised while monitor mode was
compiled out. Two functions dereferenced the resulting NULL adapter_link without a
check:
// core/rtw_wlan_util.c — after
void rtw_get_oper_chdef(...)
{
if (!adapter->phl_role || !adapter_link)
return;
...
}// core/monitor/rtw_radiotap.c — after
if (padapter_link) {
/* fields that depend on padapter_link only accessed inside this guard */
}How to hunt for this pattern specifically: when a repo's history shows a feature
flag, #ifdef, or config option being newly turned on (check recent commits/PRs for
exactly this), treat every function reachable only from that newly-live path as
suspect, even if the function itself wasn't touched in the enabling commit.
Specifically check every value returned by a lookup/accessor function called from
that path for a NULL-check at each call site — lookup functions that "shouldn't
normally fail" are exactly the ones nobody checks.
Shape: applies whenever a mechanical, automated rewrite touches many files at
once — a codemod, a search-and-replace script, an LLM-driven bulk edit, a linter
autofix, a macro-expansion or preprocessor-conditional simplification. The rewrite
tool's own self-check is usually "does the output still parse / compile / pass a
structural validator (balanced braces, balanced #if/#endif)." That check proves
the output is valid, never that it's behaviorally equivalent to the input — and
for anything whose meaning depends on more than surface syntax (preprocessor
conditionals, macro expansion, generated code, operator precedence assumptions), a
tool can produce perfectly valid, silently wrong output.
A script collapsed dead LINUX_VERSION_CODE/config-version preprocessor branches
across ~56 files (~868 sites) once this project's minimum supported kernel moved
past various historical version checks (e.g. code that only ever ran on kernels
older than the new floor gets deleted, and the wrapping #if collapses).
First attempt shipped after passing structural validation (balanced directive
nesting) and looking correct on manual spot-checks — and compiled with 0 errors.
It broke the driver on real hardware: the USB device still enumerated (lsusb saw
it), but no wlan* interface ever appeared, dmesg was empty, and the DKMS build
itself reported no errors. A completely silent failure — not a crash, not a
build diagnostic, just wrong behavior that satisfied the compiler fine. Reverted
once the regression was found.
Root cause, found on the second attempt: the script's expression parser only
understood relational operators (>=, <, etc.) as part of a special-cased
LINUX_VERSION_CODE ... KERNEL_VERSION(...) text pattern. Any other bare
relational comparison ANDed alongside one — e.g.
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0)) && (CONFIG_IFACE_NUMBER >= 2) —
had its second clause's tokens silently dropped by the generic tokenizer, collapsing
the whole thing to #if CONFIG_IFACE_NUMBER (a truthy/existence check) instead of
#if CONFIG_IFACE_NUMBER >= 2. With a single-interface build, that flipped a
wiphy capability field from correctly-unset to incorrectly-set — almost certainly
why cfg80211 refused to register the interface. Valid C. Wrong semantics. No
compiler diagnostic is possible for this class of bug, by construction.
The fix that mattered wasn't the parser patch — it was the verification method
added on the second attempt: a directives-only preprocessor-equivalence diff.
For every compiled .c file, run the real compiler's preprocessor with the actual
build's flags (gcc <real -D/-I set, extracted from a make V=1 build> -E -fdirectives-only -P) on both the original and the rewritten source, then diff the
two output trees (diff -rq -w, ignoring whitespace so a merely-reformatted-but-
equivalent removal doesn't show up as noise). A genuine semantic difference shows up
as a real content diff. This pinpointed the exact 2 broken lines out of 410 compiled
files and 3500+ changed lines of diff — a level of confidence manual review did not
reach on the first attempt, and could not have reached, since the bug produced
syntactically perfect, individually-plausible-looking code at every site.
Generalizable lesson: "compiles clean" and "passes a structural validator" are not proof a bulk automated text transformation preserved behavior, for any transform where meaning depends on more than syntax validity. If a transform's own test is "does it still compile" or "is nesting balanced," that test cannot catch a transform that produces different-but-valid output — you need to diff against something that reflects actual resolved behavior (preprocessed output, an AST, a semantic model — whatever the language's real meaning layer is), not the transformed source text itself. This generalizes well beyond C preprocessor directives: the same failure mode applies to any large LLM-driven or scripted find-and-replace pass over a codebase.
Shape: an expensive or noisy code path has a runtime early-exit guard in front of
it — if (some_mode_flag == EXPECTED_VALUE) { skip / return / goto cheap_path; } —
that looks like real protection on a read of the function. But the only code that
would ever set some_mode_flag to EXPECTED_VALUE sits behind a compile-time flag
that is never actually defined in the real build (its own #define site is itself
gated behind a different condition — another flag, a platform check, an
"only for standalone compile-checking" branch — that never evaluates true for any real
target). The guard is syntactically present, semantically dead: some_mode_flag can
never take the value the guard checks for, so the branch it protects runs
unconditionally, every time, forever — not just in the rare case the guard's author
was trying to special-case.
Why this is easy to miss in review: the guard reads as correct and the code
compiles clean — no dangling reference, no type error, nothing a compiler or linter
flags. Confirming it's dead requires tracing the setter, not the checker: find every
place the flag gets assigned the value the guard is looking for, then check whether
that code is itself reachable given the actual Makefile/build-config #defines —
not just whether it exists somewhere in the source tree. Grepping for the guard itself
tells you nothing; you have to grep for what feeds it.
phl/phl_rx.c's per-packet receive-reorder function has an early exit clearly meant
to skip its expensive station-lookup/reorder logic entirely while the radio is in
monitor/sniffer mode (where "no station found" is the normal case for every foreign
frame overheard, not an error):
if (phl_info->phl_com->drv_mode == RTW_DRV_MODE_SNIFFER) {
goto dont_reorder;
}The only place that sets drv_mode = RTW_DRV_MODE_SNIFFER is inside
rtw_phl_enter_mon_mode(), itself wrapped in #ifdef CONFIG_PHL_SNIFFER_SUPPORT. That
flag has exactly two possible #define sites in phl/phl_config.h: one gated behind
PHL_FEATURE_NONE (only true for a phl-only standalone compile check — a real Linux
build defines PHL_PLATFORM_LINUX, which takes the other branch, PHL_FEATURE_NIC),
and one gated behind CONFIG_SNIFFER_SUPPORT (a different, driver-level flag that is
never defined anywhere — not in the Makefile, not in any header). For every real
build of this driver, CONFIG_PHL_SNIFFER_SUPPORT is undefined, drv_mode can never
become RTW_DRV_MODE_SNIFFER, and the guard above never fires — meaning every single
received frame in monitor mode, which is virtually all of them (that's the point of
monitor mode), falls through to a station lookup that's guaranteed to fail, hitting
an unconditional, unrate-limited printk().
Confirmed by two independent pieces of hardware evidence: a live capture in this
session showing the log volume drop from "one line per packet" to a handful once
rate-limited, and — independently, from a different investigation of the same driver —
a captured journalctl burst showing this exact line 144,782 times in about two
seconds, immediately preceding a hard hang that needed a physical reset. Not a crash
with a backtrace — a self-inflicted printk storm, real enough to take the whole
machine down with it.
The fix wasn't re-wiring the dead flag — too large a change to make confidently without knowing why it was disabled in the first place (see "Avoiding false positives" below for why that caution matters generally). Instead: rate-limit the two log calls this guard was supposed to make unreachable, directly, with a static per-call counter sampling 1-in-2000 rather than every occurrence. Smaller blast radius, fixes the actual symptom (resource exhaustion from log volume) regardless of whether the dead guard is ever revived, and doesn't guess at unwinding a compile-time flag whose disablement might have been deliberate — an incomplete or known-buggy feature, not just an oversight. Nothing in the source says which, and that ambiguity is exactly why the larger fix wasn't attempted.
How to hunt for this pattern specifically: for every runtime guard that checks a mode/state flag against one specific value, find every assignment to that flag across the tree, then check each assigning site's own compile-time reachability against the actual build configuration — not just whether the assignment exists in a file that gets compiled. A guard whose trigger condition can never occur is worse than no guard at all: it looks like the noisy/expensive case is handled, so nobody thinks to check it until the volume itself becomes the incident.
A dereference that looks unguarded is not automatically a bug. The most common way to be wrong: a correlated guard exists somewhere else in the same code path — some other field or condition that is always true/false in exact lockstep with the "nullable" pointer, so checking it is equivalent to checking the pointer, even though the pointer itself is never directly tested at that call site.
Three real examples from auditing this repo, all initially flagged as candidates, all correctly ruled out on closer reading. A fourth example closes the loop from the other direction — a candidate that was genuinely dead, and what it actually took to confirm that with confidence:
-
ch_idxas an accidental NULL-guard forscan_ch. Two ACS functions dereferencedscan_ch->acs_idxwith no visible check onscan_ch. But the call site already checkedsctrl->ch_idx < 0— andch_idxis initialized to-1and only ever advances in the exact same function, at the exact same point, wherescan_chis first assigned non-NULL. Tracing both fields' init/update sites confirmed they change in lockstep. Not a bug. -
A power-save mode flag as a guard for
ps->sta._cfg_bcn_tracking()dereferencedps->sta->bcn_i.cfgwith no direct check, but is only reachable whenps->ps_mode == PS_MODE_LPS, and every code path that sets that mode does so only after a call that also setsps->staas a side effect of succeeding. Tracing every assignment site of both the mode and the pointer confirmed the correlation. Not a bug. -
A thread-join as an implicit lifetime guard. A background-module struct is captured by pointer when a message is sent, and freed later during teardown — a classic-looking use-after-free shape. But every real teardown call site was preceded by a call that fully stops and joins the dispatcher thread(s) first, so no thread remains alive to process a stale message by the time the free happens. Confirmed by tracing the actual call sites, not by assuming the shape implies the bug. Not a bug.
-
The flip side: clearing the bar to actually remove an extern-linkage symbol.
rtw_phl_dump_mdl()(phl/phl_cmd_dispatch_engine.c) was non-static, declared as public API in two headers, and had zero callers anywhere in the tree — genuinely dead, not a false positive, but a much higher bar to confirm than astaticsymbol confined to one file. Confirming it took more than a repo grep: checking it wasn't in the module'sEXPORT_SYMBOLlist (ruling out use from outside this module entirely), checking there was no sibling chip-variant source tree in the checkout that could hold an out-of-sight caller, checking for no macro-concatenated or table-driven reference under any spelling of the name, and — after removal — confirming vianmon the rebuilt object and the final.kothat the symbol was actually gone, not just absent from a grep. Extern-linkage removal deserves this whole bar; astatic-in-one-file symbol doesn't need most of it, because the language itself already rules out the risks the bar exists to catch.
The rule: before fixing (or even reporting) a candidate, trace whether an
early return, an enclosing if, or a correlated flag/index/refcount elsewhere in the
same code path already rules out the null/freed case. If you can't confirm
reachability with confidence, say so explicitly and don't guess — a wrong "fix" that
adds a needless check is low-cost, but a wrong "fix" that papers over a different
real bug by making a crash silently do nothing is worse than not touching it.
- Identify long-lived context/state structs — ones whose pointers are read across more than one function call, not just locals within a single call stack.
- For each pointer-typed field, grep for explicit nulling or freeing
(
= NULL,free(...),kfree(...), language-appropriate equivalents). Each hit is evidence the field is designed to become invalid at some point in normal operation — that's not the bug, that's the setup for finding one. - Grep every dereference of that same field across the file (and check whether the struct/field is used in sibling files too).
- For each dereference site with no visible guard, classify it: is it reached synchronously, in the same logical operation that established the field's validity (usually safe by construction), or reached via an async boundary — message handler, timer callback, completion callback, deferred/queued work (the risk category)?
- Before concluding a site is a real bug, actively look for a correlated guard (see above) that already rules out the null case through a different field or flag. Don't stop at "I don't see a direct check on this exact pointer" — trace the actual reachability.
- When you confirm one genuine instance, don't stop — grep every other dereference of the same field in the file, then check whether structurally similar fields in sibling files (same subsystem, same "teardown nulls it, async handler reads it" shape) have the same gap. One confirmed instance is a strong prior that more exist nearby.
- Fix with the smallest possible guard, matching whatever idiom the codebase already uses elsewhere for the same or a similar field. Don't introduce a new style, don't refactor beyond the guard itself, don't add unrelated validation.
- If the codebase is large enough that reading every file inline isn't practical, splitting the sweep across parallel review passes (each covering a distinct subset of files, each given the same pattern description and the same false-positive discipline above) scales this well — that's exactly how the 6-sibling-file sweep in this repo was done, and it correctly returned "no bug here" for most of them rather than forcing false-positive fixes to justify the effort.
- Separately from all of the above: whenever a change is a bulk mechanical rewrite rather than a hand-written fix (Pattern C), don't trust "it compiles" as sufficient. Diff against the actual resolved/semantic output, not the source text, before shipping it.
Repo-specific, not general patterns — included for completeness, not because it generalizes to other codebases.
-
20955bd— Add opt-inrtw_6g_apmodule param for 6GHz LPI AP mode. Ported an upstream community PR that adds a module parameter bypassing this driver's blanket "forbid 6GHz AP mode" restriction, which exists because full regulatory enforcement (AFC — Automatic Frequency Coordination) isn't implemented. 6GHz AP operation without AFC is legally permitted as Low Power Indoor (LPI) operation in some jurisdictions. The param makes enabling it a conscious, documented opt-in (MODULE_PARM_DESCspells out the legal caveat) rather than leaving the capability silently unreachable. A feature addition, not a bug fix. -
f5b21ae— Add performance improvement plan and VM handoff notes. Two docs, no code: a staged plan for a scan-latency/CPU-overhead investigation (gated on measuring a real baseline before changing anything), and a context-snapshot doc for continuing that work from a second machine, since Claude Code sessions don't sync across machines and repo files are the only thing that reliably transfers. -
Merge-conflict resolution (
c994a1f, mergingmaininto the kernel-cleanup branch). Not a bug, a real 3-way conflict: one branch had stripped a dead#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0)wrapper (as part of the Pattern C cleanup above), while the other had added thertw_6g_apgating condition inside that same wrapper. Both changes were valid and non-overlapping in intent; the resolution kept both (dropped the dead wrapper, kept the gating condition). Notable only as a reminder that auto-merge silently reverting a hunk to the merge-base version (rather than leaving conflict markers) can happen — worth double-checking the three actual git stages (git show :1:/:2:/:3:path) directly rather than trusting a combined diff's hunk count at face value. -
ebab27f— Investigate wifite channel-set hot path; document dead ends and a found bug. Follow-up to thef5b21aeperformance plan above: traced the actual code path behind monitor-mode channel hopping to test that plan's Phase 2 theory, that async command-dispatch/queue overhead was worth optimizing. It wasn't reachable at all. Neither driver-side command mechanism considered —phl_cmd_dispatch_engine.c's async dispatcher, norcore/rtw_cmd.c's separate H2C command queue — is ever hit by wifite's hopping, confirmed twice over: first by gated timing instrumentation (DBG_CHANSET_TIMING, off by default) that produced zero output on a real run, then bystraceshowingairodump-ngactually issuesNL80211_CMD_SET_WIPHY, notNL80211_CMD_SET_CHANNELas the original static trace had assumed. That command maps tocfg80211_rtw_set_wiphy_params(), which turned out to be an unimplemented stub — a dead#if 0body copy-pasted from an unrelated Intel driver, referencing types and macros that don't exist in this codebase, leaving only an unconditionalreturn 0that silently does nothing while reporting success. A real bug, found as a side effect of chasing a performance question, not fixed here — worth its own look separately. The exact kernel-to-driver dispatch past the netlink layer remains unresolved; would need kernel source or kprobe/ftrace tracing to go further. Also flaggedrtw_phl_dump_mdl()(zero callers anywhere in the tree) dead with a TODO rather than deleting it on the spot — later actually removed once verified more rigorously, see thef854cdaentry below — and consolidatedPERFORMANCE_PLAN.md/VM_HANDOFF.mdwith a current-status summary reflecting the full investigation. Not a Part 1 pattern by itself — the theory that motivated the trace turned out to be wrong, twice, and the stub bug was found, not fixed — but a worked example of the same discipline Part 1 argues for: falsify with real evidence (instrumentation, thenstrace) instead of trusting a static call-graph read, and don't stop investigating just because the first mechanism checked turns out not to be it. -
9326957— Record Phase 0 baseline, gate always-on scan-cycle debug logging. Closes the loop on the performance plan's Phase 1: measured baseline scan-cycle timing (~5.0s for a 39-channel sweep) and CPU usage (47.5%/74.4% avg/peak) on real hardware, then foundDBG_SCAN_CHAN_DUMPwasn't the only always-on logging culprit — four morePHL_INFO()calls in the same scan message handlers had no#ifdefat all and printed by default (phl_log_leveldefaults to a level that lets barePHL_INFO()through). Gated all five behind the same flag rather than a half-fix. Verified via admesgdiff of an identical channel span before/after: line count for that span dropped from 150 to 112, matching four call sites going from firing every channel to zero. Also did the scoped re-check this playbook's own recipe recommends (step 8) — sweptphl_cmd_dispatch_engine.c/phl_cmd_dispatcher.cfor the same always-on-logging shape, found none; that whole path already logs through a component flag that's off by default, unlikephl_cmd_scan.c's bare calls.One catch worth its own callout, generalizable well past this repo: gating one of the five required commenting out the single-statement body of a braceless
if (sctrl->scan_ch), which was immediately followed by an unconditionalbreak. Without adding braces first,#ifdef-ing out just thePHL_INFO(...)line would have leftbreak;as the only remaining statement — and since C binds an unbracedif's body to whichever single statement follows,breakitself would have silently become theif's body, turning a guaranteed break into one that only fires whenscan_chhappens to be set. Caught before it shipped, not after — but it's the same family of bug as the infamous SSLgoto fail;incident: whenever a conditional-compilation edit removes or comments out code inside a bracelessif/else/for/while, check what statement the compiler will bind the block to after the edit, not before. Adding explicit braces is the fix and costs nothing. -
df56f62— Move performance-investigation docs intodocs/. Pure reorganization, no content change: relocatedPERFORMANCE_PLAN.mdandVM_HANDOFF.mdnext to this file, fixing the cross-references that move broke. -
f854cda— Remove deadrtw_phl_dump_mdl()and its orphaned helpers. The TODO from theebab27fentry above, resolved: actually deleted, along with_get_evt_str()/_get_mdl_str(), the twostatichelpers that existed only to feed its debug print. See item 4 of "Avoiding false positives" above for the specific verification bar cleared before removing an extern-linkage symbol like this one — a plain repo grep alone isn't enough for this category, unlike thestatic-scoped cases this playbook mostly deals with. -
bfc0c51— Implementcfg80211_rtw_set_wiphy_params()for real. The dead-stub bug first surfaced in theebab27fentry above, now actually fixed: replaced the#if 0'd-out copy-paste with a real implementation forWIPHY_PARAM_FRAG_THRESHOLD/WIPHY_PARAM_RTS_THRESHOLD, matching this driver's own existing WEXT handlers exactly (same bounds, same fields, already live elsewhere in the TX path — not fabricated logic). Frag threshold verified end-to-end on hardware. RTS threshold's driver-side code is correct but couldn't be verified the same way — traced viastracedown to the raw netlink response and found this specific kernel (7.1.8-arch1) never persists the value regardless of what's set, apparently a kernel-core issue tied to a recent multi-radio wiphy rework, not a driver bug. Out of scope to chase further here, but worth knowing if this ever looks broken again on this box: check the kernel side before assuming the driver regressed. -
6d03105— Fix monitor-mode crashes and RX log flood. Three defects found investigating reports of wpa_supplicant hangs and a system freeze during monitor-mode/Bully/wifite usage: an unthrottled per-packet log flood inphl_rx_reorder()(Pattern D), a NULL-deref in the channel/bandwidth command path reachable via the legacy WEXT ioctl (rtw_phl_cmd_set_ch_bw()and three sibling functions, Pattern A worked example 3), and a NULL-deref in the cfg80211 key-management callbacks reachable via cfg80211's own deferred disconnect-cleanup workqueue (Pattern A worked example 4) — the last one confirmed via a real, byte-identical-twice kernel Oops recovered fromjournalctl's persistent cross-boot log rather than a fresh live repro. See Part 1 above for the full technical write-up of each.