win-pvdrivers

changeset 555:9d6c46298386

Fixed a bug where passing a NULL ScatterGatherBuffer would cause a BSoD
author James Harper <james.harper@bendigoit.com.au>
date Sat Apr 11 10:09:22 2009 +1000 (2009-04-11)
parents 2447875396d0
children 8c315cf5142c
files xenpci/xenpci_pdo.c
line diff
     1.1 --- a/xenpci/xenpci_pdo.c	Fri Apr 03 21:30:56 2009 +1100
     1.2 +++ b/xenpci/xenpci_pdo.c	Sat Apr 11 10:09:22 2009 +1000
     1.3 @@ -574,6 +574,11 @@ XenPci_DOP_BuildScatterGatherList(
     1.4    
     1.5    //FUNCTION_ENTER();
     1.6    
     1.7 +  if (!ScatterGatherBuffer)
     1.8 +  {
     1.9 +    KdPrint((__DRIVER_NAME "     NULL ScatterGatherBuffer\n"));
    1.10 +    return STATUS_INVALID_PARAMETER;
    1.11 +  }
    1.12    ASSERT(MmGetMdlVirtualAddress(Mdl) == CurrentVa);
    1.13  
    1.14    xen_dma_adapter = (xen_dma_adapter_t *)DmaAdapter;
    1.15 @@ -617,6 +622,8 @@ XenPci_DOP_BuildScatterGatherList(
    1.16    if (ScatterGatherBufferLength < FIELD_OFFSET(SCATTER_GATHER_LIST, Elements) +
    1.17      sizeof(SCATTER_GATHER_ELEMENT) * sglist->NumberOfElements + sizeof(sg_extra_t))
    1.18    {
    1.19 +    KdPrint((__DRIVER_NAME "     STATUS_BUFFER_TOO_SMALL (%d < %d)\n", ScatterGatherBufferLength, FIELD_OFFSET(SCATTER_GATHER_LIST, Elements) +
    1.20 +      sizeof(SCATTER_GATHER_ELEMENT) * sglist->NumberOfElements + sizeof(sg_extra_t)));
    1.21      return STATUS_BUFFER_TOO_SMALL;
    1.22    }
    1.23    
    1.24 @@ -633,6 +640,10 @@ XenPci_DOP_BuildScatterGatherList(
    1.25      {
    1.26        remaining = MmGetMdlByteCount(curr_mdl);
    1.27        offset = MmGetMdlByteOffset(curr_mdl);
    1.28 +      if (!remaining)
    1.29 +      {
    1.30 +        KdPrint((__DRIVER_NAME "     zero length MDL\n"));
    1.31 +      }
    1.32        for (i = 0; i < ADDRESS_AND_SIZE_TO_SPAN_PAGES(MmGetMdlVirtualAddress(curr_mdl), MmGetMdlByteCount(curr_mdl)); i++)
    1.33        {
    1.34  //KdPrint((__DRIVER_NAME "     element = %d\n", sg_element));
    1.35 @@ -654,7 +665,7 @@ XenPci_DOP_BuildScatterGatherList(
    1.36      sg_extra->aligned_buffer = ExAllocatePoolWithTag(NonPagedPool, max(Length, PAGE_SIZE), XENPCI_POOL_TAG);
    1.37      if (!sg_extra->aligned_buffer)
    1.38      {
    1.39 -      //KdPrint((__DRIVER_NAME "     MAP_TYPE_REMAPPED buffer allocation failed - requested va = %p, length = %d\n", MmGetMdlVirtualAddress(Mdl), Length));
    1.40 +      KdPrint((__DRIVER_NAME "     MAP_TYPE_REMAPPED buffer allocation failed - requested va = %p, length = %d\n", MmGetMdlVirtualAddress(Mdl), Length));
    1.41        return STATUS_INSUFFICIENT_RESOURCES;
    1.42      }
    1.43      //KdPrint((__DRIVER_NAME "     MAP_TYPE_REMAPPED - %p -> %p\n", MmGetMdlVirtualAddress(Mdl), sg_extra->aligned_buffer));
    1.44 @@ -682,6 +693,9 @@ XenPci_DOP_BuildScatterGatherList(
    1.45      sglist->Elements[0].Length = Length;
    1.46      //KdPrint((__DRIVER_NAME "     MAP_TYPE_VIRTUAL - %08x\n", sglist->Elements[0].Address.LowPart));
    1.47      break;
    1.48 +  default:
    1.49 +    KdPrint((__DRIVER_NAME "     map_type = %d\n", map_type));
    1.50 +    break;
    1.51    }
    1.52  
    1.53    ExecutionRoutine(DeviceObject, DeviceObject->CurrentIrp, ScatterGatherBuffer, Context);