win-pvdrivers

changeset 990:20ea0ca954e4

Fix gref leak.
Change ASSERTS to NT_ASSERTS
author James Harper <james.harper@bendigoit.com.au>
date Fri Sep 21 23:24:00 2012 +1000 (2012-09-21)
parents fa9851d4a67a
children e9903455ba9d
files xennet/xennet6.c xennet/xennet6_rx.c xennet/xennet6_tx.c
line diff
     1.1 --- a/xennet/xennet6.c	Fri Sep 21 16:43:11 2012 +1000
     1.2 +++ b/xennet/xennet6.c	Fri Sep 21 23:24:00 2012 +1000
     1.3 @@ -142,7 +142,7 @@ XenNet_ConnectBackend(struct xennet_info
     1.4  
     1.5    FUNCTION_ENTER();
     1.6    
     1.7 -  ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
     1.8 +  NT_ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
     1.9  
    1.10    xi->backend_csum_supported = TRUE; /* just assume this */
    1.11    xi->backend_gso_value = 0;
    1.12 @@ -252,7 +252,7 @@ XenNet_ResumeWorkItem(PDEVICE_OBJECT dev
    1.13    
    1.14    FUNCTION_ENTER();
    1.15  
    1.16 -  ASSERT(xi->resume_work_item);
    1.17 +  NT_ASSERT(xi->resume_work_item);
    1.18  
    1.19    IoFreeWorkItem(xi->resume_work_item);
    1.20    
     2.1 --- a/xennet/xennet6_rx.c	Fri Sep 21 16:43:11 2012 +1000
     2.2 +++ b/xennet/xennet6_rx.c	Fri Sep 21 23:24:00 2012 +1000
     2.3 @@ -84,9 +84,10 @@ put_pb_on_freelist(struct xennet_info *x
     2.4      //NDIS_BUFFER_LINKAGE(pb->buffer) = NULL;
     2.5      if (xi->rx_pb_free > RX_MAX_PB_FREELIST)
     2.6      {
     2.7 +      xi->vectors.GntTbl_EndAccess(xi->vectors.context, pb->gref, FALSE, (ULONG)'XNRX');
     2.8        IoFreeMdl(pb->mdl);
     2.9 -    NdisFreeMemory(pb->virtual, PAGE_SIZE, 0);
    2.10 -    NdisFreeMemory(pb, sizeof(shared_buffer_t), 0);
    2.11 +      NdisFreeMemory(pb->virtual, PAGE_SIZE, 0);
    2.12 +      NdisFreeMemory(pb, sizeof(shared_buffer_t), 0);
    2.13        return;
    2.14      }
    2.15      pb->mdl->ByteCount = PAGE_SIZE;
    2.16 @@ -131,7 +132,7 @@ get_hb_from_freelist(struct xennet_info 
    2.17  static __inline VOID
    2.18  put_hb_on_freelist(struct xennet_info *xi, shared_buffer_t *hb)
    2.19  {
    2.20 -  ASSERT(xi);
    2.21 +  NT_ASSERT(xi);
    2.22    hb->mdl->ByteCount = sizeof(shared_buffer_t) + MAX_ETH_HEADER_LENGTH + MAX_LOOKAHEAD_LENGTH;
    2.23    hb->mdl->Next = NULL;
    2.24    hb->next = NULL;
    2.25 @@ -172,12 +173,12 @@ XenNet_FillRing(struct xennet_info *xi)
    2.26  
    2.27      /* Give to netback */
    2.28      id = (USHORT)((req_prod + i) & (NET_RX_RING_SIZE - 1));
    2.29 -    ASSERT(xi->rx_ring_pbs[id] == NULL);
    2.30 +    NT_ASSERT(xi->rx_ring_pbs[id] == NULL);
    2.31      xi->rx_ring_pbs[id] = page_buf;
    2.32      req = RING_GET_REQUEST(&xi->rx, req_prod + i);
    2.33      req->id = id;
    2.34      req->gref = page_buf->gref;
    2.35 -    ASSERT(req->gref != INVALID_GRANT_REF);
    2.36 +    NT_ASSERT(req->gref != INVALID_GRANT_REF);
    2.37    }
    2.38    KeMemoryBarrier();
    2.39    xi->rx.req_prod_pvt = req_prod + i;
    2.40 @@ -243,7 +244,7 @@ XenNet_MakePacket(struct xennet_info *xi
    2.41      NB_FIRST_PB(nb) = pi->first_pb;
    2.42      ref_pb(xi, pi->first_pb);
    2.43    } else {
    2.44 -    ASSERT(ndis_os_minor_version >= 1);
    2.45 +    NT_ASSERT(ndis_os_minor_version >= 1);
    2.46      header_buf = get_hb_from_freelist(xi);
    2.47      if (!header_buf)
    2.48      {
    2.49 @@ -261,7 +262,7 @@ XenNet_MakePacket(struct xennet_info *xi
    2.50      /* make sure only the header is in the first buffer (or the entire packet, but that is done in the above case) */
    2.51      XenNet_BuildHeader(pi, header_va, MAX_ETH_HEADER_LENGTH + pi->ip4_header_length + pi->tcp_header_length);
    2.52      header_extra = pi->header_length - (MAX_ETH_HEADER_LENGTH + pi->ip4_header_length + pi->tcp_header_length);
    2.53 -    ASSERT(pi->header_length <= MAX_ETH_HEADER_LENGTH + MAX_LOOKAHEAD_LENGTH);
    2.54 +    NT_ASSERT(pi->header_length <= MAX_ETH_HEADER_LENGTH + MAX_LOOKAHEAD_LENGTH);
    2.55      header_buf->mdl->ByteCount = pi->header_length;
    2.56      mdl_head = mdl_tail = curr_mdl = header_buf->mdl;
    2.57      NB_FIRST_PB(nb) = header_buf;
    2.58 @@ -286,12 +287,12 @@ XenNet_MakePacket(struct xennet_info *xi
    2.59        pi->tcp_remaining = (USHORT)(pi->tcp_remaining - tcp_length);
    2.60        /* part of the packet is already present in the header buffer for lookahead */
    2.61        out_remaining = tcp_length - header_extra;
    2.62 -      ASSERT((LONG)out_remaining >= 0);
    2.63 +      NT_ASSERT((LONG)out_remaining >= 0);
    2.64      }
    2.65      else
    2.66      {
    2.67        out_remaining = pi->total_length - pi->header_length;
    2.68 -      ASSERT((LONG)out_remaining >= 0);
    2.69 +      NT_ASSERT((LONG)out_remaining >= 0);
    2.70      }
    2.71      //KdPrint((__DRIVER_NAME "     before loop - out_remaining = %d\n", out_remaining));
    2.72  
    2.73 @@ -315,7 +316,7 @@ XenNet_MakePacket(struct xennet_info *xi
    2.74        in_buffer_length = MmGetMdlByteCount(pi->curr_mdl);
    2.75        out_length = min(out_remaining, in_buffer_length - pi->curr_mdl_offset);
    2.76        curr_mdl = IoAllocateMdl((PUCHAR)MmGetMdlVirtualAddress(pi->curr_mdl) + pi->curr_mdl_offset, out_length, FALSE, FALSE, NULL);
    2.77 -      ASSERT(curr_mdl);
    2.78 +      NT_ASSERT(curr_mdl);
    2.79        IoBuildPartialMdl(pi->curr_mdl, curr_mdl, (PUCHAR)MmGetMdlVirtualAddress(pi->curr_mdl) + pi->curr_mdl_offset, out_length);
    2.80        mdl_tail->Next = curr_mdl;
    2.81        mdl_tail = curr_mdl;
    2.82 @@ -508,7 +509,7 @@ XenNet_ReturnNetBufferLists(NDIS_HANDLE 
    2.83  
    2.84    //KdPrint((__DRIVER_NAME "     page_buf = %p\n", page_buf));
    2.85  
    2.86 -  ASSERT(xi);
    2.87 +  NT_ASSERT(xi);
    2.88    while (curr_nbl)
    2.89    {
    2.90      PNET_BUFFER_LIST next_nbl;
    2.91 @@ -530,7 +531,7 @@ XenNet_ReturnNetBufferLists(NDIS_HANDLE 
    2.92          shared_buffer_t *next_buf;
    2.93          PMDL next_mdl;
    2.94          
    2.95 -        ASSERT(page_buf); /* make sure that there is a pb to match this mdl */
    2.96 +        NT_ASSERT(page_buf); /* make sure that there is a pb to match this mdl */
    2.97          next_mdl = curr_mdl->Next;
    2.98          next_buf = page_buf->next;
    2.99          if (!page_buf->virtual)
   2.100 @@ -638,7 +639,7 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.101      {
   2.102        id = (USHORT)(cons & (NET_RX_RING_SIZE - 1));
   2.103        page_buf = xi->rx_ring_pbs[id];
   2.104 -      ASSERT(page_buf);
   2.105 +      NT_ASSERT(page_buf);
   2.106        xi->rx_ring_pbs[id] = NULL;
   2.107        xi->rx_id_free++;
   2.108        memcpy(&page_buf->rsp, RING_GET_RESPONSE(&xi->rx, cons), max(sizeof(struct netif_rx_response), sizeof(struct netif_extra_info)));
   2.109 @@ -649,7 +650,7 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.110          {
   2.111            KdPrint((__DRIVER_NAME "     Error: rsp offset %d, size %d\n",
   2.112              page_buf->rsp.offset, page_buf->rsp.status));
   2.113 -          ASSERT(!extra_info_flag);
   2.114 +          NT_ASSERT(!extra_info_flag);
   2.115            put_pb_on_freelist(xi, page_buf);
   2.116            continue;
   2.117          }
   2.118 @@ -759,7 +760,7 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.119          case XEN_NETIF_GSO_TYPE_TCPV4:
   2.120            pi->mss = ei->u.gso.size;
   2.121            //KdPrint((__DRIVER_NAME "     mss = %d\n", pi->mss));
   2.122 -          // TODO - put this assertion somewhere ASSERT(header_len + pi->mss <= PAGE_SIZE); // this limits MTU to PAGE_SIZE - XN_HEADER_LEN
   2.123 +          // TODO - put this assertion somewhere NT_ASSERT(header_len + pi->mss <= PAGE_SIZE); // this limits MTU to PAGE_SIZE - XN_HEADER_LEN
   2.124            break;
   2.125          default:
   2.126            KdPrint((__DRIVER_NAME "     Unknown GSO type (%d) detected\n", ei->u.gso.type));
   2.127 @@ -774,7 +775,7 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.128      }
   2.129      else
   2.130      {
   2.131 -      ASSERT(!page_buf->rsp.offset);
   2.132 +      NT_ASSERT(!page_buf->rsp.offset);
   2.133        if (!more_data_flag) // handling the packet's 1st buffer
   2.134        {
   2.135          if (page_buf->rsp.flags & NETRXF_csum_blank)
   2.136 @@ -787,11 +788,11 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.137        //KdPrint((__DRIVER_NAME "     buffer = %p, pb = %p\n", buffer, page_buf));
   2.138        if (pi->first_pb)
   2.139        {
   2.140 -        ASSERT(pi->curr_pb);
   2.141 +        NT_ASSERT(pi->curr_pb);
   2.142          //KdPrint((__DRIVER_NAME "     additional buffer\n"));
   2.143          pi->curr_pb->next = page_buf;
   2.144          pi->curr_pb = page_buf;
   2.145 -        ASSERT(pi->curr_mdl);
   2.146 +        NT_ASSERT(pi->curr_mdl);
   2.147          pi->curr_mdl->Next = mdl;
   2.148          pi->curr_mdl = mdl;
   2.149        }
   2.150 @@ -818,7 +819,7 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.151  
   2.152      page_buf = next_buf;
   2.153    }
   2.154 -  ASSERT(!more_data_flag && !extra_info_flag);
   2.155 +  NT_ASSERT(!more_data_flag && !extra_info_flag);
   2.156  
   2.157    if (rc.first_nbl)
   2.158    {
     3.1 --- a/xennet/xennet6_tx.c	Fri Sep 21 16:43:11 2012 +1000
     3.2 +++ b/xennet/xennet6_tx.c	Fri Sep 21 23:24:00 2012 +1000
     3.3 @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fi
     3.4  static USHORT
     3.5  get_id_from_freelist(struct xennet_info *xi)
     3.6  {
     3.7 -  ASSERT(xi->tx_id_free);
     3.8 +  NT_ASSERT(xi->tx_id_free);
     3.9    xi->tx_id_free--;
    3.10  
    3.11    return xi->tx_id_list[xi->tx_id_free];
    3.12 @@ -46,15 +46,15 @@ XenNet_PutCbOnRing(struct xennet_info *x
    3.13    xi->tx.req_prod_pvt++;
    3.14    xi->tx_ring_free--;
    3.15    tx->id = get_id_from_freelist(xi);
    3.16 -  ASSERT(xi->tx_shadows[tx->id].gref == INVALID_GRANT_REF);
    3.17 -  ASSERT(!xi->tx_shadows[tx->id].cb);
    3.18 +  NT_ASSERT(xi->tx_shadows[tx->id].gref == INVALID_GRANT_REF);
    3.19 +  NT_ASSERT(!xi->tx_shadows[tx->id].cb);
    3.20    xi->tx_shadows[tx->id].cb = coalesce_buf;
    3.21    tx->gref = xi->vectors.GntTbl_GrantAccess(xi->vectors.context, (ULONG)(MmGetPhysicalAddress(coalesce_buf).QuadPart >> PAGE_SHIFT), FALSE, gref, (ULONG)'XNTX');
    3.22    xi->tx_shadows[tx->id].gref = tx->gref;
    3.23    tx->offset = 0;
    3.24    tx->size = (USHORT)length;
    3.25 -  ASSERT(tx->offset + tx->size <= PAGE_SIZE);
    3.26 -  ASSERT(tx->size);
    3.27 +  NT_ASSERT(tx->offset + tx->size <= PAGE_SIZE);
    3.28 +  NT_ASSERT(tx->size);
    3.29    return tx;
    3.30  }
    3.31    
    3.32 @@ -269,7 +269,7 @@ XenNet_HWSendPacket(struct xennet_info *
    3.33  
    3.34    /* (A) */
    3.35    tx0 = XenNet_PutCbOnRing(xi, coalesce_buf, pi.header_length, gref);
    3.36 -  ASSERT(tx0); /* this will never happen */
    3.37 +  NT_ASSERT(tx0); /* this will never happen */
    3.38    tx0->flags = flags;
    3.39    tx_length += pi.header_length;
    3.40  
    3.41 @@ -283,7 +283,7 @@ XenNet_HWSendPacket(struct xennet_info *
    3.42    /* (B) */
    3.43    if (xen_gso)
    3.44    {
    3.45 -    ASSERT(flags & NETTXF_extra_info);
    3.46 +    NT_ASSERT(flags & NETTXF_extra_info);
    3.47      ei = (struct netif_extra_info *)RING_GET_REQUEST(&xi->tx, xi->tx.req_prod_pvt);
    3.48      //KdPrint((__DRIVER_NAME "     pos = %d\n", xi->tx.req_prod_pvt));
    3.49      xi->tx.req_prod_pvt++;
    3.50 @@ -296,7 +296,7 @@ XenNet_HWSendPacket(struct xennet_info *
    3.51      ei->u.gso.features = 0;
    3.52    }
    3.53  
    3.54 -  ASSERT(xi->current_sg_supported || !remaining);
    3.55 +  NT_ASSERT(xi->current_sg_supported || !remaining);
    3.56    
    3.57    /* (C) - only if data is remaining */
    3.58    coalesce_buf = NULL;
    3.59 @@ -305,7 +305,7 @@ XenNet_HWSendPacket(struct xennet_info *
    3.60      ULONG length;
    3.61      PFN_NUMBER pfn;
    3.62      
    3.63 -    ASSERT(pi.curr_mdl);
    3.64 +    NT_ASSERT(pi.curr_mdl);
    3.65      if (coalesce_required)
    3.66      {
    3.67        PVOID va;
    3.68 @@ -356,7 +356,7 @@ XenNet_HWSendPacket(struct xennet_info *
    3.69        if (remaining)
    3.70        {
    3.71          txN = XenNet_PutCbOnRing(xi, coalesce_buf, min(PAGE_SIZE, remaining), gref);
    3.72 -        ASSERT(txN);
    3.73 +        NT_ASSERT(txN);
    3.74          coalesce_buf = NULL;
    3.75          tx_length += min(PAGE_SIZE, remaining);
    3.76          remaining -= min(PAGE_SIZE, remaining);
    3.77 @@ -376,18 +376,18 @@ XenNet_HWSendPacket(struct xennet_info *
    3.78        xi->tx.req_prod_pvt++;
    3.79        xi->tx_ring_free--;
    3.80        txN->id = get_id_from_freelist(xi);
    3.81 -      ASSERT(!xi->tx_shadows[txN->id].cb);
    3.82 +      NT_ASSERT(!xi->tx_shadows[txN->id].cb);
    3.83        offset = MmGetMdlByteOffset(pi.curr_mdl) + pi.curr_mdl_offset;
    3.84        pfn = MmGetMdlPfnArray(pi.curr_mdl)[offset >> PAGE_SHIFT];
    3.85        txN->offset = (USHORT)offset & (PAGE_SIZE - 1);
    3.86        txN->gref = xi->vectors.GntTbl_GrantAccess(xi->vectors.context, (ULONG)pfn, FALSE, gref, (ULONG)'XNTX');
    3.87 -      ASSERT(xi->tx_shadows[txN->id].gref == INVALID_GRANT_REF);
    3.88 +      NT_ASSERT(xi->tx_shadows[txN->id].gref == INVALID_GRANT_REF);
    3.89        xi->tx_shadows[txN->id].gref = txN->gref;
    3.90        //ASSERT(sg->Elements[sg_element].Length > sg_offset);
    3.91        txN->size = (USHORT)length;
    3.92 -      ASSERT(txN->offset + txN->size <= PAGE_SIZE);
    3.93 -      ASSERT(txN->size);
    3.94 -      ASSERT(txN->gref != INVALID_GRANT_REF);
    3.95 +      NT_ASSERT(txN->offset + txN->size <= PAGE_SIZE);
    3.96 +      NT_ASSERT(txN->size);
    3.97 +      NT_ASSERT(txN->gref != INVALID_GRANT_REF);
    3.98        remaining -= length;
    3.99        tx_length += length;
   3.100      }
   3.101 @@ -396,8 +396,8 @@ XenNet_HWSendPacket(struct xennet_info *
   3.102      XenNet_EatData(&pi, length);
   3.103    }
   3.104    txN->flags &= ~NETTXF_more_data;
   3.105 -  ASSERT(tx0->size == pi.total_length);
   3.106 -  ASSERT(!xi->tx_shadows[txN->id].nb);
   3.107 +  NT_ASSERT(tx0->size == pi.total_length);
   3.108 +  NT_ASSERT(!xi->tx_shadows[txN->id].nb);
   3.109    xi->tx_shadows[txN->id].nb = nb;
   3.110  
   3.111    switch (lso_info.Transmit.Type)
   3.112 @@ -427,7 +427,7 @@ XenNet_SendQueuedPackets(struct xennet_i
   3.113  
   3.114    //FUNCTION_ENTER();
   3.115  
   3.116 -  ASSERT(!KeTestSpinLock(&xi->tx_lock));
   3.117 +  NT_ASSERT(!KeTestSpinLock(&xi->tx_lock));
   3.118    if (xi->device_state->suspend_resume_state_pdo != SR_STATE_RUNNING)
   3.119      return;
   3.120  
   3.121 @@ -467,7 +467,7 @@ XenNet_TxBufferGC(struct xennet_info *xi
   3.122  
   3.123    if (!xi->connected)
   3.124      return; /* a delayed DPC could let this come through... just do nothing */
   3.125 -  ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
   3.126 +  NT_ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
   3.127  
   3.128    KeAcquireSpinLockAtDpcLevel(&xi->tx_lock);
   3.129  
   3.130 @@ -684,7 +684,7 @@ XenNet_CancelSend(NDIS_HANDLE adapter_co
   3.131      {
   3.132        KdPrint((__DRIVER_NAME "     Found packet to cancel %p\n", packet));
   3.133        result = RemoveEntryList((PLIST_ENTRY)&packet->MiniportReservedEx[sizeof(PVOID)]);
   3.134 -      ASSERT(result);
   3.135 +      NT_ASSERT(result);
   3.136        *(PNDIS_PACKET *)&packet->MiniportReservedEx[0] = NULL;
   3.137        if (head)
   3.138          *(PNDIS_PACKET *)&tail->MiniportReservedEx[0] = packet;