diff options
author | Dmitry Fleytman <dfleytma@redhat.com> | 2015-11-24 10:26:57 +0200 |
---|---|---|
committer | Dmitry Fleytman <dfleytma@redhat.com> | 2015-11-24 12:32:35 +0200 |
commit | 2cac450d17dc7b33f4ed39a753e5630fd62209d6 (patch) | |
tree | cd001bfad8a0b4ef06242c2207cb32775df1ebae | |
parent | 5a7034b0e8a4ff31782034aea3714f611bf883ce (diff) |
UsbDk: Drop uneeded dynamic memory allocations
-rw-r--r-- | UsbDk/ControlDevice.cpp | 9 | ||||
-rw-r--r-- | UsbDk/ControlDevice.h | 8 | ||||
-rw-r--r-- | UsbDk/DeviceAccess.h | 4 | ||||
-rw-r--r-- | UsbDk/HiderDevice.cpp | 9 | ||||
-rw-r--r-- | UsbDk/HiderDevice.h | 8 | ||||
-rw-r--r-- | UsbDk/RedirectorStrategy.cpp | 26 | ||||
-rw-r--r-- | UsbDk/RedirectorStrategy.h | 16 | ||||
-rw-r--r-- | UsbDk/WdfDevice.cpp | 16 | ||||
-rw-r--r-- | UsbDk/WdfDevice.h | 28 |
9 files changed, 37 insertions, 87 deletions
diff --git a/UsbDk/ControlDevice.cpp b/UsbDk/ControlDevice.cpp index 710b80c..2e3061a 100644 --- a/UsbDk/ControlDevice.cpp +++ b/UsbDk/ControlDevice.cpp @@ -450,14 +450,7 @@ NTSTATUS CUsbDkControlDevice::Register() return status; } - m_DeviceQueue = new CUsbDkControlDeviceQueue(*this, WdfIoQueueDispatchSequential); - if (m_DeviceQueue == nullptr) - { - TraceEvents(TRACE_LEVEL_ERROR, TRACE_CONTROLDEVICE, "%!FUNC! Device queue allocation failed"); - return STATUS_INSUFFICIENT_RESOURCES; - } - - status = m_DeviceQueue->Create(); + status = m_DeviceQueue.Create(*this); if (NT_SUCCESS(status)) { FinishInitializing(); diff --git a/UsbDk/ControlDevice.h b/UsbDk/ControlDevice.h index 23bdb4e..8898543 100644 --- a/UsbDk/ControlDevice.h +++ b/UsbDk/ControlDevice.h @@ -58,11 +58,11 @@ public: } }; -class CUsbDkControlDeviceQueue : public CWdfDefaultQueue, public CAllocatable<PagedPool, 'QCHR'> +class CUsbDkControlDeviceQueue : public CWdfDefaultQueue { public: - CUsbDkControlDeviceQueue(CWdfDevice &Device, WDF_IO_QUEUE_DISPATCH_TYPE DispatchType) - : CWdfDefaultQueue(Device, DispatchType) + CUsbDkControlDeviceQueue(WDF_IO_QUEUE_DISPATCH_TYPE DispatchType) + : CWdfDefaultQueue(DispatchType) {} private: @@ -299,7 +299,7 @@ public: private: NTSTATUS ReloadPersistentHideRules(); - CObjHolder<CUsbDkControlDeviceQueue> m_DeviceQueue; + CUsbDkControlDeviceQueue m_DeviceQueue{WdfIoQueueDispatchSequential}; static CRefCountingHolder<CUsbDkControlDevice> *m_UsbDkControlDevice; CObjHolder<CUsbDkHiderDevice, CWdfDeviceDeleter<CUsbDkHiderDevice> > m_HiderDevice; diff --git a/UsbDk/DeviceAccess.h b/UsbDk/DeviceAccess.h index 800c3a3..7918a2f 100644 --- a/UsbDk/DeviceAccess.h +++ b/UsbDk/DeviceAccess.h @@ -29,14 +29,14 @@ #include "Public.h" -class CWdmDeviceAccess : public CAllocatable<PagedPool, 'ADHR'> +class CWdmDeviceAccess { public: CWdmDeviceAccess(PDEVICE_OBJECT WdmDevice) : m_DevObj(WdmDevice) { ObReferenceObjectWithTag(m_DevObj, 'DMHR'); } - virtual ~CWdmDeviceAccess() + ~CWdmDeviceAccess() { ObDereferenceObjectWithTag(m_DevObj, 'DMHR'); } CWdmDeviceAccess(const CWdmDeviceAccess&) = delete; diff --git a/UsbDk/HiderDevice.cpp b/UsbDk/HiderDevice.cpp index 0fa013f..16594a1 100644 --- a/UsbDk/HiderDevice.cpp +++ b/UsbDk/HiderDevice.cpp @@ -190,14 +190,7 @@ NTSTATUS CUsbDkHiderDevice::Register() return status; } - m_DeviceQueue = new CUsbDkHiderDeviceQueue(*this, WdfIoQueueDispatchSequential); - if (m_DeviceQueue == nullptr) - { - TraceEvents(TRACE_LEVEL_ERROR, TRACE_HIDERDEVICE, "%!FUNC! Device queue allocation failed"); - return STATUS_INSUFFICIENT_RESOURCES; - } - - status = m_DeviceQueue->Create(); + status = m_DeviceQueue.Create(*this); if (NT_SUCCESS(status)) { FinishInitializing(); diff --git a/UsbDk/HiderDevice.h b/UsbDk/HiderDevice.h index 9ad13e8..23b2c5a 100644 --- a/UsbDk/HiderDevice.h +++ b/UsbDk/HiderDevice.h @@ -28,11 +28,11 @@ class CWdfRequest; -class CUsbDkHiderDeviceQueue : public CWdfDefaultQueue, public CAllocatable<PagedPool, 'QHHR'> +class CUsbDkHiderDeviceQueue : public CWdfDefaultQueue { public: - CUsbDkHiderDeviceQueue(CWdfDevice &Device, WDF_IO_QUEUE_DISPATCH_TYPE DispatchType) - : CWdfDefaultQueue(Device, DispatchType) + CUsbDkHiderDeviceQueue(WDF_IO_QUEUE_DISPATCH_TYPE DispatchType) + : CWdfDefaultQueue(DispatchType) {} private: @@ -60,7 +60,7 @@ public: private: static void ContextCleanup(_In_ WDFOBJECT DeviceObject); - CObjHolder<CUsbDkHiderDeviceQueue> m_DeviceQueue; + CUsbDkHiderDeviceQueue m_DeviceQueue{WdfIoQueueDispatchSequential}; WDFDRIVER m_Driver = nullptr; friend class CUsbDkHiderDeviceInit; diff --git a/UsbDk/RedirectorStrategy.cpp b/UsbDk/RedirectorStrategy.cpp index 02284be..b19f42f 100644 --- a/UsbDk/RedirectorStrategy.cpp +++ b/UsbDk/RedirectorStrategy.cpp @@ -57,27 +57,13 @@ NTSTATUS CUsbDkRedirectorStrategy::Create(CUsbDkFilterDevice *Owner) return status; } - m_IncomingDataQueue = new CUsbDkRedirectorQueueData(*m_Owner); - if (!m_IncomingDataQueue) - { - TraceEvents(TRACE_LEVEL_ERROR, TRACE_REDIRECTOR, "%!FUNC! RW Queue allocation failed"); - return STATUS_INSUFFICIENT_RESOURCES; - } - - status = m_IncomingDataQueue->Create(); + status = m_IncomingDataQueue.Create(*m_Owner); if (!NT_SUCCESS(status)) { TraceEvents(TRACE_LEVEL_ERROR, TRACE_REDIRECTOR, "%!FUNC! RW Queue creation failed"); } - m_IncomingConfigQueue = new CUsbDkRedirectorQueueConfig(*m_Owner); - if (!m_IncomingConfigQueue) - { - TraceEvents(TRACE_LEVEL_ERROR, TRACE_REDIRECTOR, "%!FUNC! IOCTL Queue allocation failed"); - return STATUS_INSUFFICIENT_RESOURCES; - } - - status = m_IncomingConfigQueue->Create(); + status = m_IncomingConfigQueue.Create(*m_Owner); if (!NT_SUCCESS(status)) { TraceEvents(TRACE_LEVEL_ERROR, TRACE_REDIRECTOR, "%!FUNC! IOCTL Queue creation failed"); @@ -447,7 +433,7 @@ void CUsbDkRedirectorStrategy::IoDeviceControl(WDFREQUEST Request, { default: { - CWdfRequest(Request).ForwardToIoQueue(*m_IncomingConfigQueue); + CWdfRequest(Request).ForwardToIoQueue(m_IncomingConfigQueue); break; } case IOCTL_USBDK_DEVICE_READ_PIPE: @@ -493,14 +479,12 @@ void CUsbDkRedirectorStrategy::IoDeviceControlConfig(WDFREQUEST Request, } case IOCTL_USBDK_DEVICE_SET_ALTSETTING: { - ASSERT(m_IncomingDataQueue); - - m_IncomingDataQueue->StopSync(); + m_IncomingDataQueue.StopSync(); CWdfRequest WdfRequest(Request); UsbDkHandleRequestWithInput<USBDK_ALTSETTINGS_IDXS>(WdfRequest, [this, Request](USBDK_ALTSETTINGS_IDXS *altSetting, size_t) {return m_Target.SetInterfaceAltSetting(altSetting->InterfaceIdx, altSetting->AltSettingIdx);}); - m_IncomingDataQueue->Start(); + m_IncomingDataQueue.Start(); return; } case IOCTL_USBDK_DEVICE_RESET_DEVICE: diff --git a/UsbDk/RedirectorStrategy.h b/UsbDk/RedirectorStrategy.h index d3e3ca5..cb2d526 100644 --- a/UsbDk/RedirectorStrategy.h +++ b/UsbDk/RedirectorStrategy.h @@ -30,11 +30,11 @@ class CRegText; -class CUsbDkRedirectorQueueData : public CWdfDefaultQueue, public CAllocatable<PagedPool, 'PQRH'> +class CUsbDkRedirectorQueueData : public CWdfDefaultQueue { public: - CUsbDkRedirectorQueueData(CWdfDevice &Device) - : CWdfDefaultQueue(Device, WdfIoQueueDispatchParallel) + CUsbDkRedirectorQueueData() + : CWdfDefaultQueue(WdfIoQueueDispatchParallel) {} private: @@ -43,11 +43,11 @@ private: CUsbDkRedirectorQueueData& operator= (const CUsbDkRedirectorQueueData&) = delete; }; -class CUsbDkRedirectorQueueConfig : public CWdfSpecificQueue, public CAllocatable<PagedPool, 'SQRH'> +class CUsbDkRedirectorQueueConfig : public CWdfSpecificQueue { public: - CUsbDkRedirectorQueueConfig(CWdfDevice &Device) - : CWdfSpecificQueue(Device, WdfIoQueueDispatchSequential) + CUsbDkRedirectorQueueConfig() + : CWdfSpecificQueue(WdfIoQueueDispatchSequential) {} private: @@ -109,8 +109,8 @@ private: CWdfUsbTarget m_Target; - CObjHolder<CUsbDkRedirectorQueueData> m_IncomingDataQueue; - CObjHolder<CUsbDkRedirectorQueueConfig> m_IncomingConfigQueue; + CUsbDkRedirectorQueueData m_IncomingDataQueue; + CUsbDkRedirectorQueueConfig m_IncomingConfigQueue; CObjHolder<CRegText> m_DeviceID; CObjHolder<CRegText> m_InstanceID; diff --git a/UsbDk/WdfDevice.cpp b/UsbDk/WdfDevice.cpp index 2a0d82f..b9df79f 100644 --- a/UsbDk/WdfDevice.cpp +++ b/UsbDk/WdfDevice.cpp @@ -128,7 +128,7 @@ NTSTATUS CWdfDevice::Create(CPreAllocatedDeviceInit &DeviceInit, WDF_OBJECT_ATTR return status; } -NTSTATUS CWdfQueue::Create() +NTSTATUS CWdfQueue::Create(CWdfDevice &Device) { WDF_IO_QUEUE_CONFIG QueueConfig; WDF_OBJECT_ATTRIBUTES Attributes; @@ -139,7 +139,7 @@ NTSTATUS CWdfQueue::Create() WDF_OBJECT_ATTRIBUTES_INIT(&Attributes); Attributes.ExecutionLevel = WdfExecutionLevelPassive; - auto status = m_OwnerDevice.AddQueue(QueueConfig, Attributes, m_Queue); + auto status = Device.AddQueue(QueueConfig, Attributes, m_Queue); if (!NT_SUCCESS(status)) { TraceEvents(TRACE_LEVEL_ERROR, TRACE_WDFDEVICE, "%!FUNC! failed %!STATUS!", status); } @@ -167,18 +167,6 @@ void CWdfSpecificQueue::InitConfig(WDF_IO_QUEUE_CONFIG &QueueConfig) WDF_IO_QUEUE_CONFIG_INIT(&QueueConfig, m_DispatchType); } -NTSTATUS CWdfSpecificQueue::Create() -{ - auto status = CWdfQueue::Create(); - if (!NT_SUCCESS(status)) - { - return status; - } - - status = SetDispatching(); - return status; -} - NTSTATUS CWdfDevice::CacheDeviceName() { WDFSTRING deviceName; diff --git a/UsbDk/WdfDevice.h b/UsbDk/WdfDevice.h index bdbb9cf..22cbca4 100644 --- a/UsbDk/WdfDevice.h +++ b/UsbDk/WdfDevice.h @@ -26,12 +26,12 @@ #include "Alloc.h" #include "UsbDkUtil.h" -class CPreAllocatedDeviceInit : public CAllocatable<PagedPool, 'IDHR'> +class CPreAllocatedDeviceInit { public: CPreAllocatedDeviceInit() {} - virtual ~CPreAllocatedDeviceInit() + ~CPreAllocatedDeviceInit() {} virtual void Attach(PWDFDEVICE_INIT DeviceInit); @@ -100,7 +100,7 @@ class CDeviceInit : public CPreAllocatedDeviceInit protected: CDeviceInit() {} - virtual ~CDeviceInit(); + ~CDeviceInit(); virtual void Attach(PWDFDEVICE_INIT DeviceInit) override; virtual PWDFDEVICE_INIT Detach() override; @@ -168,12 +168,11 @@ public: class CWdfQueue { public: - CWdfQueue(CWdfDevice &Device, WDF_IO_QUEUE_DISPATCH_TYPE DispatchType) - : m_OwnerDevice(Device) - , m_DispatchType(DispatchType) + CWdfQueue(WDF_IO_QUEUE_DISPATCH_TYPE DispatchType) + : m_DispatchType(DispatchType) {} - virtual NTSTATUS Create(); + virtual NTSTATUS Create(CWdfDevice &Device); void StopSync() {WdfIoQueueDrain(m_Queue, nullptr, nullptr); } void Start() @@ -187,7 +186,6 @@ protected: virtual void SetCallbacks(WDF_IO_QUEUE_CONFIG &QueueConfig) = 0; WDFQUEUE m_Queue; - CWdfDevice &m_OwnerDevice; WDF_IO_QUEUE_DISPATCH_TYPE m_DispatchType; CWdfQueue(const CWdfQueue&) = delete; @@ -197,8 +195,8 @@ protected: class CWdfDefaultQueue : public CWdfQueue { public: - CWdfDefaultQueue(CWdfDevice &Device, WDF_IO_QUEUE_DISPATCH_TYPE DispatchType) - : CWdfQueue(Device, DispatchType) + CWdfDefaultQueue(WDF_IO_QUEUE_DISPATCH_TYPE DispatchType) + : CWdfQueue(DispatchType) {} private: @@ -211,16 +209,10 @@ private: class CWdfSpecificQueue : public CWdfQueue { public: - CWdfSpecificQueue(CWdfDevice &Device, WDF_IO_QUEUE_DISPATCH_TYPE DispatchType) - : CWdfQueue(Device, DispatchType) + CWdfSpecificQueue(WDF_IO_QUEUE_DISPATCH_TYPE DispatchType) + : CWdfQueue(DispatchType) {} - virtual NTSTATUS Create() override; - -protected: - virtual NTSTATUS SetDispatching() - { return STATUS_SUCCESS; } - private: virtual void InitConfig(WDF_IO_QUEUE_CONFIG &QueueConfig) override; |