Skip to content

Commit 86d743c

Browse files
JohnAZoidbergclaude
andcommitted
EcCommunication: Fix DeviceIoControl return value handling
DeviceIoControl returns BOOL, not NTSTATUS. The previous code assigned the return value to an NTSTATUS variable and checked with NT_SUCCESS(), which worked by accident but was incorrect. Check the boolean return directly and use GetLastError() on failure for proper error reporting. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7f6664d commit 86d743c

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

FrameworkSensors/EcCommunication.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,10 @@ int CrosEcSendCommand(
6060
unsigned int inlen
6161
)
6262
{
63-
NTSTATUS Status = STATUS_SUCCESS;
6463
DWORD retb{};
6564
CROSEC_COMMAND cmd{};
6665

6766
if (Handle == INVALID_HANDLE_VALUE) {
68-
Status = STATUS_INVALID_HANDLE;
6967
TraceError("%!FUNC! Invalid Handle");
7068
return 0;
7169
}
@@ -91,16 +89,16 @@ int CrosEcSendCommand(
9189

9290
RtlCopyMemory(cmd.data, outdata, outlen);
9391

94-
Status = DeviceIoControl(Handle,
92+
if (!DeviceIoControl(Handle,
9593
(DWORD) IOCTL_CROSEC_XCMD,
9694
&cmd,
9795
sizeof(cmd),
9896
&cmd,
9997
sizeof(cmd),
10098
&retb,
101-
nullptr);
102-
if (!NT_SUCCESS(Status)) {
103-
TraceError("%!FUNC! ConnectToEc failed %!STATUS!", Status);
99+
nullptr)) {
100+
DWORD err = GetLastError();
101+
TraceError("%!FUNC! DeviceIoControl XCMD failed, error=%d", err);
104102
return 0;
105103
}
106104

@@ -123,28 +121,26 @@ int CrosEcSendCommand(
123121

124122
int CrosEcReadMemU8(HANDLE Handle, unsigned int offset, UINT8* dest)
125123
{
126-
NTSTATUS Status = STATUS_SUCCESS;
127124
DWORD retb{};
128125
CROSEC_READMEM rm{};
129126

130127
if (Handle == INVALID_HANDLE_VALUE) {
131-
Status = STATUS_INVALID_HANDLE;
132128
TraceError("%!FUNC! Invalid Handle");
133129
return 0;
134130
}
135131

136132
rm.bytes = 0x01;
137133
rm.offset = offset;
138-
Status = DeviceIoControl(Handle,
134+
if (!DeviceIoControl(Handle,
139135
(DWORD) IOCTL_CROSEC_RDMEM,
140136
&rm,
141137
sizeof(rm),
142138
&rm,
143139
sizeof(rm),
144140
&retb,
145-
nullptr);
146-
if (!NT_SUCCESS(Status)) {
147-
TraceError("%!FUNC! ConnectToEc failed %!STATUS!", Status);
141+
nullptr)) {
142+
DWORD err = GetLastError();
143+
TraceError("%!FUNC! DeviceIoControl RDMEM failed, error=%d", err);
148144
return 0;
149145
}
150146

0 commit comments

Comments
 (0)