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

Tzachi Dar tzachid at mellanox.co.il
Sat Sep 11 12:32:18 PDT 2010



> -----Original Message-----
> From: Tzachi Dar [mailto:tzachid at mellanox.co.il]
> Sent: Monday, September 06, 2010 3:01 PM
> To: Hefty, Sean
> Cc: ofw at lists.openfabrics.org
> Subject: RE: [PATCH] winmad: check return value of Read/WriteFile
> 
> I believe that there is also a similar issue with DeviceIoControl on
> the same file.
> 
> Thanks
> Tzachi
> 
> > -----Original Message-----
> > From: Hefty, Sean [mailto:sean.hefty at intel.com]
> > Sent: Thursday, September 02, 2010 11:00 PM
> > To: Hefty, Sean; Tzachi Dar
> > Cc: ofw at lists.openfabrics.org
> > Subject: [PATCH] winmad: check return value of Read/WriteFile
> >
> > 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)) {




More information about the ofw mailing list