Use ObOpenObjectByPointer instead of creating ourselves the IRP_MJ_CREATE/CLEANUP...
[reactos.git] / reactos / drivers / bus / serenum / detect.c
index 655f48b..252e106 100644 (file)
@@ -60,44 +60,6 @@ DeviceIoControl(
        return Status;
 }
 
-static NTSTATUS
-SendIrp(
-       IN PDEVICE_OBJECT DeviceObject,
-       IN ULONG MajorFunction)
-{
-       KEVENT Event;
-       PIRP Irp;
-       IO_STATUS_BLOCK IoStatus;
-       NTSTATUS Status;
-
-       KeInitializeEvent(&Event, NotificationEvent, FALSE);
-
-       Irp = IoBuildSynchronousFsdRequest(
-               MajorFunction,
-               DeviceObject,
-               NULL,
-               0,
-               NULL,
-               &Event,
-               &IoStatus);
-       if (Irp == NULL)
-       {
-               DPRINT("IoBuildSynchronousFsdRequest() failed\n");
-               return STATUS_INSUFFICIENT_RESOURCES;
-       }
-
-       Status = IoCallDriver(DeviceObject, Irp);
-
-       if (Status == STATUS_PENDING)
-       {
-               DPRINT("Operation pending\n");
-               KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
-               Status = IoStatus.Status;
-       }
-
-       return Status;
-}
-
 static NTSTATUS
 ReadBytes(
        IN PDEVICE_OBJECT LowerDevice,
@@ -256,6 +218,7 @@ SerenumDetectPnpDevice(
        IN PDEVICE_OBJECT DeviceObject,
        IN PDEVICE_OBJECT LowerDevice)
 {
+       HANDLE Handle = NULL;
        UCHAR Buffer[256];
        ULONG BaudRate;
        ULONG_PTR TotalBytesReceived = 0;
@@ -270,7 +233,14 @@ SerenumDetectPnpDevice(
        NTSTATUS Status;
 
        /* Open port */
-       Status = SendIrp(LowerDevice, IRP_MJ_CREATE);
+       Status = ObOpenObjectByPointer(
+               LowerDevice,
+               OBJ_KERNEL_HANDLE,
+               NULL,
+               0,
+               NULL,
+               KernelMode,
+               &Handle);
        if (!NT_SUCCESS(Status)) goto ByeBye;
 
        /* 1. COM port initialization, check for device enumerate */
@@ -459,8 +429,8 @@ DisconnectIdle:
 
 ByeBye:
        /* Close port */
-       SendIrp(LowerDevice, IRP_MJ_CLOSE);
-       SendIrp(LowerDevice, IRP_MJ_CLEANUP);
+       if (Handle)
+               ZwClose(Handle);
        return Status;
 }
 
@@ -469,6 +439,7 @@ SerenumDetectLegacyDevice(
        IN PDEVICE_OBJECT DeviceObject,
        IN PDEVICE_OBJECT LowerDevice)
 {
+       HANDLE Handle = NULL;
        ULONG Fcr, Mcr;
        ULONG BaudRate;
        ULONG Command;
@@ -490,7 +461,14 @@ SerenumDetectLegacyDevice(
        RtlZeroMemory(Buffer, sizeof(Buffer));
 
        /* Open port */
-       Status = SendIrp(LowerDevice, IRP_MJ_CREATE);
+       Status = ObOpenObjectByPointer(
+               LowerDevice,
+               OBJ_EXCLUSIVE | OBJ_KERNEL_HANDLE,
+               NULL,
+               0,
+               NULL,
+               KernelMode,
+               &Handle);
        if (!NT_SUCCESS(Status)) return Status;
 
        /* Reset UART */
@@ -610,7 +588,7 @@ SerenumDetectLegacyDevice(
 
 ByeBye:
        /* Close port */
-       SendIrp(LowerDevice, IRP_MJ_CLOSE);
-       SendIrp(LowerDevice, IRP_MJ_CLEANUP);
+       if (Handle)
+               ZwClose(Handle);
        return Status;
 }