- IOReturn res;
-
- if (!inAction)
- return kIOReturnBadArgument;
-
- // Try to close the gate if can't get return immediately.
- if (!tryCloseGate())
- return kIOReturnCannotLock;
-
- // If the command gate is disabled then sleep until we get a wakeup
- if (!workLoop->onThread() && !enabled)
- res = kIOReturnNotPermitted;
- else {
-
- bool trace = ( gIOKitTrace & kIOTraceCommandGates ) ? true : false;
-
- if (trace)
- IOTimeStampStartConstant(IODBG_CMDQ(IOCMDQ_ACTION),
- (uintptr_t) inAction, (uintptr_t) owner);
-
- IOStatisticsActionCall();
-
- res = (*inAction)(owner, arg0, arg1, arg2, arg3);
-
- if (trace)
- IOTimeStampEndConstant(IODBG_CMDQ(IOCMDQ_ACTION),
- (uintptr_t) inAction, (uintptr_t) owner);
- }
-
- openGate();
-
- return res;
+ IOReturn res;
+ IOWorkLoop * wl;
+
+ if (!inAction) {
+ return kIOReturnBadArgument;
+ }
+ if (!(wl = workLoop)) {
+ return kIOReturnNotReady;
+ }
+
+ // Try to close the gate if can't get return immediately.
+ if (!wl->tryCloseGate()) {
+ return kIOReturnCannotLock;
+ }
+
+ // If the command gate is disabled then sleep until we get a wakeup
+ if (!wl->onThread() && !enabled) {
+ res = kIOReturnNotPermitted;
+ } else {
+ bool trace = (gIOKitTrace & kIOTraceCommandGates) ? true : false;
+
+ if (trace) {
+ IOTimeStampStartConstant(IODBG_CMDQ(IOCMDQ_ACTION),
+ VM_KERNEL_ADDRHIDE(inAction), VM_KERNEL_ADDRHIDE(owner));
+ }
+
+ IOStatisticsActionCall();
+
+ res = (*inAction)(owner, arg0, arg1, arg2, arg3);
+
+ if (trace) {
+ IOTimeStampEndConstant(IODBG_CMDQ(IOCMDQ_ACTION),
+ VM_KERNEL_ADDRHIDE(inAction), VM_KERNEL_ADDRHIDE(owner));
+ }
+ }
+
+ wl->openGate();
+
+ return res;