[ofw] [PATCH] winverbs/winmad: check return value of DeviceIoControl
Hefty, Sean
sean.hefty at intel.com
Tue Sep 14 16:47:00 PDT 2010
We need to check the return value from DeviceIoControl before
calling GetOverlappedResult to avoid potential hangs.
Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
trunk/core/winmad/user/wm_provider.cpp | 13 ++++++++-----
trunk/core/winverbs/user/wv_base.cpp | 13 +++++++------
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/trunk/core/winmad/user/wm_provider.cpp b/trunk/core/winmad/user/wm_provider.cpp
index 7b026ea..064b098 100644
--- a/trunk/core/winmad/user/wm_provider.cpp
+++ b/trunk/core/winmad/user/wm_provider.cpp
@@ -134,11 +134,14 @@ WmDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,
if (lpOverlapped == NULL) {
EnterCriticalSection(&m_CritSecWrite);
- DeviceIoControl(hDevice, dwIoControlCode,
- lpInBuffer, nInBufferSize,
- lpOutBuffer, nOutBufferSize,
- lpBytesReturned, &m_OverlapWrite);
- ret = ::GetOverlappedResult(m_hFile, &m_OverlapWrite, lpBytesReturned, TRUE);
+ ret = DeviceIoControl(hDevice, dwIoControlCode,
+ lpInBuffer, nInBufferSize,
+ lpOutBuffer, nOutBufferSize,
+ lpBytesReturned, &m_OverlapWrite);
+ if (!ret && GetLastError() == ERROR_IO_PENDING) {
+ ret = ::GetOverlappedResult(m_hFile, &m_OverlapWrite,
+ lpBytesReturned, TRUE);
+ }
LeaveCriticalSection(&m_CritSecWrite);
} else {
ret = DeviceIoControl(hDevice, dwIoControlCode,
diff --git a/trunk/core/winverbs/user/wv_base.cpp b/trunk/core/winverbs/user/wv_base.cpp
index 5ed4e9f..e231ec3 100644
--- a/trunk/core/winverbs/user/wv_base.cpp
+++ b/trunk/core/winverbs/user/wv_base.cpp
@@ -89,12 +89,13 @@ WvDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,
if (lpOverlapped == NULL) {
EnterCriticalSection(&m_CritSec);
- DeviceIoControl(hDevice, dwIoControlCode,
- lpInBuffer, nInBufferSize,
- lpOutBuffer, nOutBufferSize,
- lpBytesReturned, &m_Overlap);
-
- ret = GetOverlappedResult(hDevice, &m_Overlap, lpBytesReturned, TRUE);
+ ret = DeviceIoControl(hDevice, dwIoControlCode,
+ lpInBuffer, nInBufferSize,
+ lpOutBuffer, nOutBufferSize,
+ lpBytesReturned, &m_Overlap);
+ if (!ret && GetLastError() == ERROR_IO_PENDING) {
+ ret = GetOverlappedResult(hDevice, &m_Overlap, lpBytesReturned, TRUE);
+ }
LeaveCriticalSection(&m_CritSec);
} else {
ret = DeviceIoControl(hDevice, dwIoControlCode,
More information about the ofw
mailing list