[USBSTOR] Do not print device descriptor by default.
authorVictor Perevertkin <victor@perevertkin.ru>
Tue, 25 Jun 2019 16:04:20 +0000 (19:04 +0300)
committerVictor Perevertkin <victor@perevertkin.ru>
Tue, 25 Jun 2019 16:04:20 +0000 (19:04 +0300)
Add SrbGetCdb macro

drivers/usb/usbstor/fdo.c
drivers/usb/usbstor/scsi.c
drivers/usb/usbstor/usbstor.h

index a8a1a4d..7b5dfc0 100644 (file)
 #include <debug.h>
 
 
+#if DBG
+static
 VOID
 USBSTOR_DumpDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor)
 {
-    DPRINT1("Dumping Device Descriptor %p\n", DeviceDescriptor);
-    DPRINT1("bLength %x\n", DeviceDescriptor->bLength);
-    DPRINT1("bDescriptorType %x\n", DeviceDescriptor->bDescriptorType);
-    DPRINT1("bcdUSB %x\n", DeviceDescriptor->bcdUSB);
-    DPRINT1("bDeviceClass %x\n", DeviceDescriptor->bDeviceClass);
-    DPRINT1("bDeviceSubClass %x\n", DeviceDescriptor->bDeviceSubClass);
-    DPRINT1("bDeviceProtocol %x\n", DeviceDescriptor->bDeviceProtocol);
-    DPRINT1("bMaxPacketSize0 %x\n", DeviceDescriptor->bMaxPacketSize0);
-    DPRINT1("idVendor %x\n", DeviceDescriptor->idVendor);
-    DPRINT1("idProduct %x\n", DeviceDescriptor->idProduct);
-    DPRINT1("bcdDevice %x\n", DeviceDescriptor->bcdDevice);
-    DPRINT1("iManufacturer %x\n", DeviceDescriptor->iManufacturer);
-    DPRINT1("iProduct %x\n", DeviceDescriptor->iProduct);
-    DPRINT1("iSerialNumber %x\n", DeviceDescriptor->iSerialNumber);
-    DPRINT1("bNumConfigurations %x\n", DeviceDescriptor->bNumConfigurations);
+    DPRINT("Dumping Device Descriptor %p\n", DeviceDescriptor);
+    DPRINT("bLength %x\n", DeviceDescriptor->bLength);
+    DPRINT("bDescriptorType %x\n", DeviceDescriptor->bDescriptorType);
+    DPRINT("bcdUSB %x\n", DeviceDescriptor->bcdUSB);
+    DPRINT("bDeviceClass %x\n", DeviceDescriptor->bDeviceClass);
+    DPRINT("bDeviceSubClass %x\n", DeviceDescriptor->bDeviceSubClass);
+    DPRINT("bDeviceProtocol %x\n", DeviceDescriptor->bDeviceProtocol);
+    DPRINT("bMaxPacketSize0 %x\n", DeviceDescriptor->bMaxPacketSize0);
+    DPRINT("idVendor %x\n", DeviceDescriptor->idVendor);
+    DPRINT("idProduct %x\n", DeviceDescriptor->idProduct);
+    DPRINT("bcdDevice %x\n", DeviceDescriptor->bcdDevice);
+    DPRINT("iManufacturer %x\n", DeviceDescriptor->iManufacturer);
+    DPRINT("iProduct %x\n", DeviceDescriptor->iProduct);
+    DPRINT("iSerialNumber %x\n", DeviceDescriptor->iSerialNumber);
+    DPRINT("bNumConfigurations %x\n", DeviceDescriptor->bNumConfigurations);
 }
+#endif
 
 NTSTATUS
 USBSTOR_FdoHandleDeviceRelations(
@@ -184,8 +187,9 @@ USBSTOR_FdoHandleStartDevice(
         return Status;
     }
 
+#if DBG
     USBSTOR_DumpDeviceDescriptor(DeviceExtension->DeviceDescriptor);
-
+#endif
 
     // Check that this device uses bulk transfers and is SCSI
 
index f917e03..be27921 100644 (file)
@@ -81,17 +81,17 @@ USBSTOR_IssueBulkOrInterruptRequest(
     Context->Urb.UrbBulkOrInterruptTransfer.TransferBuffer = TransferBuffer;
     Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferMDL = TransferBufferMDL;
 
-    NextStack = IoGetNextIrpStackLocation(Irp); 
-    NextStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; 
-    NextStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB; 
-    NextStack->Parameters.Others.Argument1 = &Context->Urb; 
+    NextStack = IoGetNextIrpStackLocation(Irp);
+    NextStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
+    NextStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
+    NextStack->Parameters.Others.Argument1 = &Context->Urb;
 
     IoSetCompletionRoutine(Irp,
                            CompletionRoutine,
                            Context,
                            TRUE,
                            TRUE,
-                           TRUE); 
+                           TRUE);
 
     return IoCallDriver(FDODeviceExtension->LowerDeviceObject, Irp);
 }
@@ -210,7 +210,7 @@ USBSTOR_CSWCompletionRoutine(
         DPRINT("USBSTOR_CSWCompletionRoutine: CSW_STATUS_COMMAND_FAILED\n");
 
         ASSERT(FDODeviceExtension->ActiveSrb == Request);
-        
+
         // setting a generic error status, additional information
         // should be read by higher-level driver from SenseInfoBuffer
         Request->SrbStatus = SRB_STATUS_ERROR;
@@ -410,7 +410,7 @@ USBSTOR_CBWCompletionRoutine(
                                 FALSE,
                                 FALSE,
                                 NULL);
-    
+
             if (Mdl)
             {
                 IoBuildPartialMdl(Irp->MdlAddress,
@@ -526,7 +526,6 @@ USBSTOR_IssueRequestSense(
     PIO_STACK_LOCATION IoStack;
     PSCSI_REQUEST_BLOCK CurrentSrb;
     PSCSI_REQUEST_BLOCK SenseSrb;
-    PCDB pCDB;
 
     DPRINT("USBSTOR_IssueRequestSense: \n");
 
@@ -551,9 +550,8 @@ USBSTOR_IssueRequestSense(
     SenseSrb->DataTransferLength = CurrentSrb->SenseInfoBufferLength;
     SenseSrb->DataBuffer = CurrentSrb->SenseInfoBuffer;
 
-    pCDB = (PCDB)SenseSrb->Cdb;
-    pCDB->CDB6GENERIC.OperationCode = SCSIOP_REQUEST_SENSE;
-    pCDB->AsByte[4] = CurrentSrb->SenseInfoBufferLength;
+    SrbGetCdb(SenseSrb)->CDB6GENERIC.OperationCode = SCSIOP_REQUEST_SENSE;
+    SrbGetCdb(SenseSrb)->AsByte[4] = CurrentSrb->SenseInfoBufferLength;
 
     return USBSTOR_SendCBWRequest(FDODeviceExtension, Irp, Context);
 }
@@ -563,7 +561,6 @@ USBSTOR_HandleExecuteSCSI(
     IN PDEVICE_OBJECT DeviceObject,
     IN PIRP Irp)
 {
-    PCDB pCDB;
     NTSTATUS Status;
     PIO_STACK_LOCATION IoStack;
     PSCSI_REQUEST_BLOCK Request;
@@ -575,12 +572,11 @@ USBSTOR_HandleExecuteSCSI(
 
     IoStack = IoGetCurrentIrpStackLocation(Irp);
     Request = IoStack->Parameters.Scsi.Srb;
-    pCDB = (PCDB)Request->Cdb;
 
-    DPRINT("USBSTOR_HandleExecuteSCSI Operation Code %x, Length %lu\n", pCDB->CDB10.OperationCode, Request->DataTransferLength);
+    DPRINT("USBSTOR_HandleExecuteSCSI Operation Code %x, Length %lu\n", SrbGetCdb(Request)->CDB10.OperationCode, Request->DataTransferLength);
 
     // check that we're sending to the right LUN
-    ASSERT(pCDB->CDB10.LogicalUnitNumber == (PDODeviceExtension->LUN & MAX_LUN));
+    ASSERT(SrbGetCdb(Request)->CDB10.LogicalUnitNumber == (PDODeviceExtension->LUN & MAX_LUN));
     Context = ExAllocatePoolWithTag(NonPagedPool, sizeof(IRP_CONTEXT), USB_STOR_TAG);
 
     if (!Context)
index 9fc3101..16bd314 100644 (file)
 #define BooleanFlagOn(Flags, SingleFlag) ((BOOLEAN)((((Flags) & (SingleFlag)) != 0)))
 #endif
 
+#ifndef SrbGetCdb
+#define SrbGetCdb(srb) ((PCDB)(srb->Cdb))
+#endif
+
 #define USB_RECOVERABLE_ERRORS (USBD_STATUS_STALL_PID | USBD_STATUS_DEV_NOT_RESPONDING \
        | USBD_STATUS_ENDPOINT_HALTED | USBD_STATUS_NO_BANDWIDTH)