Fwd: PnP Manager Firing Unintended IRP_MN_SURPRISE_REMOVAL IRP

---------- Forwarded message ----------
From: Abhishek Bhadraja
Date: Fri, Oct 17, 2014 at 1:36 PM
Subject: PnP Manager Firing Unintended IRP_MN_SURPRISE_REMOVAL IRP
To: xxxxx@lists.osr.com

Hi,

I have a scenario where USB device is connected to PC and communicating with it.

In this process application is keep on opening and closing the handle
to access a USB port and doing few cycle to read and write.

When the above process in going on in a loop, all of sudden I can see
PnP manager is firing a IRP_MN_SURPRISE_REMOVAL IRP though there is no
USB re-enumeration done manually and after that I can see PnP manager
is firing IRP_MN_START_DEVICE before IRP_MN_REMOVE_DEVICE and due to
this USB communication going down cause IRP_MN_REMOVE_DEVICE called
after add device and ideally I am expecting IRP_MN_REMOVE should occur
before IRP_MN_START_DEVICE.

Please share your input. Here are the some traces from my device driver.

00003774 853.22888184 Enter fnProcessPnPIrp()
00003775 853.22888184 Enter IRP_MN_SURPRISE_REMOVAL
00003776 853.22888184 Set event for No pending IO Event
00003777 853.22985840 Exit IRP_MN_SURPRISE_REMOVAL

00003778 853.46289063 Enter fnPnPAddDevice()
00003779 853.46325684 0 == ntStatus
00003780 853.46337891 Enter fnProcessPnPIrp()
00003781 853.46337891 Set event for No pending IO Event
00003782 853.46343994 Enter fnProcessPnPIrp()
00003783 853.46343994 Set event for No pending IO Event
00003784 853.46350098 Enter fnProcessPnPIrp()
00003785 853.46350098 Set event for No pending IO Event
00003786 853.46362305 Enter fnProcessPnPIrp()
00003787 853.46417236 Enter StartDevice()
00003788 853.46588135 Set event for No pending IO Event
00003789 853.46649170 Enter fnProcessPnPIrp()
00003790 853.46649170 Enter Capabilities or PNP device state
00003791 853.46661377 Set event for No pending IO Event
00003792 853.46661377 Exit Capabilities or PNP device state
00003793 853.46667480 Enter fnProcessPnPIrp()
00003794 853.46667480 Enter Capabilities or PNP device state
00003795 853.46667480 Set event for No pending IO Event
00003796 853.46667480 Exit Capabilities or PNP device state
00003797 853.46673584 Enter fnProcessPnPIrp()
00003798 853.46673584 Enter Capabilities or PNP device state
00003799 853.46673584 Set event for No pending IO Event
00003800 853.46673584 Exit Capabilities or PNP device state
00003801 853.46685791 Set event for No pending IO Event
00003802 854.07531738 [88CBA0F0] WskProIRPGetAddrInfo is called.

00003816 855.16186523 Enter fnProcessPnPIrp()
00003817 855.16192627 Enter IRP_MN_REMOVE_DEVICE
00003818 855.16192627 Set event for No pending IO Event
00003819 855.16192627 Set event for remove device event
00003820 855.16192627 Enter fnRemoveDevice()
00003821 855.16229248 Exit IRP_MN_REMOVE_DEVICE