[02/11] OvmfPkg/XenBusDxe: Have XenStoreFindWatch take a pointer
diff mbox series

Message ID 20190913145100.303433-3-anthony.perard@citrix.com
State New
Headers show
Series
  • OvmfPkg/XenBusDxe: Fix ExitBootServices handler to avoid allocation
Related show

Commit Message

Anthony PERARD Sept. 13, 2019, 2:50 p.m. UTC
Rework XenStoreFindWatch() to be able to search for a registered watch
with a pointer instead of a string.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 OvmfPkg/XenBusDxe/XenStore.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

Comments

Laszlo Ersek Sept. 16, 2019, 2:38 p.m. UTC | #1
On 09/13/19 16:50, Anthony PERARD wrote:
> Rework XenStoreFindWatch() to be able to search for a registered watch
> with a pointer instead of a string.
> 
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> ---
>  OvmfPkg/XenBusDxe/XenStore.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c
> index 7253d8ae37..727641a0fe 100644
> --- a/OvmfPkg/XenBusDxe/XenStore.c
> +++ b/OvmfPkg/XenBusDxe/XenStore.c
> @@ -253,14 +253,12 @@ Split (
>  STATIC
>  XENSTORE_WATCH *
>  XenStoreFindWatch (
> -  IN CONST CHAR8 *Token
> +  IN VOID *Token
>    )
>  {
> -  XENSTORE_WATCH *Watch, *WantedWatch;
> +  XENSTORE_WATCH *Watch;
>    LIST_ENTRY *Entry;
>  
> -  WantedWatch = (VOID *) AsciiStrHexToUintn (Token);
> -
>    if (IsListEmpty (&xs.RegisteredWatches)) {
>      return NULL;
>    }
> @@ -268,7 +266,7 @@ XenStoreFindWatch (
>         !IsNull (&xs.RegisteredWatches, Entry);
>         Entry = GetNextNode (&xs.RegisteredWatches, Entry)) {
>      Watch = XENSTORE_WATCH_FROM_LINK (Entry);
> -    if (Watch == WantedWatch)
> +    if ((VOID *) Watch == Token)
>        return Watch;
>    }
>  
> @@ -632,12 +630,16 @@ XenStoreProcessMessage (
>    Body[Message->Header.len] = '\0';
>  
>    if (Message->Header.type == XS_WATCH_EVENT) {
> +    VOID *ConvertedToken;
> +
>      Message->u.Watch.Vector = Split(Body, Message->Header.len,
>                                      &Message->u.Watch.VectorSize);
>  
> +    ConvertedToken =
> +      (VOID *) AsciiStrHexToUintn (Message->u.Watch.Vector[XS_WATCH_TOKEN]);
> +
>      EfiAcquireLock (&xs.RegisteredWatchesLock);
> -    Message->u.Watch.Handle =
> -      XenStoreFindWatch (Message->u.Watch.Vector[XS_WATCH_TOKEN]);
> +    Message->u.Watch.Handle = XenStoreFindWatch (ConvertedToken);
>      DEBUG ((EFI_D_INFO, "XenStore: Watch event %a\n",
>              Message->u.Watch.Vector[XS_WATCH_TOKEN]));
>      if (Message->u.Watch.Handle != NULL) {
> @@ -1384,8 +1386,7 @@ XenStoreUnregisterWatch (
>  
>    ASSERT (Watch->Signature == XENSTORE_WATCH_SIGNATURE);
>  
> -  AsciiSPrint (Token, sizeof (Token), "%p", (VOID *) Watch);
> -  if (XenStoreFindWatch (Token) == NULL) {
> +  if (XenStoreFindWatch (Watch) == NULL) {
>      return;
>    }
>  
> @@ -1393,6 +1394,7 @@ XenStoreUnregisterWatch (
>    RemoveEntryList (&Watch->Link);
>    EfiReleaseLock (&xs.RegisteredWatchesLock);
>  
> +  AsciiSPrint (Token, sizeof (Token), "%p", (VOID *) Watch);
>    XenStoreUnwatch (Watch->Node, Token);
>  
>    /* Cancel pending watch events. */
> 

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Patch
diff mbox series

diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c
index 7253d8ae37..727641a0fe 100644
--- a/OvmfPkg/XenBusDxe/XenStore.c
+++ b/OvmfPkg/XenBusDxe/XenStore.c
@@ -253,14 +253,12 @@  Split (
 STATIC
 XENSTORE_WATCH *
 XenStoreFindWatch (
-  IN CONST CHAR8 *Token
+  IN VOID *Token
   )
 {
-  XENSTORE_WATCH *Watch, *WantedWatch;
+  XENSTORE_WATCH *Watch;
   LIST_ENTRY *Entry;
 
-  WantedWatch = (VOID *) AsciiStrHexToUintn (Token);
-
   if (IsListEmpty (&xs.RegisteredWatches)) {
     return NULL;
   }
@@ -268,7 +266,7 @@  XenStoreFindWatch (
        !IsNull (&xs.RegisteredWatches, Entry);
        Entry = GetNextNode (&xs.RegisteredWatches, Entry)) {
     Watch = XENSTORE_WATCH_FROM_LINK (Entry);
-    if (Watch == WantedWatch)
+    if ((VOID *) Watch == Token)
       return Watch;
   }
 
@@ -632,12 +630,16 @@  XenStoreProcessMessage (
   Body[Message->Header.len] = '\0';
 
   if (Message->Header.type == XS_WATCH_EVENT) {
+    VOID *ConvertedToken;
+
     Message->u.Watch.Vector = Split(Body, Message->Header.len,
                                     &Message->u.Watch.VectorSize);
 
+    ConvertedToken =
+      (VOID *) AsciiStrHexToUintn (Message->u.Watch.Vector[XS_WATCH_TOKEN]);
+
     EfiAcquireLock (&xs.RegisteredWatchesLock);
-    Message->u.Watch.Handle =
-      XenStoreFindWatch (Message->u.Watch.Vector[XS_WATCH_TOKEN]);
+    Message->u.Watch.Handle = XenStoreFindWatch (ConvertedToken);
     DEBUG ((EFI_D_INFO, "XenStore: Watch event %a\n",
             Message->u.Watch.Vector[XS_WATCH_TOKEN]));
     if (Message->u.Watch.Handle != NULL) {
@@ -1384,8 +1386,7 @@  XenStoreUnregisterWatch (
 
   ASSERT (Watch->Signature == XENSTORE_WATCH_SIGNATURE);
 
-  AsciiSPrint (Token, sizeof (Token), "%p", (VOID *) Watch);
-  if (XenStoreFindWatch (Token) == NULL) {
+  if (XenStoreFindWatch (Watch) == NULL) {
     return;
   }
 
@@ -1393,6 +1394,7 @@  XenStoreUnregisterWatch (
   RemoveEntryList (&Watch->Link);
   EfiReleaseLock (&xs.RegisteredWatchesLock);
 
+  AsciiSPrint (Token, sizeof (Token), "%p", (VOID *) Watch);
   XenStoreUnwatch (Watch->Node, Token);
 
   /* Cancel pending watch events. */