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

[PATCH 09/11] xenvkbd: Fix annotations reported by code analysis


  • To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
  • Date: Mon, 19 Oct 2026 15:14:35 +0200
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:In-Reply-To:References:Feedback-ID"
  • Cc: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
  • Delivery-date: Mon, 19 Oct 2026 13:14:55 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

* Mark registry root handles and cleared driver globals as optional
since NULL is valid there
* Annotate the enumerated device list as _Inout_opt_, and
describe the interface filled by IRP_MN_QUERY_INTERFACE as an
_Inout_ buffer.
* Fix spacings

No functional change.

Signed-off-by: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
---
 src/xenvkbd/assert.h   |  2 +-
 src/xenvkbd/bus.c      | 24 +++++++--------
 src/xenvkbd/driver.c   |  4 +--
 src/xenvkbd/fdo.c      | 66 +++++++++++++++++++++---------------------
 src/xenvkbd/fdo.h      | 20 ++++++-------
 src/xenvkbd/hid.c      | 16 +++++-----
 src/xenvkbd/hid.h      |  6 ++--
 src/xenvkbd/pdo.c      | 20 ++++++-------
 src/xenvkbd/pdo.h      | 20 ++++++-------
 src/xenvkbd/registry.c | 12 ++++----
 src/xenvkbd/registry.h | 14 ++++-----
 src/xenvkbd/ring.c     | 12 ++++----
 12 files changed, 108 insertions(+), 108 deletions(-)

diff --git a/src/xenvkbd/assert.h b/src/xenvkbd/assert.h
index 6540eb7..c5fab23 100644
--- a/src/xenvkbd/assert.h
+++ b/src/xenvkbd/assert.h
@@ -160,7 +160,7 @@ _IsZeroMemory(
     _In_ ULONG                      Length
     )
 {
-    ULONG           Offset;
+    ULONG                           Offset;
 
     Offset = 0;
     while (Offset < Length) {
diff --git a/src/xenvkbd/bus.c b/src/xenvkbd/bus.c
index 52dd2ed..eeac1d6 100644
--- a/src/xenvkbd/bus.c
+++ b/src/xenvkbd/bus.c
@@ -126,14 +126,14 @@ static
 _Function_class_(GET_SET_DEVICE_DATA)
 ULONG
 BusSetData(
-    _In_ PVOID                             _Context,
-    _In_ ULONG                             DataType,
-    _Inout_updates_bytes_(Length) PVOID    Buffer,
-    _In_ ULONG                             Offset,
-    _In_ ULONG                             Length
+    _In_ PVOID                          _Context,
+    _In_ ULONG                          DataType,
+    _Inout_updates_bytes_(Length) PVOID Buffer,
+    _In_ ULONG                          Offset,
+    _In_ ULONG                          Length
     )
 {
-    PXENVKBD_BUS_CONTEXT    Context = _Context;
+    PXENVKBD_BUS_CONTEXT                Context = _Context;
 
     return PdoSetBusData(Context->Pdo,
                          DataType,
@@ -146,14 +146,14 @@ static
 _Function_class_(GET_SET_DEVICE_DATA)
 ULONG
 BusGetData(
-    _In_ PVOID                             _Context,
-    _In_ ULONG                             DataType,
-    _Inout_updates_bytes_(Length) PVOID    Buffer,
-    _In_ ULONG                             Offset,
-    _In_ ULONG                             Length
+    _In_ PVOID                          _Context,
+    _In_ ULONG                          DataType,
+    _Inout_updates_bytes_(Length) PVOID Buffer,
+    _In_ ULONG                          Offset,
+    _In_ ULONG                          Length
     )
 {
-    PXENVKBD_BUS_CONTEXT    Context = _Context;
+    PXENVKBD_BUS_CONTEXT                Context = _Context;
 
     return PdoGetBusData(Context->Pdo,
                          DataType,
diff --git a/src/xenvkbd/driver.c b/src/xenvkbd/driver.c
index 2c1adda..b7aee4b 100644
--- a/src/xenvkbd/driver.c
+++ b/src/xenvkbd/driver.c
@@ -71,7 +71,7 @@ DriverSafeMode(
 
 static FORCEINLINE VOID
 __DriverSetDriverObject(
-    _In_ PDRIVER_OBJECT DriverObject
+    _In_opt_ PDRIVER_OBJECT DriverObject
     )
 {
     Driver.DriverObject = DriverObject;
@@ -95,7 +95,7 @@ DriverGetDriverObject(
 
 static FORCEINLINE VOID
 __DriverSetParametersKey(
-    _In_ HANDLE Key
+    _In_opt_ HANDLE Key
     )
 {
     Driver.ParametersKey = Key;
diff --git a/src/xenvkbd/fdo.c b/src/xenvkbd/fdo.c
index 133a62b..958e3dd 100644
--- a/src/xenvkbd/fdo.c
+++ b/src/xenvkbd/fdo.c
@@ -370,14 +370,14 @@ FdoTranslateBusAddress(
 
 ULONG
 FdoSetBusData(
-    _In_ PXENVKBD_FDO                      Fdo,
-    _In_ ULONG                             DataType,
-    _Inout_updates_bytes_(Length) PVOID    Buffer,
-    _In_ ULONG                             Offset,
-    _In_ ULONG                             Length
+    _In_ PXENVKBD_FDO                   Fdo,
+    _In_ ULONG                          DataType,
+    _Inout_updates_bytes_(Length) PVOID Buffer,
+    _In_ ULONG                          Offset,
+    _In_ ULONG                          Length
     )
 {
-    PBUS_INTERFACE_STANDARD BusInterface;
+    PBUS_INTERFACE_STANDARD             BusInterface;
 
     BusInterface = Fdo->LowerBusInterface;
     ASSERT(BusInterface != NULL);
@@ -391,14 +391,14 @@ FdoSetBusData(
 
 ULONG
 FdoGetBusData(
-    _In_ PXENVKBD_FDO                      Fdo,
-    _In_ ULONG                             DataType,
-    _Inout_updates_bytes_(Length) PVOID    Buffer,
-    _In_ ULONG                             Offset,
-    _In_ ULONG                             Length
+    _In_ PXENVKBD_FDO                   Fdo,
+    _In_ ULONG                          DataType,
+    _Inout_updates_bytes_(Length) PVOID Buffer,
+    _In_ ULONG                          Offset,
+    _In_ ULONG                          Length
     )
 {
-    PBUS_INTERFACE_STANDARD BusInterface;
+    PBUS_INTERFACE_STANDARD             BusInterface;
 
     BusInterface = Fdo->LowerBusInterface;
     ASSERT(BusInterface != NULL);
@@ -715,16 +715,16 @@ FdoReleaseMutex(
 
 static FORCEINLINE BOOLEAN
 __FdoEnumerate(
-    _In_ PXENVKBD_FDO   Fdo,
-    _In_ PANSI_STRING   Devices
+    _In_ PXENVKBD_FDO           Fdo,
+    _Inout_opt_ PANSI_STRING    Devices
     )
 {
-    BOOLEAN             NeedInvalidate;
-    HANDLE              ParametersKey;
-    ULONG               Enumerate;
-    PLIST_ENTRY         ListEntry;
-    ULONG               Index;
-    NTSTATUS            status;
+    BOOLEAN                     NeedInvalidate;
+    HANDLE                      ParametersKey;
+    ULONG                       Enumerate;
+    PLIST_ENTRY                 ListEntry;
+    ULONG                       Index;
+    NTSTATUS                    status;
 
     Trace("====>\n");
 
@@ -2902,19 +2902,19 @@ FdoDispatch(
 _IRQL_requires_(PASSIVE_LEVEL)
 static NTSTATUS
 FdoQueryInterface(
-    _In_ PXENVKBD_FDO   Fdo,
-    _In_ const GUID     *Guid,
-    _In_ ULONG          Version,
-    _Out_ PINTERFACE    Interface,
-    _In_ ULONG          Size,
-    _In_ BOOLEAN        Optional
-    )
-{
-    KEVENT              Event;
-    IO_STATUS_BLOCK     StatusBlock;
-    PIRP                Irp;
-    PIO_STACK_LOCATION  StackLocation;
-    NTSTATUS            status;
+    _In_ PXENVKBD_FDO                       Fdo,
+    _In_ const GUID                         *Guid,
+    _In_ ULONG                              Version,
+    _Inout_updates_bytes_(Size) PINTERFACE  Interface,
+    _In_ ULONG                              Size,
+    _In_ BOOLEAN                            Optional
+    )
+{
+    KEVENT                                  Event;
+    IO_STATUS_BLOCK                         StatusBlock;
+    PIRP                                    Irp;
+    PIO_STACK_LOCATION                      StackLocation;
+    NTSTATUS                                status;
 
     ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
 
diff --git a/src/xenvkbd/fdo.h b/src/xenvkbd/fdo.h
index 3cd0b2d..d0590da 100644
--- a/src/xenvkbd/fdo.h
+++ b/src/xenvkbd/fdo.h
@@ -100,20 +100,20 @@ FdoTranslateBusAddress(
 
 extern ULONG
 FdoSetBusData(
-    _In_ PXENVKBD_FDO                      Fdo,
-    _In_ ULONG                             DataType,
-    _Inout_updates_bytes_(Length) PVOID    Buffer,
-    _In_ ULONG                             Offset,
-    _In_ ULONG                             Length
+    _In_ PXENVKBD_FDO                   Fdo,
+    _In_ ULONG                          DataType,
+    _Inout_updates_bytes_(Length) PVOID Buffer,
+    _In_ ULONG                          Offset,
+    _In_ ULONG                          Length
     );
 
 extern ULONG
 FdoGetBusData(
-    _In_ PXENVKBD_FDO                      Fdo,
-    _In_ ULONG                             DataType,
-    _Inout_updates_bytes_(Length) PVOID    Buffer,
-    _In_ ULONG                             Offset,
-    _In_ ULONG                             Length
+    _In_ PXENVKBD_FDO                   Fdo,
+    _In_ ULONG                          DataType,
+    _Inout_updates_bytes_(Length) PVOID Buffer,
+    _In_ ULONG                          Offset,
+    _In_ ULONG                          Length
     );
 
 extern NTSTATUS
diff --git a/src/xenvkbd/hid.c b/src/xenvkbd/hid.c
index 97e2f96..92912ef 100644
--- a/src/xenvkbd/hid.c
+++ b/src/xenvkbd/hid.c
@@ -65,11 +65,11 @@ struct _XENVKBD_HID_CONTEXT {
 
 static FORCEINLINE NTSTATUS
 HidCopyBuffer(
-    _Out_writes_bytes_opt_(Length) PVOID         Buffer,
-    _In_ ULONG                                   Length,
-    _In_reads_bytes_(SourceLength) const VOID    *Source,
-    _In_ ULONG                                   SourceLength,
-    _Out_ PULONG                                 Returned
+    _Out_writes_bytes_opt_(Length) PVOID        Buffer,
+    _In_ ULONG                                  Length,
+    _In_reads_bytes_(SourceLength) const VOID   *Source,
+    _In_ ULONG                                  SourceLength,
+    _Out_ PULONG                                Returned
     )
 {
     if (Buffer == NULL)
@@ -674,9 +674,9 @@ HidTeardown(
 
 BOOLEAN
 HidSendReadReport(
-    _In_ PXENVKBD_HID_CONTEXT         Context,
-    _In_reads_bytes_(Length) PVOID    Buffer,
-    _In_ ULONG                        Length
+    _In_ PXENVKBD_HID_CONTEXT       Context,
+    _In_reads_bytes_(Length) PVOID  Buffer,
+    _In_ ULONG                      Length
     )
 {
     if (!Context->Enabled)
diff --git a/src/xenvkbd/hid.h b/src/xenvkbd/hid.h
index cc7dfd6..3c626f3 100644
--- a/src/xenvkbd/hid.h
+++ b/src/xenvkbd/hid.h
@@ -65,9 +65,9 @@ HidTeardown(
 
 extern BOOLEAN
 HidSendReadReport(
-    _In_ PXENVKBD_HID_CONTEXT         Context,
-    _In_reads_bytes_(Length) PVOID    Buffer,
-    _In_ ULONG                        Length
+    _In_ PXENVKBD_HID_CONTEXT       Context,
+    _In_reads_bytes_(Length) PVOID  Buffer,
+    _In_ ULONG                      Length
     );
 
 #endif  // _XENVKBD_VKBD_H
diff --git a/src/xenvkbd/pdo.c b/src/xenvkbd/pdo.c
index 60a5ae5..30e1a49 100644
--- a/src/xenvkbd/pdo.c
+++ b/src/xenvkbd/pdo.c
@@ -487,11 +487,11 @@ PdoTranslateBusAddress(
 
 ULONG
 PdoSetBusData(
-    _In_ PXENVKBD_PDO                      Pdo,
-    _In_ ULONG                             DataType,
-    _Inout_updates_bytes_(Length) PVOID    Buffer,
-    _In_ ULONG                             Offset,
-    _In_ ULONG                             Length
+    _In_ PXENVKBD_PDO                   Pdo,
+    _In_ ULONG                          DataType,
+    _Inout_updates_bytes_(Length) PVOID Buffer,
+    _In_ ULONG                          Offset,
+    _In_ ULONG                          Length
     )
 {
     Trace("<===>\n");
@@ -505,11 +505,11 @@ PdoSetBusData(
 
 ULONG
 PdoGetBusData(
-    _In_ PXENVKBD_PDO                      Pdo,
-    _In_ ULONG                             DataType,
-    _Inout_updates_bytes_(Length) PVOID    Buffer,
-    _In_ ULONG                             Offset,
-    _In_ ULONG                             Length
+    _In_ PXENVKBD_PDO                   Pdo,
+    _In_ ULONG                          DataType,
+    _Inout_updates_bytes_(Length) PVOID Buffer,
+    _In_ ULONG                          Offset,
+    _In_ ULONG                          Length
     )
 {
     Trace("<===>\n");
diff --git a/src/xenvkbd/pdo.h b/src/xenvkbd/pdo.h
index 28f396c..10a9329 100644
--- a/src/xenvkbd/pdo.h
+++ b/src/xenvkbd/pdo.h
@@ -104,20 +104,20 @@ PdoTranslateBusAddress(
 
 extern ULONG
 PdoSetBusData(
-    _In_ PXENVKBD_PDO                      Pdo,
-    _In_ ULONG                             DataType,
-    _Inout_updates_bytes_(Length) PVOID    Buffer,
-    _In_ ULONG                             Offset,
-    _In_ ULONG                             Length
+    _In_ PXENVKBD_PDO                   Pdo,
+    _In_ ULONG                          DataType,
+    _Inout_updates_bytes_(Length) PVOID Buffer,
+    _In_ ULONG                          Offset,
+    _In_ ULONG                          Length
     );
 
 extern ULONG
 PdoGetBusData(
-    _In_ PXENVKBD_PDO                      Pdo,
-    _In_ ULONG                             DataType,
-    _Inout_updates_bytes_(Length) PVOID    Buffer,
-    _In_ ULONG                             Offset,
-    _In_ ULONG                             Length
+    _In_ PXENVKBD_PDO                   Pdo,
+    _In_ ULONG                          DataType,
+    _Inout_updates_bytes_(Length) PVOID Buffer,
+    _In_ ULONG                          Offset,
+    _In_ ULONG                          Length
     );
 
 extern NTSTATUS
diff --git a/src/xenvkbd/registry.c b/src/xenvkbd/registry.c
index 52ba33b..5cc6b99 100644
--- a/src/xenvkbd/registry.c
+++ b/src/xenvkbd/registry.c
@@ -146,7 +146,7 @@ fail1:
 
 NTSTATUS
 RegistryOpenKey(
-    _In_ HANDLE             Parent,
+    _In_opt_ HANDLE         Parent,
     _In_ PUNICODE_STRING    Path,
     _In_ ACCESS_MASK        DesiredAccess,
     _Out_ PHANDLE           Key
@@ -208,7 +208,7 @@ fail1:
 
 NTSTATUS
 RegistryCreateKey(
-    _In_ HANDLE             Parent,
+    _In_opt_ HANDLE         Parent,
     _In_ PUNICODE_STRING    Path,
     _In_ ULONG              Options,
     _Out_ PHANDLE           Key
@@ -1240,10 +1240,10 @@ fail1:
 
 NTSTATUS
 RegistryUpdateBinaryValue(
-    _In_ HANDLE                       Key,
-    _In_ PSTR                         Name,
-    _In_reads_bytes_(Length) PVOID    Buffer,
-    _In_ ULONG                        Length
+    _In_ HANDLE                     Key,
+    _In_ PSTR                       Name,
+    _In_reads_bytes_(Length) PVOID  Buffer,
+    _In_ ULONG                      Length
     )
 {
     ANSI_STRING                     Ansi;
diff --git a/src/xenvkbd/registry.h b/src/xenvkbd/registry.h
index 2451e03..4535747 100644
--- a/src/xenvkbd/registry.h
+++ b/src/xenvkbd/registry.h
@@ -47,7 +47,7 @@ RegistryTeardown(
 
 extern NTSTATUS
 RegistryOpenKey(
-    _In_ HANDLE             Parent,
+    _In_opt_ HANDLE         Parent,
     _In_ PUNICODE_STRING    Path,
     _In_ ACCESS_MASK        DesiredAccess,
     _Out_ PHANDLE           Key
@@ -55,7 +55,7 @@ RegistryOpenKey(
 
 extern NTSTATUS
 RegistryCreateKey(
-    _In_ HANDLE             Parent,
+    _In_opt_ HANDLE         Parent,
     _In_ PUNICODE_STRING    Path,
     _In_ ULONG              Options,
     _Out_ PHANDLE           Key
@@ -96,7 +96,7 @@ RegistryOpenSubKey(
 
 extern NTSTATUS
 RegistryCreateSubKey(
-    _In_ HANDLE     Key,
+    _In_opt_ HANDLE Key,
     _In_ PSTR       Name,
     _In_ ULONG      Options,
     _Out_ PHANDLE   SubKey
@@ -160,10 +160,10 @@ RegistryQueryBinaryValue(
 
 extern NTSTATUS
 RegistryUpdateBinaryValue(
-    _In_ HANDLE                       Key,
-    _In_ PSTR                         Name,
-    _In_reads_bytes_(Length) PVOID    Buffer,
-    _In_ ULONG                        Length
+    _In_ HANDLE                     Key,
+    _In_ PSTR                       Name,
+    _In_reads_bytes_(Length) PVOID  Buffer,
+    _In_ ULONG                      Length
     );
 
 extern NTSTATUS
diff --git a/src/xenvkbd/ring.c b/src/xenvkbd/ring.c
index 9a79fc9..7779b83 100644
--- a/src/xenvkbd/ring.c
+++ b/src/xenvkbd/ring.c
@@ -109,11 +109,11 @@ __RingFree(
 
 static FORCEINLINE NTSTATUS
 __RingCopyBuffer(
-    _Out_writes_bytes_opt_(Length) PVOID         Buffer,
-    _In_ ULONG                                   Length,
-    _In_reads_bytes_(SourceLength) const VOID    *Source,
-    _In_ ULONG                                   SourceLength,
-    _Out_ PULONG                                 Returned
+    _Out_writes_bytes_opt_(Length) PVOID        Buffer,
+    _In_ ULONG                                  Length,
+    _In_reads_bytes_(SourceLength) const VOID   *Source,
+    _In_ ULONG                                  SourceLength,
+    _Out_ PULONG                                Returned
     )
 {
     if (Buffer == NULL)
@@ -437,7 +437,7 @@ KSERVICE_ROUTINE    RingEvtchnCallback;
 BOOLEAN
 RingEvtchnCallback(
     _In_ PKINTERRUPT    InterruptObject,
-    _In_ PVOID          Argument
+    _In_opt_ PVOID      Argument
     )
 {
     PXENVKBD_RING       Ring = Argument;
-- 
2.55.0.windows.5



--
Césaire Mounah | Vates Windows Guest Tools Engineer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

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