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

Re: [PATCH 3/4] Fix CodeQL warnings


  • To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Paul Durrant <xadimgnik@xxxxxxxxx>
  • Date: Mon, 20 Sep 2021 10:34:47 +0100
  • Delivery-date: Mon, 20 Sep 2021 09:34:51 +0000
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

On 12/08/2021 13:41, Owen Smith wrote:
- ExAllocatePoolWithTag is deprecated in Win10 2004, use
     ExAllocatePoolUninitialized instead

Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
  src/common/util.h    |  4 ++++
  src/xenvbd/adapter.c | 12 ++++--------
  src/xenvbd/base64.c  | 15 ++++-----------
  3 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/src/common/util.h b/src/common/util.h
index eddad4a..36a36dd 100644
--- a/src/common/util.h
+++ b/src/common/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;
diff --git a/src/xenvbd/adapter.c b/src/xenvbd/adapter.c
index 9fd2abc..5b17a6b 100644
--- a/src/xenvbd/adapter.c
+++ b/src/xenvbd/adapter.c
@@ -102,13 +102,9 @@ __AdapterAllocate(
      IN  ULONG   Size
      )
  {
-    PVOID       Buffer;
-    Buffer = ExAllocatePoolWithTag(NonPagedPool,
-                                   Size,
-                                   ADAPTER_POOL_TAG);
-    if (Buffer)
-        RtlZeroMemory(Buffer, Size);

We'll still need to zero the memory to maintain the semantics, right?

I'll amend the patch accordingly.

  Paul

-    return Buffer;
+    return __AllocatePoolWithTag(NonPagedPool,
+                                 Size,
+                                 ADAPTER_POOL_TAG);
  }
static FORCEINLINE VOID
@@ -116,7 +112,7 @@ __AdapterFree(
      IN  PVOID   Buffer
      )
  {
-    ExFreePoolWithTag(Buffer, ADAPTER_POOL_TAG);
+    __FreePoolWithTag(Buffer, ADAPTER_POOL_TAG);
  }
static FORCEINLINE PANSI_STRING
diff --git a/src/xenvbd/base64.c b/src/xenvbd/base64.c
index 0e62784..223579a 100644
--- a/src/xenvbd/base64.c
+++ b/src/xenvbd/base64.c
@@ -44,15 +44,9 @@ Base64Allocate(
      IN  ULONG   Size
      )
  {
-    PVOID       Buffer;
-
-    Buffer = ExAllocatePoolWithTag(NonPagedPool,
-                                   Size,
-                                   BASE64_POOL_TAG);
-    if (Buffer)
-        RtlZeroMemory(Buffer, Size);
-
-    return Buffer;
+    return __AllocatePoolWithTag(NonPagedPool,
+                                 Size,
+                                 BASE64_POOL_TAG);
  }
VOID
@@ -60,8 +54,7 @@ Base64Free(
      IN  PVOID   Buffer
      )
  {
-    if (Buffer)
-        ExFreePoolWithTag(Buffer, BASE64_POOL_TAG);
+    __FreePoolWithTag(Buffer, BASE64_POOL_TAG);
  }
static FORCEINLINE UCHAR





 


Rackspace

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