Skip to content

Commit

Permalink
UsbDk: Simplify and refactor filter attachment code
Browse files Browse the repository at this point in the history
This is a refactoring commit, no functional changes introduced.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
  • Loading branch information
Dmitry Fleytman committed Jun 29, 2016
1 parent 0b7487b commit f014083
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
27 changes: 12 additions & 15 deletions UsbDk/FilterDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,19 +412,19 @@ void CUsbDkHubFilterStrategy::ApplyRedirectionPolicy(CUsbDkChildDevice &Device)
if (m_ControlDevice->ShouldRedirect(Device) ||
m_ControlDevice->ShouldHide(Device.DeviceDescriptor()))
{
if (Device.MakeRedirected())
if (Device.AttachToDeviceStack())
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Adding new PDO 0x%p as redirected initially", Device.PDO());
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Attached to device stack for 0x%p", Device.PDO());
}
else
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_FILTERDEVICE, "%!FUNC! Failed to create redirector PDO for 0x%p", Device.PDO());
TraceEvents(TRACE_LEVEL_ERROR, TRACE_FILTERDEVICE, "%!FUNC! Failed to attach to device stack for 0x%p", Device.PDO());
}
}
else
{
m_ControlDevice->NotifyRedirectionRemoved(Device);
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Adding new PDO 0x%p as non-redirected initially", Device.PDO());
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Not attaching to device stack for 0x%p", Device.PDO());
}
}

Expand All @@ -433,21 +433,18 @@ ULONG CUsbDkChildDevice::ParentID() const
return m_ParentDevice.GetInstanceNumber();
}

bool CUsbDkChildDevice::MakeRedirected()
bool CUsbDkChildDevice::AttachToDeviceStack()
{
m_Redirected = CreateRedirectorDevice();
if (!m_Redirected)
auto DriverObj = m_ParentDevice.GetDriverObject();

auto Status = DriverObj->DriverExtension->AddDevice(DriverObj, m_PDO);
if (!NT_SUCCESS(Status))
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_FILTERDEVICE, "%!FUNC! Failed to create redirector for child");
TraceEvents(TRACE_LEVEL_ERROR, TRACE_FILTERDEVICE, "%!FUNC! Failed to attach to device stack");
return false;
}

return m_Redirected;
}

bool CUsbDkChildDevice::CreateRedirectorDevice()
{
auto DriverObj = m_ParentDevice.GetDriverObject();
return NT_SUCCESS(DriverObj->DriverExtension->AddDevice(DriverObj, m_PDO));
return true;
}

NTSTATUS CUsbDkFilterDevice::AttachToStack(WDFDRIVER Driver)
Expand Down
7 changes: 1 addition & 6 deletions UsbDk/FilterDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class CUsbDkChildDevice : public CAllocatable<NonPagedPool, 'DCHR'>
{ return m_Speed; }
const USB_DEVICE_DESCRIPTOR &DeviceDescriptor() const
{ return m_DevDescriptor; }
bool IsRedirected() const
{ return m_Redirected; }
PDEVICE_OBJECT PDO() const { return m_PDO; }

bool ConfigurationDescriptor(UCHAR Index, USB_CONFIGURATION_DESCRIPTOR &Buffer, size_t BufferLength)
Expand All @@ -96,7 +94,7 @@ class CUsbDkChildDevice : public CAllocatable<NonPagedPool, 'DCHR'>
bool Match(PDEVICE_OBJECT PDO) const
{ return m_PDO == PDO; }

bool MakeRedirected();
bool AttachToDeviceStack();

void Dump();

Expand All @@ -109,9 +107,6 @@ class CUsbDkChildDevice : public CAllocatable<NonPagedPool, 'DCHR'>
TDescriptorsCache m_CfgDescriptors;
PDEVICE_OBJECT m_PDO;
const CUsbDkFilterDevice &m_ParentDevice;
bool m_Redirected = false;

bool CreateRedirectorDevice();

CUsbDkChildDevice(const CUsbDkChildDevice&) = delete;
CUsbDkChildDevice& operator= (const CUsbDkChildDevice&) = delete;
Expand Down

0 comments on commit f014083

Please sign in to comment.