[SCSIPORT]: Fixes + documentation:

- In SpiSendInquiry():
  * use ExFreePoolWithTag;
  * if IoBuildDeviceIoControlRequest() fails, exit correctly the loop so that the allocated buffers are cleaned up;
- In SpiBuildDeviceMap():
  * support new peripheral type names, as documented in the links in the comments;
  * fix the "CommunicationsPeripheral" name (communication'S') as documented, and as done in windows' scsiport driver.

svn path=/trunk/; revision=74595
This commit is contained in:
Hermès Bélusca-Maïto 2017-05-19 15:02:02 +00:00
parent b00727337e
commit 87d9dfae0d

View file

@ -3565,7 +3565,7 @@ SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
PSCSI_PORT_LUN_EXTENSION LunExtension; PSCSI_PORT_LUN_EXTENSION LunExtension;
PSCSI_PORT_DEVICE_EXTENSION DeviceExtension; PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
DPRINT ("SpiSendInquiry() called\n"); DPRINT("SpiSendInquiry() called\n");
DeviceExtension = (PSCSI_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension; DeviceExtension = (PSCSI_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
@ -3576,7 +3576,7 @@ SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
SenseBuffer = ExAllocatePoolWithTag(NonPagedPool, SENSE_BUFFER_SIZE, TAG_SCSIPORT); SenseBuffer = ExAllocatePoolWithTag(NonPagedPool, SENSE_BUFFER_SIZE, TAG_SCSIPORT);
if (SenseBuffer == NULL) if (SenseBuffer == NULL)
{ {
ExFreePool(InquiryBuffer); ExFreePoolWithTag(InquiryBuffer, TAG_SCSIPORT);
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
} }
@ -3600,7 +3600,11 @@ SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
if (Irp == NULL) if (Irp == NULL)
{ {
DPRINT("IoBuildDeviceIoControlRequest() failed\n"); DPRINT("IoBuildDeviceIoControlRequest() failed\n");
return STATUS_INSUFFICIENT_RESOURCES;
/* Quit the loop */
Status = STATUS_INSUFFICIENT_RESOURCES;
KeepTrying = FALSE;
continue;
} }
/* Prepare SRB */ /* Prepare SRB */
@ -3656,6 +3660,7 @@ SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
InquiryBuffer, InquiryBuffer,
INQUIRYDATABUFFERSIZE); INQUIRYDATABUFFERSIZE);
/* Quit the loop */
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
KeepTrying = FALSE; KeepTrying = FALSE;
continue; continue;
@ -3701,6 +3706,7 @@ SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
(Srb.DataTransferLength > INQUIRYDATABUFFERSIZE) ? (Srb.DataTransferLength > INQUIRYDATABUFFERSIZE) ?
INQUIRYDATABUFFERSIZE : Srb.DataTransferLength); INQUIRYDATABUFFERSIZE : Srb.DataTransferLength);
/* Quit the loop */
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
KeepTrying = FALSE; KeepTrying = FALSE;
} }
@ -3710,6 +3716,7 @@ SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
/* LUN is not valid, but some device responds there. /* LUN is not valid, but some device responds there.
Mark it as invalid anyway */ Mark it as invalid anyway */
/* Quit the loop */
Status = STATUS_INVALID_DEVICE_REQUEST; Status = STATUS_INVALID_DEVICE_REQUEST;
KeepTrying = FALSE; KeepTrying = FALSE;
} }
@ -3725,7 +3732,7 @@ SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
} }
else else
{ {
/* That's all, go to exit */ /* That's all, quit the loop */
KeepTrying = FALSE; KeepTrying = FALSE;
/* Set status according to SRB status */ /* Set status according to SRB status */
@ -3743,8 +3750,8 @@ SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
} }
/* Free buffers */ /* Free buffers */
ExFreePool(InquiryBuffer); ExFreePoolWithTag(InquiryBuffer, TAG_SCSIPORT);
ExFreePool(SenseBuffer); ExFreePoolWithTag(SenseBuffer, TAG_SCSIPORT);
DPRINT("SpiSendInquiry() done with Status 0x%08X\n", Status); DPRINT("SpiSendInquiry() done with Status 0x%08X\n", Status);
@ -5574,6 +5581,11 @@ SpiBuildDeviceMap(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
} }
/* Set 'Type' (REG_SZ) value */ /* Set 'Type' (REG_SZ) value */
/*
* See https://docs.microsoft.com/en-us/windows-hardware/drivers/install/identifiers-for-ide-devices
* and https://docs.microsoft.com/en-us/windows-hardware/drivers/install/identifiers-for-scsi-devices
* for a list of types with their human-readable forms.
*/
switch (LunExtension->InquiryData.DeviceType) switch (LunExtension->InquiryData.DeviceType)
{ {
case 0: case 0:
@ -5585,6 +5597,7 @@ SpiBuildDeviceMap(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
case 2: case 2:
TypeName = L"PrinterPeripheral"; TypeName = L"PrinterPeripheral";
break; break;
// case 3: "ProcessorPeripheral", classified as 'other': fall back to default case.
case 4: case 4:
TypeName = L"WormPeripheral"; TypeName = L"WormPeripheral";
break; break;
@ -5601,8 +5614,29 @@ SpiBuildDeviceMap(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
TypeName = L"MediumChangerPeripheral"; TypeName = L"MediumChangerPeripheral";
break; break;
case 9: case 9:
TypeName = L"CommunicationPeripheral"; TypeName = L"CommunicationsPeripheral";
break; break;
/* New peripheral types (SCSI only) */
case 10: case 11:
TypeName = L"ASCPrePressGraphicsPeripheral";
break;
case 12:
TypeName = L"ArrayPeripheral";
break;
case 13:
TypeName = L"EnclosurePeripheral";
break;
case 14:
TypeName = L"RBCPeripheral";
break;
case 15:
TypeName = L"CardReaderPeripheral";
break;
case 16:
TypeName = L"BridgePeripheral";
break;
default: default:
TypeName = L"OtherPeripheral"; TypeName = L"OtherPeripheral";
break; break;