AddDevice getting called while Surpriseremoval is still getting processed

Hi team,

We have a USB Bus driver and a Function driver. During SurpriseRemoval, Function driver disable its interface, so that OS Services can close the Open Handle to the driver.

WDF calls the D0Exit and ReleaseHardware of Function driver, and the calls EvtDeviceFileClose. The delay in WDF callback EvtDeviceFileClose, doesnt allow the filter driver to unload. Meanwhile, even though the Bus driver is in Releasehardware.

Meanwhile OS calls a AddDevice to the BusDriver, which cant be handled as this stage as we have already started the cleanup, and we have to return a error for Adddevice.

Is there a way, we can ask Framework not to do a Addevice, until the driver unloads completely ? or can EvtDeviceFileClose on Function driver be called before ReleaseHardware callback on Function driver ?

I’m not sure I understand why this is a race condition for you.

Each device instance is separate, right? So, while one instance is being “cleaned up” (I’m not sure *exactly* what you mean by this, but…) another instance can *always* arrive, right?

Sorry… I guess I don’t understand the basic issue,

Peter
OSR
@OSRDrivers

Hi Peter,

the driver doesnt support Multi instance, as there are few globals and Hardware config params which needs to be cleaned before re-instanced.

xxxxx@gmail.com wrote:

We have a USB Bus driver and a Function driver. During SurpriseRemoval, Function driver disable its interface, so that OS Services can close the Open Handle to the driver.

So, you have a USB device.  The driver for that device creates a PDO,
for which you have another function driver, and you have an app opening
a handle to that driver.  Is that right?  So, in surprise removal, that
whole stack is going to get torn down.  Or have I misinterpreted?

WDF calls the D0Exit and ReleaseHardware of Function driver, and the calls EvtDeviceFileClose. The delay in WDF callback EvtDeviceFileClose, doesnt allow the filter driver to unload. Meanwhile, even though the Bus driver is in Releasehardware.

What filter driver?  What that a typo?

I’m not sure why this should be a problem.

 

Meanwhile OS calls a AddDevice to the BusDriver, which cant be handled as this stage as we have already started the cleanup, and we have to return a error for Adddevice.

This is a design flaw in your drivers.  The AddDevice in the bus driver
is trying to create a brand-new device instance for the newly reinserted
hardware, which should be totally independent of the old device
instance.  What kind of global state are you tracking that causes you to
return an error?  And why are you doing so?

Is there a way, we can ask Framework not to do a Addevice, until the driver unloads completely ? or can EvtDeviceFileClose on Function driver be called before ReleaseHardware callback on Function driver ?

The order shouldn’t matter.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

xxxxx@gmail.com wrote:

the driver doesnt support Multi instance, as there are few globals and Hardware config params which needs to be cleaned before re-instanced.

Then your driver is broken.  It’s just that simple.  There is NO excuse
for having a USB driver that does not support multi-instance.  Your
hardware config is not global, it is specific to a single device
instance.  When you get a new instance, then you have to reset the
hardware config, whether or not there is another device already configured.

You need to fix it.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

> your driver is broken

You need to fix it

This.

Peter
OSR
@OSRDrivers