Skip to content

qdss: refactoring the code#66

Open
Chenxi Han (5656hcx) wants to merge 7 commits into
mainfrom
qdss-modernization
Open

qdss: refactoring the code#66
Chenxi Han (5656hcx) wants to merge 7 commits into
mainfrom
qdss-modernization

Conversation

@5656hcx

@5656hcx Chenxi Han (5656hcx) commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Commits

1. 49822d7 — qdss: add shared registry functions

Introduces a new module (QDBREG.c / QDBREG.h) centralising all driver software-key access. Six typed helpers are added: QDBREG_GetDriverRegistryStringW, QDBREG_SetDriverRegistryStringW, QDBREG_SetDriverRegistryStringA (converts PCHAR → Unicode via RtlAnsiStringToUnicodeString), QDBREG_SetDriverRegistryDword, QDBREG_GetDriverRegistryDword, and QDBREG_DeleteDriverRegistryValue. All write/delete operations open the registry key with KEY_SET_VALUE.

  • Add QDBREG.c (+239 lines) and QDBREG.h (+135 lines)
  • Register both files in qdbusb.vcxproj

Files changed: QDBREG.c, QDBREG.h, qdbusb.vcxproj — net +376 lines


2. 0e0367c — qdss: fix trace draining and remove hardcoded device-type dependency from INF

Fixes the pipe-drain for QDSS device type in QDBRD.c: QDBRD_PipeDrainStart, QDBRD_PipeDrainStop, QDBRD_SendIOBlock, QDBRD_AllocateRequestsRx, and QDBRD_FreeIoBuffer. qdbusb.inf is rewritten to remove hardcoded device-type assumptions, making the INF applicable across configurations without per-device editing.

Files changed: QDBPNP.c, QDBPNP.h, QDBRD.c, qdbusb.inf — net −29 lines


3. d7c0f62 — qdss: update port name, friendly name, and symbolic link creation

Rewrites QDBPNP_CreateSymbolicName to eliminate fixed-size stack buffers (~8 KB). Device properties are now queried with kmdf api WdfDeviceAllocAndQueryProperty, which allocates exactly the required bytes from non-paged pool and is freed immediately after use. DEVPKEY_Device_FriendlyName is updated via WdfDeviceAssignProperty using the WDF_DEVICE_PROPERTY_DATA API. portName is updated to use device instanceId rather than incremental counter.

Files changed: QDBPNP.c (+125/−97) — net +28 lines


4. 34d9bef — qdss: refactor pnp functions to use shared registry functions

Replaces open-coded WdfDeviceOpenRegistryKey / WdfRegistry* / WdfRegistryClose sequences in QDBPNP_GetCID, QDBPNP_GetDeviceSerialNumber, QDBPNP_GetParentDeviceName, and QDBPNP_SetStamp with the QDBREG_* helpers.

Files changed: QDBMAIN.h, QDBPNP.c, QDBPNP.h — net −90 lines


5. 84a0425 — qdss: refactor IOCTL handler functions

Refactors QDBDSP_IoDeviceControl to replace the legacy WDM-style QDBDSP_IrpIoCompletion handler (which accessed raw IRP fields directly) with a new QDBDSP_GetDPLStats helper that uses WdfRequestRetrieveOutputBuffer and WdfRequestCompleteWithInformation. Removes unused local variables and simplifies the IOCTL dispatch logic.

Files changed: QDBDSP.c (+63/−144), QDBDSP.h — net −81 lines


6. 6781390 — qdss: inline QDBWT_WriteUSB into QDBWT_IoWrite

QDBWT_WriteUSB had exactly one call site and re-fetched pDevContext and fileContext redundantly from Queue and Request, both of which are already resolved in the caller. The function body is inlined into QDBWT_IoWrite, eliminating two superfluous context lookups and simplifying the call graph. QDBWT_WriteUSB is removed from QDBWT.h. No functional change.

Files changed: QDBWT.c (+46/−121), QDBWT.h (−7) — net −75 lines


7. 04b2cff — qdss: remove unnecessary codes, update header includes

Large cleanup pass removing dead code no longer reachable after the preceding refactors:

  • Remove QDBMAIN_AllocateUnicodeString and QDBMAIN_GetRegistrySettings from QDBMAIN.c; drop their declarations from QDBMAIN.h
  • Remove QDBPNP_SetStamp and several other obsolete PNP helpers from QDBPNP.c; clean up QDBPNP.h
  • Remove QDBRD_PipeDrainCompletion from QDBRD.c
  • Prune unused fields from DEVICE_CONTEXT and FILE_CONTEXT in QDBMAIN.h
  • Consolidate stale #include directives across QDBDEV.c, QDBDSP.c, and QDBRD.h

Files changed: 11 files — net −646 lines

@hangzqcom hangzqcom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

The three-commit structure is clean and the core logic changes are correct: removing the duplicate EvtDeviceFileClose, eliminating the registry-based function-type detection, and inverting the drain guards so QDSS (not DPL) gets the background pipe drain. A few issues need attention before merge.

Blocking

PortName is never initialized (QDBPNP.c): sprintf(pDevContext->PortName, ...) was removed from EvtDriverDeviceAdd and nothing replaces it. PortName is used as the %s prefix in 50+ QDB_DbgPrint calls across the driver. With a zero-initialized context it will always print an empty string, making WPP traces unreadable. Either populate it from the symbolic link / device description string (as QDBPNP_CreateSymbolicName already builds), or use RtlStringCbPrintfA to copy a short identifier there.

Non-blocking

Stale comment in EvtDevicePrepareHW: the comment immediately before the QDBRD_AllocateRequestsRx / QDBRD_PipeDrainStart call block still reads // Start to drain IN pipe for DPL. After the drain-guard inversion it should read // Start to drain IN pipe for QDSS.

WPP_GLOBALLOGGER removed without explanation (QDBMAIN.c): removing this macro silently disables the WPP global-logger session, which is used for boot-time tracing. If this is intentional (e.g. the global logger is no longer needed), add a comment explaining why; otherwise restore it.

Missing break in default case (QDBPNP_SetFunctionProtocol): the default: block sets FunctionType and calls QDB_DbgPrint but has no break. It is the last case so there is no fall-through bug, but adding break is consistent with the other cases and avoids a future maintenance hazard.

@5656hcx Chenxi Han (5656hcx) changed the title qdss: remove dead code, correct type determination and drain dispatch for QDSS/DPL devices qdss: code modenrazation Jun 23, 2026
@5656hcx Chenxi Han (5656hcx) changed the title qdss: code modenrazation qdss: refactoring the code Jun 23, 2026
Signed-off-by: Chenxi Han <chehan@qti.qualcomm.com>
…from INF

Signed-off-by: Chenxi Han <chehan@qti.qualcomm.com>
Signed-off-by: Chenxi Han <chehan@qti.qualcomm.com>
Signed-off-by: Chenxi Han <chehan@qti.qualcomm.com>
Signed-off-by: Chenxi Han <chehan@qti.qualcomm.com>
Signed-off-by: Chenxi Han <chehan@qti.qualcomm.com>
@5656hcx

Copy link
Copy Markdown
Contributor Author

The PR is updated with new commit ids.

Signed-off-by: Chenxi Han <chehan@qti.qualcomm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants