giles123
giles123

Reputation: 361

WDK7: Using IoAttachDeviceToDeviceStack gives "Memory must be held" warning in PREfast

I am using PREFast to check some driver code build for Windows7. The following line of code

stackDeviceObject = IoAttachDeviceToDeviceStack(deviceObject, PhysicalDeviceObject);

Gives the warning:

warning 28107: The Memory 'deviceObject' must be held when calling 'IoAttachDeviceToDeviceStack'.

deviceObject is obtained with an earlier call to IoCreateDevice. Does anyone know what this warning means and how to get rid of it?

The PREfast help says "A resource that the program must acquire before calling the function was not acquired when the function was called. As a result, the function call will fail."

The example that the help page provides surrounds a pair of calls to ExAcquireResourceLite and ExReleaseResourceLite (which gives this warning) between calls to KaEnterCriticalRegion and KaLeaveCriticalRegion, which then supposedly gets rid of the warning, but I don't know how to apply this info to my call to IoAttachDeviceToDeviceStack.

Any advice would be appreciated.

Upvotes: 0

Views: 366

Answers (1)

giles123
giles123

Reputation: 361

I believe I have an answer to my own question. The call to IoCreateDevice was in a separate function which was called from this one. I think this was stopping PREfast from seeing that this function was being called and deviceObject was being correctly initialised before the call to IoAttachDeviceToDeviceStack was called.

I have moved the IoCreateDevice call into the same function as IoAttachDeviceToDeviceStack and the warning went away.

Thanks to anyone that spent time reading this and trying to find an answer.

Upvotes: 0

Related Questions