Repository navigation
Added DEVPKEY_DsHidMini_RO_IpcSlotIndex for IPC - #433
Conversation
📝 WalkthroughWalkthroughAdded a persistent, exported device property Changes
Sequence DiagramsequenceDiagram
participant Driver as Kernel Driver
participant PnP as PnP System
participant SDK as SDK (DsHidMiniInterop)
participant DevEnum as Device Enumeration
Driver->>Driver: DsDevice_InitContext: Claim slot
Driver->>PnP: Publish IpcSlotIndexProperty with assigned SlotIndex
SDK->>DevEnum: RefreshDevices(): Enumerate PnPDevices
DevEnum-->>SDK: Return list of devices
loop For each discovered device
SDK->>PnP: Read IpcSlotIndexProperty
alt Property exists and valid
PnP-->>SDK: Return one-based slot index
SDK->>SDK: Store device using slot index (keyed by slot)
else Property missing/invalid
SDK->>SDK: Assign to lowest available fallback slot (starting at 1)
end
end
SDK->>SDK: _connectedDevices populated by actual slot indices
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@driver/Device.c`:
- Around line 483-497: The call to WdfDeviceAssignProperty currently ignores its
return value; change Device.c to capture the NTSTATUS from
WdfDeviceAssignProperty (when assigning DEVPKEY_DsHidMini_RO_IpcSlotIndex with
pDevCtx->SlotIndex), check for failure, and handle it: log the error (include
the NTSTATUS and context) via the driver's logging mechanism and, if IPC is
enabled, propagate the failure out of the initialization path (return a failure
NTSTATUS or abort device init) instead of discarding it so the new property
write does not silently degrade to the old heuristic.
In `@SDK/Nefarius.DsHidMini.IPC/DsHidMiniInterop.cs`:
- Around line 266-269: The Single(...) call that looks up the device in
_connectedDevices is a no-op and can throw if the device isn't present or Equals
doesn't match; remove that lookup or replace it with a non-throwing check (e.g.,
use _connectedDevices.Any(kvp => kvp.Value.Equals(device)) or
_connectedDevices.TryGetValue/ContainsKey pattern) so the removal path does not
throw and allows RefreshDevices() to run; update the code around the device
variable and _connectedDevices to perform a safe diagnostic check or omit it
entirely.
- Around line 195-225: The second pass incorrectly assigns fallback slots to
devices that *did* return an explicit IpcSlotIndexProperty but collided, causing
wrong remapping; change the second foreach to only assign a fallback when
TryGetIpcSlotIndex(device) indicates no valid explicit slot (null/invalid), and
skip any device that returned a non-null int (even if that int was already
used). Use TryGetIpcSlotIndex to re-check each device and only run the fallback
allocation logic for devices where the property is missing/invalid; leave
devices that returned an explicit slot untouched so _connectedDevices and
usedKeys remain consistent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bdbcfb5f-f859-42bf-a53e-8535e33bacef
📒 Files selected for processing (6)
DSHMC/Drivers/DsHidMiniDriver.csSDK/Nefarius.DsHidMini.IPC/DsHidMiniInterop.csSDK/Nefarius.DsHidMini.IPC/Models/Drivers/DsHidMiniDriver.csSDK/Nefarius.DsHidMini.IPC/README.mddriver/Device.cinclude/DsHidMini/dshmguid.h
There was a problem hiding this comment.
🧹 Nitpick comments (1)
SDK/Nefarius.DsHidMini.IPC/DsHidMiniInterop.cs (1)
244-267: Implementation is correct; consider narrowing the exception filter for better diagnostics.The helper correctly handles missing/invalid properties and validates the one-based slot range. The broad
catch (Exception)is intentional for driver compatibility, but you may want to catch more specific exceptions (e.g.,Win32Exception,InvalidCastException) and log unexpected ones to aid debugging when issues arise.💡 Optional: narrower exception handling
try { slot = device.GetProperty<uint>(DsHidMiniDriver.IpcSlotIndexProperty); } - catch (Exception) + catch (Exception ex) when (ex is System.ComponentModel.Win32Exception or InvalidCastException) { // Older driver without the property, or property not yet available return null; } + catch (Exception ex) + { + // Unexpected error - log and treat as missing + System.Diagnostics.Debug.WriteLine($"Unexpected error reading IpcSlotIndexProperty: {ex}"); + return null; + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@SDK/Nefarius.DsHidMini.IPC/DsHidMiniInterop.cs` around lines 244 - 267, The TryGetIpcSlotIndex method currently uses a broad catch (Exception) around device.GetProperty<uint>(DsHidMiniDriver.IpcSlotIndexProperty); narrow this by catching expected exceptions such as InvalidCastException and Win32Exception (or whatever specific exceptions PnPDevice.GetProperty can throw) and return null for those, and add a separate catch for unexpected Exception where you log the exception via your logger before rethrowing or returning null as appropriate; locate TryGetIpcSlotIndex and the call to device.GetProperty<uint> to implement the two-tiered catches and logging.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@SDK/Nefarius.DsHidMini.IPC/DsHidMiniInterop.cs`:
- Around line 244-267: The TryGetIpcSlotIndex method currently uses a broad
catch (Exception) around
device.GetProperty<uint>(DsHidMiniDriver.IpcSlotIndexProperty); narrow this by
catching expected exceptions such as InvalidCastException and Win32Exception (or
whatever specific exceptions PnPDevice.GetProperty can throw) and return null
for those, and add a separate catch for unexpected Exception where you log the
exception via your logger before rethrowing or returning null as appropriate;
locate TryGetIpcSlotIndex and the call to device.GetProperty<uint> to implement
the two-tiered catches and logging.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ff2ff73f-ca3f-4dcd-8c46-6d1e68b6b5b4
📒 Files selected for processing (2)
SDK/Nefarius.DsHidMini.IPC/DsHidMiniInterop.csdriver/Device.c
Summary by CodeRabbit
New Features
Bug Fixes
Documentation