[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/3] Fix CodeQL warnings


  • To: <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Owen Smith <owen.smith@xxxxxxxxxx>
  • Date: Thu, 12 Aug 2021 13:44:27 +0100
  • Authentication-results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Owen Smith <owen.smith@xxxxxxxxxx>
  • Delivery-date: Thu, 12 Aug 2021 12:44:51 +0000
  • Ironport-hdrordr: A9a23:Uuvzh60di0cjyfzPZU+1RAqjBGgkLtp133Aq2lEZdPUMSL3iqy iv9M5rtiMc+wxhIk3I+OrwRpVoJEm3yXcb2/h3AV7PZmjbUS6TXflfBOjZskzd8k/Fh4hgPM 5bGsAUZbGeY2SSz/yKmTVQeOxQouVvhZrY4ds2uE0dKD2CBZsB0+4zMHfnLqQ/fng7OXMWLu vi2vZ6
  • Ironport-sdr: YhCaqMCz8mrbqegoSoka1t8S9N1C1pTSBIoScNClOrfFyfSfMxlpXnr0j2E2y1IKmzxCkGtknv D32tGoyDJDvBLmt5M257nhDVANRBiOIUW2DegXpGOOIBp5LVACMmJTv1lufad6CyYnCLF0uyV1 PK7TPuvgh43SXx1LlwqCeL9iQPMaXNd+MMuFzHD6mytbabb2SIC2F04Poakt/OWZ9JpLTFoosb 431KWX4HfNrCql8UcLwRZi/F7hCrcUyVSEwfoPukHOEMx5/1dAuH0MDSlvXvvaEcwdXpYaKLXt XGn9CTyCv81DxUCAovZ42MlC
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

- ExAllocatePoolWithTag has been deprecated with Win10 2004, use
    ExAllocatePoolUninitialized instead
- Check return value of _strtoui64 for error condition as indicated by
    _UI64_MAX

Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
 src/xenvif/fdo.c  |  4 +---
 src/xenvif/mac.c  |  2 ++
 src/xenvif/pdo.c  | 16 ++++------------
 src/xenvif/util.h |  4 ++++
 4 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/src/xenvif/fdo.c b/src/xenvif/fdo.c
index 745f948..8067e03 100644
--- a/src/xenvif/fdo.c
+++ b/src/xenvif/fdo.c
@@ -1879,14 +1879,12 @@ FdoQueryDeviceRelations(
 
     Size = FIELD_OFFSET(DEVICE_RELATIONS, Objects) + (sizeof (PDEVICE_OBJECT) 
* __max(Count, 1));
 
-    Relations = ExAllocatePoolWithTag(PagedPool, Size, 'FIV');
+    Relations = __AllocatePoolWithTag(PagedPool, Size, 'FIV');
 
     status = STATUS_NO_MEMORY;
     if (Relations == NULL)
         goto fail1;
 
-    RtlZeroMemory(Relations, Size);
-
     for (ListEntry = Fdo->Dx->ListEntry.Flink;
          ListEntry != &Fdo->Dx->ListEntry;
          ListEntry = ListEntry->Flink) {
diff --git a/src/xenvif/mac.c b/src/xenvif/mac.c
index a89904b..f21a673 100644
--- a/src/xenvif/mac.c
+++ b/src/xenvif/mac.c
@@ -715,6 +715,8 @@ __MacGetSpeed(
         Unit = "G";
     } else {
         Speed = _strtoui64(Buffer, &Unit, 10);
+        if (Speed == _UI64_MAX)
+            Speed = Mac->Speed;
         if (*Unit == '\0')
             Unit = "G";
 
diff --git a/src/xenvif/pdo.c b/src/xenvif/pdo.c
index e6ffbc3..bc9b9ed 100644
--- a/src/xenvif/pdo.c
+++ b/src/xenvif/pdo.c
@@ -1595,14 +1595,12 @@ PdoQueryDeviceRelations(
     if (StackLocation->Parameters.QueryDeviceRelations.Type != 
TargetDeviceRelation)
         goto done;
 
-    Relations = ExAllocatePoolWithTag(PagedPool, sizeof (DEVICE_RELATIONS), 
'FIV');
+    Relations = __AllocatePoolWithTag(PagedPool, sizeof (DEVICE_RELATIONS), 
'FIV');
 
     status = STATUS_NO_MEMORY;
     if (Relations == NULL)
         goto done;
 
-    RtlZeroMemory(Relations, sizeof (DEVICE_RELATIONS));
-
     Relations->Count = 1;
     ObReferenceObject(__PdoGetDeviceObject(Pdo));
     Relations->Objects[0] = __PdoGetDeviceObject(Pdo);
@@ -1848,14 +1846,12 @@ PdoQueryDeviceText(
         goto done;
     }
 
-    Buffer = ExAllocatePoolWithTag(PagedPool, MAXTEXTLEN, 'FIV');
+    Buffer = __AllocatePoolWithTag(PagedPool, MAXTEXTLEN, 'FIV');
 
     status = STATUS_NO_MEMORY;
     if (Buffer == NULL)
         goto done;
 
-    RtlZeroMemory(Buffer, MAXTEXTLEN);
-
     Text.Buffer = Buffer;
     Text.MaximumLength = MAXTEXTLEN;
     Text.Length = 0;
@@ -1983,14 +1979,12 @@ PdoQueryId(
         goto done;
     }
 
-    Buffer = ExAllocatePoolWithTag(PagedPool, Id.MaximumLength, 'FIV');
+    Buffer = __AllocatePoolWithTag(PagedPool, Id.MaximumLength, 'FIV');
 
     status = STATUS_NO_MEMORY;
     if (Buffer == NULL)
         goto done;
 
-    RtlZeroMemory(Buffer, Id.MaximumLength);
-
     Id.Buffer = Buffer;
     Id.Length = 0;
 
@@ -2129,14 +2123,12 @@ PdoQueryBusInformation(
 
     UNREFERENCED_PARAMETER(Pdo);
 
-    Info = ExAllocatePoolWithTag(PagedPool, sizeof (PNP_BUS_INFORMATION), 
'FIV');
+    Info = __AllocatePoolWithTag(PagedPool, sizeof (PNP_BUS_INFORMATION), 
'FIV');
 
     status = STATUS_NO_MEMORY;
     if (Info == NULL)
         goto done;
 
-    RtlZeroMemory(Info, sizeof (PNP_BUS_INFORMATION));
-
     Info->BusTypeGuid = GUID_BUS_TYPE_INTERNAL;
     Info->LegacyBusType = PNPBus;
     Info->BusNumber = 0;
diff --git a/src/xenvif/util.h b/src/xenvif/util.h
index 74d0436..0df2a52 100644
--- a/src/xenvif/util.h
+++ b/src/xenvif/util.h
@@ -151,8 +151,12 @@ __AllocatePoolWithTag(
     __analysis_assume(PoolType == NonPagedPool ||
                       PoolType == PagedPool);
 
+#if (_MSC_VER >= 1928) // VS 16.9 (EWDK 20344 or later)
+    Buffer = ExAllocatePoolUninitialized(PoolType, NumberOfBytes, Tag);
+#else
 #pragma warning(suppress:28160) // annotation error
     Buffer = ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag);
+#endif
     if (Buffer == NULL)
         return NULL;
 
-- 
2.31.1.windows.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.