[ofw] [PATCH] winmad: check return value of Read/WriteFile

Hefty, Sean sean.hefty at intel.com
Thu Sep 2 13:00:18 PDT 2010


When performing synchronous operation, we need to check the return value
of ReadFile/WriteFile before calling GetOverlappedResult.  Otherwise
GetOverlappedResult can hang.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---

Index: trunk/core/winmad/user/wm_provider.cpp
===================================================================
--- trunk/core/winmad/user/wm_provider.cpp	(revision 2893)
+++ trunk/core/winmad/user/wm_provider.cpp	(working copy)
@@ -187,8 +187,11 @@
 	bytes = (DWORD) sizeof(WM_MAD) + pMad->Length;
 	if (pOverlapped == NULL) {
 		EnterCriticalSection(&m_CritSecWrite);
-		WriteFile(m_hFile, pMad, bytes, &bytes, &m_OverlapWrite);
-		hr = GetOverlappedResult(&m_OverlapWrite, &bytes, TRUE);
+		if (WriteFile(m_hFile, pMad, bytes, &bytes, &m_OverlapWrite)) {
+			hr = GetOverlappedResult(&m_OverlapWrite, &bytes, TRUE);
+		} else {
+			hr = HRESULT_FROM_WIN32(GetLastError());
+		}
 		LeaveCriticalSection(&m_CritSecWrite);
 	} else {
 		if (WriteFile(m_hFile, pMad, bytes, &bytes, pOverlapped)) {
@@ -209,8 +212,11 @@
 
 	if (pOverlapped == NULL) {
 		EnterCriticalSection(&m_CritSecRead);
-		ReadFile(m_hFile, pMad, (DWORD) BufferSize, &bytes, &m_OverlapRead);
-		hr = GetOverlappedResult(&m_OverlapRead, &bytes, TRUE);
+		if (ReadFile(m_hFile, pMad, (DWORD) BufferSize, &bytes, &m_OverlapRead)) {
+			hr = GetOverlappedResult(&m_OverlapRead, &bytes, TRUE);
+		} else {
+			hr = HRESULT_FROM_WIN32(GetLastError());
+		}
 		LeaveCriticalSection(&m_CritSecRead);
 	} else {
 		if (ReadFile(m_hFile, pMad, (DWORD) BufferSize, &bytes, pOverlapped)) {

-------------- next part --------------
A non-text attachment was scrubbed...
Name: wm.patch
Type: application/octet-stream
Size: 1382 bytes
Desc: wm.patch
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20100902/bb569c79/attachment.obj>


More information about the ofw mailing list